@pisell/pisellos 3.0.89 → 3.0.91
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/apis/picoding.d.ts +0 -0
- package/dist/apis/picoding.js +1 -0
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.js +1 -0
- package/dist/model/strategy/adapter/index.d.ts +7 -0
- package/dist/model/strategy/adapter/index.js +7 -0
- package/dist/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
- package/dist/model/strategy/adapter/itemRule/adapter.js +483 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
- package/dist/model/strategy/adapter/itemRule/examples.d.ts +79 -0
- package/dist/model/strategy/adapter/itemRule/examples.js +382 -0
- package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/dist/model/strategy/adapter/itemRule/index.js +5 -0
- package/dist/model/strategy/adapter/itemRule/type.d.ts +225 -0
- package/dist/model/strategy/adapter/itemRule/type.js +101 -0
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/dist/model/strategy/adapter/promotion/adapter.js +271 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +1206 -0
- package/dist/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/dist/model/strategy/adapter/promotion/examples.js +166 -0
- package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/dist/model/strategy/adapter/promotion/index.js +0 -0
- package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/dist/model/strategy/adapter/promotion/type.js +209 -0
- package/dist/model/strategy/adapter/type.d.ts +28 -0
- package/dist/model/strategy/adapter/type.js +1 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +502 -0
- package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
- package/dist/model/strategy/adapter/walletPass/example.js +258 -0
- package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
- package/dist/model/strategy/adapter/walletPass/index.js +182 -0
- package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
- package/dist/model/strategy/adapter/walletPass/locales.js +26 -0
- package/dist/model/strategy/adapter/walletPass/type.d.ts +187 -0
- package/dist/model/strategy/adapter/walletPass/type.js +1 -0
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
- package/dist/model/strategy/adapter/walletPass/utils.js +1104 -0
- package/dist/model/strategy/engine.d.ts +106 -0
- package/dist/model/strategy/engine.js +611 -0
- package/dist/model/strategy/index.d.ts +3 -0
- package/dist/model/strategy/index.js +8 -0
- package/dist/model/strategy/strategy-example.d.ts +5 -0
- package/dist/model/strategy/strategy-example.js +331 -0
- package/dist/model/strategy/type.d.ts +228 -0
- package/dist/model/strategy/type.js +94 -0
- package/dist/modules/Cart/utils/cartProduct.js +1 -0
- package/dist/modules/Discount/index.d.ts +4 -2
- package/dist/modules/Discount/index.js +90 -3
- package/dist/modules/Discount/types.d.ts +6 -0
- package/dist/modules/OpenData/index.d.ts +24 -0
- package/dist/modules/OpenData/index.js +173 -0
- package/dist/modules/OpenData/types.d.ts +73 -0
- package/dist/modules/OpenData/types.js +1 -0
- package/dist/modules/OpenData/utils.d.ts +2 -0
- package/dist/modules/OpenData/utils.js +75 -0
- package/dist/modules/Order/index.d.ts +66 -1
- package/dist/modules/Order/index.js +884 -10
- package/dist/modules/Order/types.d.ts +174 -12
- package/dist/modules/Order/types.js +2 -0
- package/dist/modules/Order/utils.d.ts +118 -0
- package/dist/modules/Order/utils.js +586 -2
- package/dist/modules/Product/utils.js +2 -2
- package/dist/modules/ProductList/index.d.ts +3 -1
- package/dist/modules/ProductList/index.js +19 -11
- package/dist/modules/Quotation/index.d.ts +48 -0
- package/dist/modules/Quotation/index.js +248 -0
- package/dist/modules/Quotation/types.d.ts +42 -0
- package/dist/modules/Quotation/types.js +1 -0
- package/dist/modules/Rules/index.js +17 -18
- package/dist/modules/SalesSummary/index.d.ts +63 -0
- package/dist/modules/SalesSummary/index.js +174 -0
- package/dist/modules/SalesSummary/types.d.ts +60 -0
- package/dist/modules/SalesSummary/types.js +1 -0
- package/dist/modules/SalesSummary/utils.d.ts +30 -0
- package/dist/modules/SalesSummary/utils.js +480 -0
- package/dist/modules/ScanOrderLogger/index.d.ts +23 -0
- package/dist/modules/ScanOrderLogger/index.js +174 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.js +221 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
- package/dist/modules/ScanOrderLogger/types.d.ts +53 -0
- package/dist/modules/ScanOrderLogger/types.js +1 -0
- package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
- package/dist/modules/Schedule/utils.d.ts +1 -1
- package/dist/modules/Summary/utils.d.ts +3 -3
- package/dist/modules/Summary/utils.js +41 -31
- package/dist/modules/index.d.ts +4 -0
- package/dist/modules/index.js +5 -1
- package/dist/solution/BookingByStep/index.d.ts +3 -3
- package/dist/solution/BookingByStep/index.js +2 -1
- package/dist/solution/BookingByStep/types.d.ts +3 -1
- package/dist/solution/BookingByStep/types.js +5 -1
- package/dist/solution/ScanOrder/index.d.ts +158 -0
- package/dist/solution/ScanOrder/index.js +3474 -0
- package/dist/solution/ScanOrder/types.d.ts +306 -0
- package/dist/solution/ScanOrder/types.js +35 -0
- package/dist/solution/ScanOrder/utils.d.ts +172 -0
- package/dist/solution/ScanOrder/utils.js +796 -0
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +23 -18
- package/dist/solution/VenueBooking/index.d.ts +201 -0
- package/dist/solution/VenueBooking/index.js +3472 -0
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/dist/solution/VenueBooking/types.d.ts +154 -0
- package/dist/solution/VenueBooking/types.js +21 -0
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
- package/dist/solution/VenueBooking/utils/dateSummary.js +104 -0
- package/dist/solution/VenueBooking/utils/resource.d.ts +14 -0
- package/dist/solution/VenueBooking/utils/resource.js +131 -0
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +239 -0
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/dist/solution/VenueBooking/utils/timeSlot.js +453 -0
- package/dist/solution/VenueBooking/utils.d.ts +1 -0
- package/dist/solution/VenueBooking/utils.js +1 -0
- package/dist/solution/index.d.ts +2 -0
- package/dist/solution/index.js +3 -1
- package/lib/apis/picoding.d.ts +0 -0
- package/lib/apis/picoding.js +0 -0
- package/lib/model/index.d.ts +1 -0
- package/lib/model/index.js +23 -0
- package/lib/model/strategy/adapter/index.d.ts +7 -0
- package/lib/model/strategy/adapter/index.js +57 -0
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
- package/lib/model/strategy/adapter/itemRule/adapter.js +377 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
- package/lib/model/strategy/adapter/itemRule/examples.d.ts +79 -0
- package/lib/model/strategy/adapter/itemRule/examples.js +316 -0
- package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/lib/model/strategy/adapter/itemRule/index.js +60 -0
- package/lib/model/strategy/adapter/itemRule/type.d.ts +225 -0
- package/lib/model/strategy/adapter/itemRule/type.js +46 -0
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/lib/model/strategy/adapter/promotion/adapter.js +217 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +844 -0
- package/lib/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/lib/model/strategy/adapter/promotion/examples.js +192 -0
- package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/lib/model/strategy/adapter/promotion/index.js +0 -0
- package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/lib/model/strategy/adapter/promotion/type.js +51 -0
- package/lib/model/strategy/adapter/type.d.ts +28 -0
- package/lib/model/strategy/adapter/type.js +17 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +424 -0
- package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
- package/lib/model/strategy/adapter/walletPass/example.js +207 -0
- package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
- package/lib/model/strategy/adapter/walletPass/index.js +142 -0
- package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
- package/lib/model/strategy/adapter/walletPass/locales.js +54 -0
- package/lib/model/strategy/adapter/walletPass/type.d.ts +187 -0
- package/lib/model/strategy/adapter/walletPass/type.js +17 -0
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +791 -0
- package/lib/model/strategy/engine.d.ts +106 -0
- package/lib/model/strategy/engine.js +450 -0
- package/lib/model/strategy/index.d.ts +3 -0
- package/lib/model/strategy/index.js +38 -0
- package/lib/model/strategy/strategy-example.d.ts +5 -0
- package/lib/model/strategy/strategy-example.js +318 -0
- package/lib/model/strategy/type.d.ts +228 -0
- package/lib/model/strategy/type.js +44 -0
- package/lib/modules/Cart/utils/cartProduct.js +1 -0
- package/lib/modules/Discount/index.d.ts +4 -2
- package/lib/modules/Discount/index.js +60 -2
- package/lib/modules/Discount/types.d.ts +6 -0
- package/lib/modules/OpenData/index.d.ts +24 -0
- package/lib/modules/OpenData/index.js +119 -0
- package/lib/modules/OpenData/types.d.ts +73 -0
- package/lib/modules/OpenData/types.js +17 -0
- package/lib/modules/OpenData/utils.d.ts +2 -0
- package/lib/modules/OpenData/utils.js +111 -0
- package/lib/modules/Order/index.d.ts +66 -1
- package/lib/modules/Order/index.js +525 -0
- package/lib/modules/Order/types.d.ts +174 -12
- package/lib/modules/Order/utils.d.ts +118 -0
- package/lib/modules/Order/utils.js +483 -2
- package/lib/modules/Product/utils.js +2 -2
- package/lib/modules/ProductList/index.d.ts +3 -1
- package/lib/modules/ProductList/index.js +45 -34
- package/lib/modules/Quotation/index.d.ts +48 -0
- package/lib/modules/Quotation/index.js +152 -0
- package/lib/modules/Quotation/types.d.ts +42 -0
- package/lib/modules/Quotation/types.js +17 -0
- package/lib/modules/Rules/index.js +17 -18
- package/lib/modules/SalesSummary/index.d.ts +63 -0
- package/lib/modules/SalesSummary/index.js +105 -0
- package/lib/modules/SalesSummary/types.d.ts +60 -0
- package/lib/modules/SalesSummary/types.js +17 -0
- package/lib/modules/SalesSummary/utils.d.ts +30 -0
- package/lib/modules/SalesSummary/utils.js +420 -0
- package/lib/modules/ScanOrderLogger/index.d.ts +23 -0
- package/lib/modules/ScanOrderLogger/index.js +147 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.js +157 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
- package/lib/modules/ScanOrderLogger/types.d.ts +53 -0
- package/lib/modules/ScanOrderLogger/types.js +17 -0
- package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
- package/lib/modules/Schedule/utils.d.ts +1 -1
- package/lib/modules/Summary/utils.d.ts +3 -3
- package/lib/modules/Summary/utils.js +22 -16
- package/lib/modules/index.d.ts +4 -0
- package/lib/modules/index.js +9 -1
- package/lib/solution/BookingByStep/index.d.ts +3 -3
- package/lib/solution/BookingByStep/index.js +2 -2
- package/lib/solution/BookingByStep/types.d.ts +3 -1
- package/lib/solution/BookingByStep/types.js +10 -0
- package/lib/solution/ScanOrder/index.d.ts +158 -0
- package/lib/solution/ScanOrder/index.js +2135 -0
- package/lib/solution/ScanOrder/types.d.ts +306 -0
- package/lib/solution/ScanOrder/types.js +36 -0
- package/lib/solution/ScanOrder/utils.d.ts +172 -0
- package/lib/solution/ScanOrder/utils.js +658 -0
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +4 -2
- package/lib/solution/VenueBooking/index.d.ts +201 -0
- package/lib/solution/VenueBooking/index.js +1937 -0
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/lib/solution/VenueBooking/types.d.ts +154 -0
- package/lib/solution/VenueBooking/types.js +44 -0
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
- package/lib/solution/VenueBooking/utils/dateSummary.js +110 -0
- package/lib/solution/VenueBooking/utils/resource.d.ts +14 -0
- package/lib/solution/VenueBooking/utils/resource.js +92 -0
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +38 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +237 -0
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/lib/solution/VenueBooking/utils/timeSlot.js +339 -0
- package/lib/solution/VenueBooking/utils.d.ts +1 -0
- package/lib/solution/VenueBooking/utils.js +69 -0
- package/lib/solution/index.d.ts +2 -0
- package/lib/solution/index.js +5 -1
- package/package.json +1 -1
|
@@ -0,0 +1,174 @@
|
|
|
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 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 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); } }
|
|
6
|
+
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); }); }; }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
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); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
11
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
12
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
13
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
14
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
15
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
16
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
17
|
+
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; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
19
|
+
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); }
|
|
20
|
+
import dayjs from 'dayjs';
|
|
21
|
+
import { BaseModule } from "../BaseModule";
|
|
22
|
+
import { feishuLoggerProvider } from "./providers/feishu";
|
|
23
|
+
import { grafanaLoggerProvider } from "./providers/grafana";
|
|
24
|
+
var defaultProviderConfig = {
|
|
25
|
+
feishu: {
|
|
26
|
+
webhook: 'https://open.feishu.cn/open-apis/bot/v2/hook/REPLACE_ME'
|
|
27
|
+
},
|
|
28
|
+
grafana: {
|
|
29
|
+
endpoint: 'https://grafana.example.com/collect'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var providerMap = {
|
|
33
|
+
feishu: feishuLoggerProvider,
|
|
34
|
+
grafana: grafanaLoggerProvider
|
|
35
|
+
};
|
|
36
|
+
export var ScanOrderLoggerModule = /*#__PURE__*/function (_BaseModule) {
|
|
37
|
+
_inherits(ScanOrderLoggerModule, _BaseModule);
|
|
38
|
+
var _super = _createSuper(ScanOrderLoggerModule);
|
|
39
|
+
function ScanOrderLoggerModule() {
|
|
40
|
+
var _this;
|
|
41
|
+
_classCallCheck(this, ScanOrderLoggerModule);
|
|
42
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
43
|
+
args[_key] = arguments[_key];
|
|
44
|
+
}
|
|
45
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
46
|
+
_defineProperty(_assertThisInitialized(_this), "defaultName", 'scanOrderLogger');
|
|
47
|
+
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
48
|
+
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
49
|
+
_defineProperty(_assertThisInitialized(_this), "window", void 0);
|
|
50
|
+
return _this;
|
|
51
|
+
}
|
|
52
|
+
_createClass(ScanOrderLoggerModule, [{
|
|
53
|
+
key: "initialize",
|
|
54
|
+
value: function () {
|
|
55
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core) {
|
|
56
|
+
var _options$otherParams, _options$otherParams2, _options$otherParams3;
|
|
57
|
+
var options,
|
|
58
|
+
provider,
|
|
59
|
+
providerConfig,
|
|
60
|
+
context,
|
|
61
|
+
_args = arguments;
|
|
62
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
63
|
+
while (1) switch (_context.prev = _context.next) {
|
|
64
|
+
case 0:
|
|
65
|
+
options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
|
|
66
|
+
this.core = core;
|
|
67
|
+
this.store = options.store;
|
|
68
|
+
this.window = core.getPlugin('window') || undefined;
|
|
69
|
+
provider = ((_options$otherParams = options.otherParams) === null || _options$otherParams === void 0 ? void 0 : _options$otherParams.provider) || 'feishu';
|
|
70
|
+
providerConfig = ((_options$otherParams2 = options.otherParams) === null || _options$otherParams2 === void 0 ? void 0 : _options$otherParams2.providerConfig) || {};
|
|
71
|
+
context = ((_options$otherParams3 = options.otherParams) === null || _options$otherParams3 === void 0 ? void 0 : _options$otherParams3.context) || {};
|
|
72
|
+
this.store.provider = provider;
|
|
73
|
+
this.store.providerConfig = _objectSpread(_objectSpread(_objectSpread({}, defaultProviderConfig), providerConfig), {}, {
|
|
74
|
+
feishu: _objectSpread(_objectSpread({}, defaultProviderConfig.feishu), providerConfig.feishu || {}),
|
|
75
|
+
grafana: _objectSpread(_objectSpread({}, defaultProviderConfig.grafana), providerConfig.grafana || {})
|
|
76
|
+
});
|
|
77
|
+
this.store.context = context;
|
|
78
|
+
case 10:
|
|
79
|
+
case "end":
|
|
80
|
+
return _context.stop();
|
|
81
|
+
}
|
|
82
|
+
}, _callee, this);
|
|
83
|
+
}));
|
|
84
|
+
function initialize(_x) {
|
|
85
|
+
return _initialize.apply(this, arguments);
|
|
86
|
+
}
|
|
87
|
+
return initialize;
|
|
88
|
+
}()
|
|
89
|
+
}, {
|
|
90
|
+
key: "setContext",
|
|
91
|
+
value: function setContext(context) {
|
|
92
|
+
this.store.context = _objectSpread(_objectSpread({}, this.store.context), context);
|
|
93
|
+
}
|
|
94
|
+
}, {
|
|
95
|
+
key: "setProvider",
|
|
96
|
+
value: function setProvider(provider) {
|
|
97
|
+
this.store.provider = provider;
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "setProviderConfig",
|
|
101
|
+
value: function setProviderConfig(providerConfig) {
|
|
102
|
+
this.store.providerConfig = _objectSpread(_objectSpread(_objectSpread({}, this.store.providerConfig), providerConfig), {}, {
|
|
103
|
+
feishu: _objectSpread(_objectSpread({}, this.store.providerConfig.feishu || {}), providerConfig.feishu || {}),
|
|
104
|
+
grafana: _objectSpread(_objectSpread({}, this.store.providerConfig.grafana || {}), providerConfig.grafana || {})
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}, {
|
|
108
|
+
key: "getCurrentHost",
|
|
109
|
+
value: function getCurrentHost() {
|
|
110
|
+
var _this$window;
|
|
111
|
+
var host = (_this$window = this.window) === null || _this$window === void 0 || (_this$window = _this$window.location) === null || _this$window === void 0 ? void 0 : _this$window.host;
|
|
112
|
+
if (typeof host === 'string' && host.length > 0) return host;
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
key: "buildRecord",
|
|
117
|
+
value: function buildRecord(params) {
|
|
118
|
+
var host = this.getCurrentHost();
|
|
119
|
+
return {
|
|
120
|
+
level: params.level || 'info',
|
|
121
|
+
title: params.title,
|
|
122
|
+
timestamp: params.timestamp || dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
123
|
+
payload: params.payload || {},
|
|
124
|
+
extra: params.extra || {},
|
|
125
|
+
context: _objectSpread(_objectSpread({}, this.store.context || {}), host ? {
|
|
126
|
+
host: host
|
|
127
|
+
} : {})
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}, {
|
|
131
|
+
key: "addLog",
|
|
132
|
+
value: function () {
|
|
133
|
+
var _addLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
134
|
+
var provider, record;
|
|
135
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
136
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
137
|
+
case 0:
|
|
138
|
+
if (params.title) {
|
|
139
|
+
_context2.next = 3;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
console.warn('[ScanOrderLogger] 缺少日志标题,已跳过');
|
|
143
|
+
return _context2.abrupt("return");
|
|
144
|
+
case 3:
|
|
145
|
+
provider = providerMap[this.store.provider] || feishuLoggerProvider;
|
|
146
|
+
record = this.buildRecord(params);
|
|
147
|
+
_context2.prev = 5;
|
|
148
|
+
_context2.next = 8;
|
|
149
|
+
return provider.send({
|
|
150
|
+
record: record,
|
|
151
|
+
providerConfig: this.store.providerConfig
|
|
152
|
+
});
|
|
153
|
+
case 8:
|
|
154
|
+
_context2.next = 13;
|
|
155
|
+
break;
|
|
156
|
+
case 10:
|
|
157
|
+
_context2.prev = 10;
|
|
158
|
+
_context2.t0 = _context2["catch"](5);
|
|
159
|
+
console.warn('[ScanOrderLogger] 日志上报失败', _context2.t0);
|
|
160
|
+
case 13:
|
|
161
|
+
case "end":
|
|
162
|
+
return _context2.stop();
|
|
163
|
+
}
|
|
164
|
+
}, _callee2, this, [[5, 10]]);
|
|
165
|
+
}));
|
|
166
|
+
function addLog(_x2) {
|
|
167
|
+
return _addLog.apply(this, arguments);
|
|
168
|
+
}
|
|
169
|
+
return addLog;
|
|
170
|
+
}()
|
|
171
|
+
}]);
|
|
172
|
+
return ScanOrderLoggerModule;
|
|
173
|
+
}(BaseModule);
|
|
174
|
+
export * from "./types";
|
|
@@ -0,0 +1,221 @@
|
|
|
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
|
+
var DEFAULT_THROTTLE_MS = 3000;
|
|
6
|
+
var pendingQueue = [];
|
|
7
|
+
var flushTimer = null;
|
|
8
|
+
var cachedProviderConfig;
|
|
9
|
+
function safeStringify(value) {
|
|
10
|
+
if (value === undefined || value === null) return '';
|
|
11
|
+
if (typeof value === 'string') return value;
|
|
12
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
|
|
13
|
+
return String(value);
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
return JSON.stringify(value);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return "[unserializable: ".concat(String(error), "]");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function isWebhookUsable(webhook) {
|
|
22
|
+
if (!webhook) return false;
|
|
23
|
+
if (webhook.includes('REPLACE_ME')) return false;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
function buildRecordSegments(record) {
|
|
27
|
+
var context = record.context || {};
|
|
28
|
+
return [[{
|
|
29
|
+
tag: 'text',
|
|
30
|
+
text: "[".concat(record.level, "] ").concat(record.timestamp, " ").concat(record.title, "\n")
|
|
31
|
+
}], [{
|
|
32
|
+
tag: 'text',
|
|
33
|
+
text: "\u7F13\u5B58\u6807\u8BC6: ".concat(safeStringify(context.cacheId), "\n")
|
|
34
|
+
}], [{
|
|
35
|
+
tag: 'text',
|
|
36
|
+
text: "\u65E5\u5FD7\u6765\u6E90: ".concat(safeStringify(context), "\n")
|
|
37
|
+
}], [{
|
|
38
|
+
tag: 'text',
|
|
39
|
+
text: "\u65E5\u5FD7\u5185\u5BB9: ".concat(safeStringify(record.payload), "\n")
|
|
40
|
+
}], [{
|
|
41
|
+
tag: 'text',
|
|
42
|
+
text: "\u6269\u5C55\u4FE1\u606F: ".concat(safeStringify(record.extra), "\n")
|
|
43
|
+
}], [{
|
|
44
|
+
tag: 'text',
|
|
45
|
+
text: '------\n'
|
|
46
|
+
}]];
|
|
47
|
+
}
|
|
48
|
+
function buildFeishuBody(records) {
|
|
49
|
+
var title = records.length === 1 ? records[0].title : "ScanOrder \u65E5\u5FD7\u6279\u91CF (".concat(records.length, " \u6761)");
|
|
50
|
+
var content = [];
|
|
51
|
+
records.forEach(function (record) {
|
|
52
|
+
buildRecordSegments(record).forEach(function (segment) {
|
|
53
|
+
return content.push(segment);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
return JSON.stringify({
|
|
57
|
+
msg_type: 'post',
|
|
58
|
+
content: JSON.stringify({
|
|
59
|
+
post: {
|
|
60
|
+
zh_cn: {
|
|
61
|
+
title: title,
|
|
62
|
+
content: content
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function postToFeishu(_x, _x2) {
|
|
69
|
+
return _postToFeishu.apply(this, arguments);
|
|
70
|
+
}
|
|
71
|
+
function _postToFeishu() {
|
|
72
|
+
_postToFeishu = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(webhook, body) {
|
|
73
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
74
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
75
|
+
case 0:
|
|
76
|
+
_context2.next = 2;
|
|
77
|
+
return fetch(webhook, {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: {
|
|
80
|
+
'Content-Type': 'application/json'
|
|
81
|
+
},
|
|
82
|
+
body: body
|
|
83
|
+
});
|
|
84
|
+
case 2:
|
|
85
|
+
case "end":
|
|
86
|
+
return _context2.stop();
|
|
87
|
+
}
|
|
88
|
+
}, _callee2);
|
|
89
|
+
}));
|
|
90
|
+
return _postToFeishu.apply(this, arguments);
|
|
91
|
+
}
|
|
92
|
+
function flushQueue() {
|
|
93
|
+
return _flushQueue.apply(this, arguments);
|
|
94
|
+
}
|
|
95
|
+
function _flushQueue() {
|
|
96
|
+
_flushQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
97
|
+
var _cachedProviderConfig;
|
|
98
|
+
var records, webhook;
|
|
99
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
100
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
101
|
+
case 0:
|
|
102
|
+
flushTimer = null;
|
|
103
|
+
if (pendingQueue.length) {
|
|
104
|
+
_context3.next = 3;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
return _context3.abrupt("return");
|
|
108
|
+
case 3:
|
|
109
|
+
records = pendingQueue.splice(0, pendingQueue.length);
|
|
110
|
+
webhook = (_cachedProviderConfig = cachedProviderConfig) === null || _cachedProviderConfig === void 0 || (_cachedProviderConfig = _cachedProviderConfig.feishu) === null || _cachedProviderConfig === void 0 ? void 0 : _cachedProviderConfig.webhook;
|
|
111
|
+
if (isWebhookUsable(webhook)) {
|
|
112
|
+
_context3.next = 7;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
return _context3.abrupt("return");
|
|
116
|
+
case 7:
|
|
117
|
+
if (!(typeof fetch !== 'function')) {
|
|
118
|
+
_context3.next = 10;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
console.warn('[ScanOrderLogger] 当前环境不支持 fetch,跳过 Feishu 日志批量上报');
|
|
122
|
+
return _context3.abrupt("return");
|
|
123
|
+
case 10:
|
|
124
|
+
_context3.prev = 10;
|
|
125
|
+
_context3.next = 13;
|
|
126
|
+
return postToFeishu(webhook, buildFeishuBody(records));
|
|
127
|
+
case 13:
|
|
128
|
+
_context3.next = 18;
|
|
129
|
+
break;
|
|
130
|
+
case 15:
|
|
131
|
+
_context3.prev = 15;
|
|
132
|
+
_context3.t0 = _context3["catch"](10);
|
|
133
|
+
console.warn('[ScanOrderLogger] Feishu 批量上报失败', _context3.t0);
|
|
134
|
+
case 18:
|
|
135
|
+
case "end":
|
|
136
|
+
return _context3.stop();
|
|
137
|
+
}
|
|
138
|
+
}, _callee3, null, [[10, 15]]);
|
|
139
|
+
}));
|
|
140
|
+
return _flushQueue.apply(this, arguments);
|
|
141
|
+
}
|
|
142
|
+
export var feishuLoggerProvider = {
|
|
143
|
+
send: function send(payload) {
|
|
144
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
145
|
+
var _payload$providerConf, _payload$providerConf2, _payload$providerConf3, _payload$providerConf4;
|
|
146
|
+
var webhook, errorHook, throttleMs;
|
|
147
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
148
|
+
while (1) switch (_context.prev = _context.next) {
|
|
149
|
+
case 0:
|
|
150
|
+
cachedProviderConfig = payload.providerConfig;
|
|
151
|
+
webhook = (_payload$providerConf = payload.providerConfig) === null || _payload$providerConf === void 0 || (_payload$providerConf = _payload$providerConf.feishu) === null || _payload$providerConf === void 0 ? void 0 : _payload$providerConf.webhook;
|
|
152
|
+
errorHook = (_payload$providerConf2 = payload.providerConfig) === null || _payload$providerConf2 === void 0 || (_payload$providerConf2 = _payload$providerConf2.feishu) === null || _payload$providerConf2 === void 0 ? void 0 : _payload$providerConf2.errorHook;
|
|
153
|
+
if (!(typeof fetch !== 'function')) {
|
|
154
|
+
_context.next = 6;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
console.warn('[ScanOrderLogger] 当前环境不支持 fetch,跳过 Feishu 日志上报');
|
|
158
|
+
return _context.abrupt("return");
|
|
159
|
+
case 6:
|
|
160
|
+
if (!(payload.record.level === 'error' && isWebhookUsable(errorHook))) {
|
|
161
|
+
_context.next = 16;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
_context.prev = 7;
|
|
165
|
+
_context.next = 10;
|
|
166
|
+
return postToFeishu(errorHook, buildFeishuBody([payload.record]));
|
|
167
|
+
case 10:
|
|
168
|
+
_context.next = 15;
|
|
169
|
+
break;
|
|
170
|
+
case 12:
|
|
171
|
+
_context.prev = 12;
|
|
172
|
+
_context.t0 = _context["catch"](7);
|
|
173
|
+
console.warn('[ScanOrderLogger] Feishu errorHook 上报失败', _context.t0);
|
|
174
|
+
case 15:
|
|
175
|
+
return _context.abrupt("return");
|
|
176
|
+
case 16:
|
|
177
|
+
if (webhook) {
|
|
178
|
+
_context.next = 19;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
console.warn('[ScanOrderLogger] Feishu webhook 未配置,跳过日志上报');
|
|
182
|
+
return _context.abrupt("return");
|
|
183
|
+
case 19:
|
|
184
|
+
if (isWebhookUsable(webhook)) {
|
|
185
|
+
_context.next = 21;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
return _context.abrupt("return");
|
|
189
|
+
case 21:
|
|
190
|
+
throttleMs = (_payload$providerConf3 = (_payload$providerConf4 = payload.providerConfig) === null || _payload$providerConf4 === void 0 || (_payload$providerConf4 = _payload$providerConf4.feishu) === null || _payload$providerConf4 === void 0 ? void 0 : _payload$providerConf4.throttleMs) !== null && _payload$providerConf3 !== void 0 ? _payload$providerConf3 : DEFAULT_THROTTLE_MS;
|
|
191
|
+
if (!(throttleMs <= 0)) {
|
|
192
|
+
_context.next = 32;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
_context.prev = 23;
|
|
196
|
+
_context.next = 26;
|
|
197
|
+
return postToFeishu(webhook, buildFeishuBody([payload.record]));
|
|
198
|
+
case 26:
|
|
199
|
+
_context.next = 31;
|
|
200
|
+
break;
|
|
201
|
+
case 28:
|
|
202
|
+
_context.prev = 28;
|
|
203
|
+
_context.t1 = _context["catch"](23);
|
|
204
|
+
console.warn('[ScanOrderLogger] Feishu 日志上报失败', _context.t1);
|
|
205
|
+
case 31:
|
|
206
|
+
return _context.abrupt("return");
|
|
207
|
+
case 32:
|
|
208
|
+
pendingQueue.push(payload.record);
|
|
209
|
+
if (!flushTimer) {
|
|
210
|
+
flushTimer = setTimeout(function () {
|
|
211
|
+
void flushQueue();
|
|
212
|
+
}, throttleMs);
|
|
213
|
+
}
|
|
214
|
+
case 34:
|
|
215
|
+
case "end":
|
|
216
|
+
return _context.stop();
|
|
217
|
+
}
|
|
218
|
+
}, _callee, null, [[7, 12], [23, 28]]);
|
|
219
|
+
}))();
|
|
220
|
+
}
|
|
221
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
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 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); }
|
|
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); } }
|
|
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); }); }; }
|
|
10
|
+
export var grafanaLoggerProvider = {
|
|
11
|
+
send: function send(payload) {
|
|
12
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
13
|
+
var _payload$providerConf, _payload$providerConf2;
|
|
14
|
+
var endpoint;
|
|
15
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
16
|
+
while (1) switch (_context.prev = _context.next) {
|
|
17
|
+
case 0:
|
|
18
|
+
endpoint = (_payload$providerConf = payload.providerConfig) === null || _payload$providerConf === void 0 || (_payload$providerConf = _payload$providerConf.grafana) === null || _payload$providerConf === void 0 ? void 0 : _payload$providerConf.endpoint;
|
|
19
|
+
if (endpoint) {
|
|
20
|
+
_context.next = 4;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
console.warn('[ScanOrderLogger] Grafana endpoint 未配置,跳过日志上报');
|
|
24
|
+
return _context.abrupt("return");
|
|
25
|
+
case 4:
|
|
26
|
+
if (!(typeof fetch !== 'function')) {
|
|
27
|
+
_context.next = 7;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
console.warn('[ScanOrderLogger] 当前环境不支持 fetch,跳过 Grafana 日志上报');
|
|
31
|
+
return _context.abrupt("return");
|
|
32
|
+
case 7:
|
|
33
|
+
_context.next = 9;
|
|
34
|
+
return fetch(endpoint, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: _objectSpread({
|
|
37
|
+
'Content-Type': 'application/json'
|
|
38
|
+
}, ((_payload$providerConf2 = payload.providerConfig) === null || _payload$providerConf2 === void 0 || (_payload$providerConf2 = _payload$providerConf2.grafana) === null || _payload$providerConf2 === void 0 ? void 0 : _payload$providerConf2.headers) || {}),
|
|
39
|
+
body: JSON.stringify({
|
|
40
|
+
record: payload.record
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
case 9:
|
|
44
|
+
case "end":
|
|
45
|
+
return _context.stop();
|
|
46
|
+
}
|
|
47
|
+
}, _callee);
|
|
48
|
+
}))();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type ScanOrderLogLevel = 'info' | 'warning' | 'error' | 'debug';
|
|
2
|
+
export type ScanOrderLoggerProviderType = 'feishu' | 'grafana';
|
|
3
|
+
export interface ScanOrderLoggerProviderFeishuConfig {
|
|
4
|
+
webhook?: string;
|
|
5
|
+
errorHook?: string;
|
|
6
|
+
/**
|
|
7
|
+
* 节流窗口毫秒数,默认 3000ms
|
|
8
|
+
* - >0:首条日志进入队列并启动定时器,窗口结束后合并成一条 Feishu post 统一发送
|
|
9
|
+
* - <=0:关闭节流,保持每条日志立即单独发送
|
|
10
|
+
*/
|
|
11
|
+
throttleMs?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface ScanOrderLoggerProviderGrafanaConfig {
|
|
14
|
+
endpoint?: string;
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
export interface ScanOrderLoggerProviderConfig {
|
|
18
|
+
feishu?: ScanOrderLoggerProviderFeishuConfig;
|
|
19
|
+
grafana?: ScanOrderLoggerProviderGrafanaConfig;
|
|
20
|
+
}
|
|
21
|
+
export interface ScanOrderLoggerContext {
|
|
22
|
+
cacheId?: string;
|
|
23
|
+
solutionName?: string;
|
|
24
|
+
moduleName?: string;
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}
|
|
27
|
+
export interface ScanOrderLogInput {
|
|
28
|
+
level?: ScanOrderLogLevel;
|
|
29
|
+
title: string;
|
|
30
|
+
payload?: Record<string, any>;
|
|
31
|
+
extra?: Record<string, any>;
|
|
32
|
+
timestamp?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ScanOrderLogRecord {
|
|
35
|
+
level: ScanOrderLogLevel;
|
|
36
|
+
title: string;
|
|
37
|
+
timestamp: string;
|
|
38
|
+
payload: Record<string, any>;
|
|
39
|
+
extra: Record<string, any>;
|
|
40
|
+
context: ScanOrderLoggerContext;
|
|
41
|
+
}
|
|
42
|
+
export interface ScanOrderLoggerDispatchPayload {
|
|
43
|
+
record: ScanOrderLogRecord;
|
|
44
|
+
providerConfig?: ScanOrderLoggerProviderConfig;
|
|
45
|
+
}
|
|
46
|
+
export interface ScanOrderLoggerProvider {
|
|
47
|
+
send: (payload: ScanOrderLoggerDispatchPayload) => Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
export interface ScanOrderLoggerState {
|
|
50
|
+
provider: ScanOrderLoggerProviderType;
|
|
51
|
+
providerConfig: ScanOrderLoggerProviderConfig;
|
|
52
|
+
context: ScanOrderLoggerContext;
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -60,8 +60,8 @@ var isInStandardSchedule = function isInStandardSchedule(targetDate, targetDateS
|
|
|
60
60
|
var startDate = dayjs(schedule.start_time);
|
|
61
61
|
var endDate = dayjs(schedule.end_time);
|
|
62
62
|
|
|
63
|
-
//
|
|
64
|
-
var isInBasicRange = targetDate.isSameOrAfter(startDate) && targetDate.
|
|
63
|
+
// 先检查是否在基础时间范围内(不考虑重复),end 为开区间
|
|
64
|
+
var isInBasicRange = targetDate.isSameOrAfter(startDate) && targetDate.isBefore(endDate);
|
|
65
65
|
if (schedule.repeat_type === 'none') {
|
|
66
66
|
return isInBasicRange;
|
|
67
67
|
}
|
|
@@ -75,24 +75,18 @@ var isInTimeSlotsSchedule = function isInTimeSlotsSchedule(targetDate, targetDat
|
|
|
75
75
|
if (!schedule.start_time) {
|
|
76
76
|
return false;
|
|
77
77
|
}
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
// 检查日期是否匹配
|
|
81
|
-
if (targetDateString !== scheduleDate) {
|
|
78
|
+
var scheduleStartDate = dayjs(schedule.start_time.split(' ')[0]);
|
|
79
|
+
if (!isDateInTimeSlotsSchedule(targetDate, schedule, scheduleStartDate)) {
|
|
82
80
|
return false;
|
|
83
81
|
}
|
|
84
|
-
|
|
85
|
-
// 检查是否在任一时间段内
|
|
86
82
|
var _iterator2 = _createForOfIteratorHelper(schedule.time_slot),
|
|
87
83
|
_step2;
|
|
88
84
|
try {
|
|
89
85
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
90
86
|
var timeSlot = _step2.value;
|
|
91
|
-
var slotStart = "".concat(
|
|
92
|
-
var slotEnd = "".concat(
|
|
93
|
-
|
|
94
|
-
var slotEndDate = dayjs(slotEnd);
|
|
95
|
-
if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
|
|
87
|
+
var slotStart = dayjs("".concat(targetDateString, " ").concat(timeSlot.start_time, ":00"));
|
|
88
|
+
var slotEnd = dayjs("".concat(targetDateString, " ").concat(timeSlot.end_time, ":00"));
|
|
89
|
+
if (targetDate.isSameOrAfter(slotStart) && targetDate.isBefore(slotEnd)) {
|
|
96
90
|
return true;
|
|
97
91
|
}
|
|
98
92
|
}
|
|
@@ -120,7 +114,7 @@ var isInDesignationSchedule = function isInDesignationSchedule(targetDate, targe
|
|
|
120
114
|
var endDateTime = "".concat(designation.end_date, " ").concat(designation.end_time, ":00");
|
|
121
115
|
var startDate = dayjs(startDateTime);
|
|
122
116
|
var endDate = dayjs(endDateTime);
|
|
123
|
-
if (targetDate.isSameOrAfter(startDate) && targetDate.
|
|
117
|
+
if (targetDate.isSameOrAfter(startDate) && targetDate.isBefore(endDate)) {
|
|
124
118
|
return true;
|
|
125
119
|
}
|
|
126
120
|
}
|
|
@@ -218,9 +212,8 @@ var isInDailyRepeat = function isInDailyRepeat(targetDate, startDate, endDate, r
|
|
|
218
212
|
var startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
219
213
|
var endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
220
214
|
|
|
221
|
-
// 每日重复:每天都在相同的时间段内有效
|
|
222
|
-
|
|
223
|
-
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
215
|
+
// 每日重复:每天都在相同的时间段内有效 [start, end)
|
|
216
|
+
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay < endTimeOfDay;
|
|
224
217
|
};
|
|
225
218
|
|
|
226
219
|
// 每周重复逻辑
|
|
@@ -247,7 +240,7 @@ var isInWeeklyRepeat = function isInWeeklyRepeat(targetDate, startDate, endDate,
|
|
|
247
240
|
var targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
248
241
|
var startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
249
242
|
var endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
250
|
-
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay
|
|
243
|
+
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay < endTimeOfDay;
|
|
251
244
|
};
|
|
252
245
|
|
|
253
246
|
// 日程时间段类型
|