@pisell/pisellos 2.2.309 → 2.2.310

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 (121) hide show
  1. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  2. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  3. package/dist/modules/BookingContext/index.js +4 -4
  4. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
  5. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
  6. package/dist/modules/Customer/index.js +6 -3
  7. package/dist/modules/Customer/types.d.ts +2 -0
  8. package/dist/modules/Discount/availability.d.ts +7 -0
  9. package/dist/modules/Discount/availability.js +49 -0
  10. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  11. package/dist/modules/Discount/entitlementPass.js +147 -0
  12. package/dist/modules/Discount/index.d.ts +2 -2
  13. package/dist/modules/Discount/index.js +37 -151
  14. package/dist/modules/Discount/types.d.ts +36 -5
  15. package/dist/modules/OpenData/index.d.ts +1 -1
  16. package/dist/modules/OpenData/index.js +21 -12
  17. package/dist/modules/Order/index.d.ts +32 -4
  18. package/dist/modules/Order/index.js +733 -373
  19. package/dist/modules/Order/types.d.ts +17 -0
  20. package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
  21. package/dist/modules/Order/utils.d.ts +14 -2
  22. package/dist/modules/Order/utils.js +275 -76
  23. package/dist/modules/Payment/index.d.ts +0 -5
  24. package/dist/modules/Payment/index.js +35 -85
  25. package/dist/modules/Payment/types.d.ts +21 -1
  26. package/dist/modules/Payment/types.js +2 -0
  27. package/dist/modules/Payment/walletpass.d.ts +1 -1
  28. package/dist/modules/Payment/walletpass.js +80 -47
  29. package/dist/modules/ProductList/index.js +18 -5
  30. package/dist/modules/Rules/index.d.ts +2 -2
  31. package/dist/modules/Rules/index.js +480 -186
  32. package/dist/modules/Rules/types.d.ts +4 -0
  33. package/dist/server/index.js +8 -5
  34. package/dist/server/modules/order/index.js +6 -0
  35. package/dist/server/modules/order/types.d.ts +12 -0
  36. package/dist/server/modules/payment/index.d.ts +25 -6
  37. package/dist/server/modules/payment/index.js +660 -133
  38. package/dist/server/utils/small-ticket.d.ts +8 -5
  39. package/dist/server/utils/small-ticket.js +1269 -199
  40. package/dist/solution/BaseSales/index.d.ts +11 -2
  41. package/dist/solution/BaseSales/index.js +1463 -1173
  42. package/dist/solution/BaseSales/types.d.ts +7 -3
  43. package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
  44. package/dist/solution/BookingByStep/index.d.ts +1 -1
  45. package/dist/solution/BookingTicket/index.d.ts +12 -3
  46. package/dist/solution/BookingTicket/index.js +663 -542
  47. package/dist/solution/BookingTicket/types.d.ts +5 -1
  48. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  49. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
  50. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  51. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  52. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
  53. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  54. package/dist/solution/ShopDiscount/index.js +99 -42
  55. package/dist/solution/ShopDiscount/utils.d.ts +4 -2
  56. package/dist/solution/ShopDiscount/utils.js +43 -23
  57. package/dist/solution/UnifiedBookingSales/index.d.ts +2 -2
  58. package/dist/solution/UnifiedBookingSales/index.js +5 -5
  59. package/dist/utils/os-private-payload.d.ts +5 -0
  60. package/dist/utils/os-private-payload.js +17 -0
  61. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  62. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  63. package/lib/modules/BookingContext/index.js +3 -3
  64. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
  65. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
  66. package/lib/modules/Customer/index.js +5 -1
  67. package/lib/modules/Customer/types.d.ts +2 -0
  68. package/lib/modules/Discount/availability.d.ts +7 -0
  69. package/lib/modules/Discount/availability.js +43 -0
  70. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  71. package/lib/modules/Discount/entitlementPass.js +141 -0
  72. package/lib/modules/Discount/index.d.ts +2 -2
  73. package/lib/modules/Discount/index.js +23 -129
  74. package/lib/modules/Discount/types.d.ts +36 -5
  75. package/lib/modules/OpenData/index.d.ts +1 -1
  76. package/lib/modules/OpenData/index.js +11 -2
  77. package/lib/modules/Order/index.d.ts +32 -4
  78. package/lib/modules/Order/index.js +341 -71
  79. package/lib/modules/Order/types.d.ts +17 -0
  80. package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
  81. package/lib/modules/Order/utils.d.ts +14 -2
  82. package/lib/modules/Order/utils.js +186 -3
  83. package/lib/modules/Payment/index.d.ts +0 -5
  84. package/lib/modules/Payment/index.js +3 -28
  85. package/lib/modules/Payment/types.d.ts +21 -1
  86. package/lib/modules/Payment/types.js +1 -0
  87. package/lib/modules/Payment/walletpass.d.ts +1 -1
  88. package/lib/modules/Payment/walletpass.js +29 -9
  89. package/lib/modules/ProductList/index.js +14 -1
  90. package/lib/modules/Rules/index.d.ts +2 -2
  91. package/lib/modules/Rules/index.js +357 -110
  92. package/lib/modules/Rules/types.d.ts +4 -0
  93. package/lib/server/index.js +8 -5
  94. package/lib/server/modules/order/index.js +6 -0
  95. package/lib/server/modules/order/types.d.ts +12 -0
  96. package/lib/server/modules/payment/index.d.ts +25 -6
  97. package/lib/server/modules/payment/index.js +350 -78
  98. package/lib/server/utils/small-ticket.d.ts +8 -5
  99. package/lib/server/utils/small-ticket.js +1009 -121
  100. package/lib/solution/BaseSales/index.d.ts +11 -2
  101. package/lib/solution/BaseSales/index.js +164 -30
  102. package/lib/solution/BaseSales/types.d.ts +7 -3
  103. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
  104. package/lib/solution/BookingByStep/index.d.ts +1 -1
  105. package/lib/solution/BookingTicket/index.d.ts +12 -3
  106. package/lib/solution/BookingTicket/index.js +103 -41
  107. package/lib/solution/BookingTicket/types.d.ts +5 -1
  108. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  109. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
  110. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  111. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  112. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
  113. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  114. package/lib/solution/ShopDiscount/index.js +55 -9
  115. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  116. package/lib/solution/ShopDiscount/utils.js +42 -25
  117. package/lib/solution/UnifiedBookingSales/index.d.ts +2 -2
  118. package/lib/solution/UnifiedBookingSales/index.js +5 -5
  119. package/lib/utils/os-private-payload.d.ts +5 -0
  120. package/lib/utils/os-private-payload.js +22 -0
  121. package/package.json +1 -1
@@ -1,12 +1,22 @@
1
+ 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; }
2
+ 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; }
1
3
  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
4
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
5
  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; }
6
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
7
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
11
+ 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; }
4
12
  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; }
5
13
  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
14
  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
15
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
16
  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
17
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
18
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
19
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
10
20
  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
21
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
22
  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); }; }
@@ -18,9 +28,16 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
18
28
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
19
29
  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
30
  import { BaseModule } from "../../../modules/BaseModule";
31
+ import { isEqual } from 'lodash-es';
21
32
  var WALLET_PASS_CODE = 'WALLET_PASS';
22
33
  var WALLET_DEPENDENT_CODES = new Set(['PRODUCTVOUCHER', 'GIFTCARD', 'POINTCARD']);
23
34
  var PAYMENT_METHODS_LOADED_EVENT = 'payment:onPaymentMethodsLoaded';
35
+ var PAYMENT_METHODS_CHANGED_EVENT = 'payment:onPaymentMethodsChanged';
36
+ var PAYMENT_METHOD_STORE_NAME = 'pay_method';
37
+ var CUSTOM_PAYMENT_MODULE = 'custom_payment';
38
+ var PAYMENT_METHOD_SYNC_DEBOUNCE_MS = 500;
39
+ var SNAPSHOT_ORDER_FIELD = '__payment_snapshot_order';
40
+ var SNAPSHOT_SHOP_ID_FIELD = '__payment_snapshot_shop_id';
24
41
  export var PaymentServerModule = /*#__PURE__*/function (_BaseModule) {
25
42
  _inherits(PaymentServerModule, _BaseModule);
26
43
  var _super = _createSuper(PaymentServerModule);
@@ -33,16 +50,24 @@ export var PaymentServerModule = /*#__PURE__*/function (_BaseModule) {
33
50
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
34
51
  _defineProperty(_assertThisInitialized(_this), "app", void 0);
35
52
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
53
+ _defineProperty(_assertThisInitialized(_this), "dbManager", void 0);
36
54
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
37
- _defineProperty(_assertThisInitialized(_this), "payMethodMemoryCache", null);
38
- _defineProperty(_assertThisInitialized(_this), "payMethodListInFlight", null);
55
+ _defineProperty(_assertThisInitialized(_this), "paymentDataSource", void 0);
56
+ _defineProperty(_assertThisInitialized(_this), "initialLoadInFlight", null);
57
+ _defineProperty(_assertThisInitialized(_this), "refreshInFlight", null);
58
+ _defineProperty(_assertThisInitialized(_this), "hasLoadedPayMethods", false);
59
+ _defineProperty(_assertThisInitialized(_this), "hasEmittedLoaded", false);
60
+ _defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
61
+ _defineProperty(_assertThisInitialized(_this), "pendingMessageUuids", new Set());
62
+ _defineProperty(_assertThisInitialized(_this), "queuedTrailingRefresh", false);
63
+ _defineProperty(_assertThisInitialized(_this), "trailingMessageUuids", new Set());
39
64
  return _this;
40
65
  }
41
66
  _createClass(PaymentServerModule, [{
42
67
  key: "initialize",
43
68
  value: function () {
44
69
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
45
- var _this$app, _this$app2, _this$app3;
70
+ var _this$app, _this$app2, _this$app3, _this$app4;
46
71
  var appPlugin;
47
72
  return _regeneratorRuntime().wrap(function _callee$(_context) {
48
73
  while (1) switch (_context.prev = _context.next) {
@@ -57,16 +82,21 @@ export var PaymentServerModule = /*#__PURE__*/function (_BaseModule) {
57
82
  appPlugin = core.getPlugin('app');
58
83
  this.app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
59
84
  this.logger = (_this$app = this.app) === null || _this$app === void 0 ? void 0 : _this$app.logger;
60
- if (!(!this.request && !((_this$app2 = this.app) !== null && _this$app2 !== void 0 && _this$app2.request))) {
61
- _context.next = 10;
85
+ this.dbManager = (_this$app2 = this.app) === null || _this$app2 === void 0 ? void 0 : _this$app2.sqlite;
86
+ if (!(!this.request && !((_this$app3 = this.app) !== null && _this$app3 !== void 0 && _this$app3.request))) {
87
+ _context.next = 11;
62
88
  break;
63
89
  }
64
90
  throw new Error('PaymentServerModule 需要 request 插件或 app.request 支持');
65
- case 10:
91
+ case 11:
92
+ this.initPaymentDataSource();
93
+ this.setupPaymentMethodSync();
66
94
  this.logInfo('PaymentServerModule initialized successfully', {
67
- hasAppRequest: !!((_this$app3 = this.app) !== null && _this$app3 !== void 0 && _this$app3.request)
95
+ hasAppRequest: !!((_this$app4 = this.app) !== null && _this$app4 !== void 0 && _this$app4.request),
96
+ hasSQLite: !!this.dbManager,
97
+ hasPaymentDataSource: !!this.paymentDataSource
68
98
  });
69
- case 11:
99
+ case 14:
70
100
  case "end":
71
101
  return _context.stop();
72
102
  }
@@ -76,68 +106,97 @@ export var PaymentServerModule = /*#__PURE__*/function (_BaseModule) {
76
106
  return _initialize.apply(this, arguments);
77
107
  }
78
108
  return initialize;
79
- }() // getRoutes(): RouteDefinition[] {
80
- // return [
81
- // {
82
- // method: 'get',
83
- // path: '/pay/custom-payment/all',
84
- // handler: async ({ data, config }) => {
85
- // const payMethods = await this.getPayMethodListAsync({
86
- // shouldFilter: this.shouldFilterPayMethods(data, config),
87
- // });
88
- // return {
89
- // code: 200,
90
- // status: true,
91
- // data: payMethods,
92
- // };
93
- // },
94
- // },
95
- // ];
96
- // }
109
+ }()
97
110
  }, {
98
- key: "getPayMethodListAsync",
111
+ key: "preload",
99
112
  value: function () {
100
- var _getPayMethodListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
101
- var _this$payMethodMemory,
102
- _this2 = this;
103
- var options,
104
- _payMethods,
105
- payMethods,
106
- _args2 = arguments;
113
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
107
114
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
108
115
  while (1) switch (_context2.prev = _context2.next) {
109
116
  case 0:
110
- options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
111
- this.logInfo('Starting getPayMethodListAsync');
112
- if (!((_this$payMethodMemory = this.payMethodMemoryCache) !== null && _this$payMethodMemory !== void 0 && _this$payMethodMemory.length)) {
113
- _context2.next = 4;
117
+ _context2.prev = 0;
118
+ _context2.next = 3;
119
+ return this.ensureInitialPayMethods('preload');
120
+ case 3:
121
+ _context2.next = 8;
122
+ break;
123
+ case 5:
124
+ _context2.prev = 5;
125
+ _context2.t0 = _context2["catch"](0);
126
+ this.logError('preload 支付方式失败,保持空列表并允许后续读取重试', {
127
+ error: this.getErrorMessage(_context2.t0)
128
+ });
129
+ case 8:
130
+ case "end":
131
+ return _context2.stop();
132
+ }
133
+ }, _callee2, this, [[0, 5]]);
134
+ }));
135
+ function preload() {
136
+ return _preload.apply(this, arguments);
137
+ }
138
+ return preload;
139
+ }()
140
+ }, {
141
+ key: "getPayMethodListAsync",
142
+ value: function () {
143
+ var _getPayMethodListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
144
+ var options,
145
+ _args3 = arguments;
146
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
147
+ while (1) switch (_context3.prev = _context3.next) {
148
+ case 0:
149
+ options = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
150
+ this.logInfo('Starting getPayMethodListAsync', {
151
+ hasLoadedPayMethods: this.hasLoadedPayMethods,
152
+ cachedCount: this.store.payMethods.length
153
+ });
154
+ if (this.hasLoadedPayMethods) {
155
+ _context3.next = 13;
114
156
  break;
115
157
  }
116
- return _context2.abrupt("return", this.resolvePayMethods(this.payMethodMemoryCache, options));
117
- case 4:
118
- if (!this.payMethodListInFlight) {
119
- _context2.next = 9;
158
+ _context3.prev = 3;
159
+ _context3.next = 6;
160
+ return this.ensureInitialPayMethods('route');
161
+ case 6:
162
+ _context3.next = 11;
163
+ break;
164
+ case 8:
165
+ _context3.prev = 8;
166
+ _context3.t0 = _context3["catch"](3);
167
+ this.logError('getPayMethodListAsync 初始化失败', {
168
+ error: this.getErrorMessage(_context3.t0)
169
+ });
170
+ case 11:
171
+ _context3.next = 22;
172
+ break;
173
+ case 13:
174
+ if (this.paymentDataSource) {
175
+ _context3.next = 22;
120
176
  break;
121
177
  }
122
- _context2.next = 7;
123
- return this.payMethodListInFlight;
124
- case 7:
125
- _payMethods = _context2.sent;
126
- return _context2.abrupt("return", this.resolvePayMethods(_payMethods, options));
127
- case 9:
128
- this.payMethodListInFlight = this.loadPayMethodListAsync().finally(function () {
129
- _this2.payMethodListInFlight = null;
178
+ _context3.prev = 14;
179
+ _context3.next = 17;
180
+ return this.refreshPayMethodsSingleFlight({
181
+ trigger: 'compat.route',
182
+ emitChanged: false
130
183
  });
131
- _context2.next = 12;
132
- return this.payMethodListInFlight;
133
- case 12:
134
- payMethods = _context2.sent;
135
- return _context2.abrupt("return", this.resolvePayMethods(payMethods, options));
136
- case 14:
184
+ case 17:
185
+ _context3.next = 22;
186
+ break;
187
+ case 19:
188
+ _context3.prev = 19;
189
+ _context3.t1 = _context3["catch"](14);
190
+ this.logWarning('兼容模式远端刷新失败,保留当前运行态快照', {
191
+ error: this.getErrorMessage(_context3.t1)
192
+ });
193
+ case 22:
194
+ return _context3.abrupt("return", this.resolvePayMethods(this.store.payMethods, options));
195
+ case 23:
137
196
  case "end":
138
- return _context2.stop();
197
+ return _context3.stop();
139
198
  }
140
- }, _callee2, this);
199
+ }, _callee3, this, [[3, 8], [14, 19]]);
141
200
  }));
142
201
  function getPayMethodListAsync() {
143
202
  return _getPayMethodListAsync.apply(this, arguments);
@@ -145,70 +204,323 @@ export var PaymentServerModule = /*#__PURE__*/function (_BaseModule) {
145
204
  return getPayMethodListAsync;
146
205
  }()
147
206
  }, {
148
- key: "clearPayMethodCache",
149
- value: function clearPayMethodCache() {
150
- this.payMethodMemoryCache = null;
151
- this.store.payMethods = [];
207
+ key: "ensureInitialPayMethods",
208
+ value: function () {
209
+ var _ensureInitialPayMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(trigger) {
210
+ var _this2 = this;
211
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
212
+ while (1) switch (_context5.prev = _context5.next) {
213
+ case 0:
214
+ if (!this.hasLoadedPayMethods) {
215
+ _context5.next = 2;
216
+ break;
217
+ }
218
+ return _context5.abrupt("return", this.store.payMethods);
219
+ case 2:
220
+ if (!this.initialLoadInFlight) {
221
+ _context5.next = 4;
222
+ break;
223
+ }
224
+ return _context5.abrupt("return", this.initialLoadInFlight);
225
+ case 4:
226
+ this.initialLoadInFlight = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
227
+ var localSnapshot;
228
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
229
+ while (1) switch (_context4.prev = _context4.next) {
230
+ case 0:
231
+ _context4.next = 2;
232
+ return _this2.loadPayMethodsFromSQLite();
233
+ case 2:
234
+ localSnapshot = _context4.sent;
235
+ if (localSnapshot.available) {
236
+ _this2.setPayMethodMirror(localSnapshot.methods);
237
+ _this2.logInfo('从 SQLite 加载支付方式兜底快照', {
238
+ trigger: trigger,
239
+ count: localSnapshot.methods.length,
240
+ shopScope: _this2.resolveCurrentShopScope(localSnapshot.methods)
241
+ });
242
+ }
243
+ _context4.prev = 4;
244
+ _context4.next = 7;
245
+ return _this2.refreshPayMethodsSingleFlight({
246
+ trigger: trigger,
247
+ emitChanged: false
248
+ });
249
+ case 7:
250
+ _this2.hasLoadedPayMethods = true;
251
+ _context4.next = 16;
252
+ break;
253
+ case 10:
254
+ _context4.prev = 10;
255
+ _context4.t0 = _context4["catch"](4);
256
+ if (localSnapshot.available) {
257
+ _context4.next = 14;
258
+ break;
259
+ }
260
+ throw _context4.t0;
261
+ case 14:
262
+ _this2.hasLoadedPayMethods = true;
263
+ _this2.logWarning('远端刷新失败,继续使用 SQLite 支付方式快照', {
264
+ trigger: trigger,
265
+ count: localSnapshot.methods.length,
266
+ error: _this2.getErrorMessage(_context4.t0)
267
+ });
268
+ case 16:
269
+ if (_this2.hasEmittedLoaded) {
270
+ _context4.next = 20;
271
+ break;
272
+ }
273
+ _this2.hasEmittedLoaded = true;
274
+ _context4.next = 20;
275
+ return _this2.core.effects.emit(PAYMENT_METHODS_LOADED_EVENT, _this2.store.payMethods);
276
+ case 20:
277
+ return _context4.abrupt("return", _this2.store.payMethods);
278
+ case 21:
279
+ case "end":
280
+ return _context4.stop();
281
+ }
282
+ }, _callee4, null, [[4, 10]]);
283
+ }))().finally(function () {
284
+ _this2.initialLoadInFlight = null;
285
+ });
286
+ return _context5.abrupt("return", this.initialLoadInFlight);
287
+ case 6:
288
+ case "end":
289
+ return _context5.stop();
290
+ }
291
+ }, _callee5, this);
292
+ }));
293
+ function ensureInitialPayMethods(_x3) {
294
+ return _ensureInitialPayMethods.apply(this, arguments);
295
+ }
296
+ return ensureInitialPayMethods;
297
+ }()
298
+ }, {
299
+ key: "initPaymentDataSource",
300
+ value: function initPaymentDataSource() {
301
+ var _serverOptions;
302
+ var PaymentDataSourceClass = (_serverOptions = this.core.serverOptions) === null || _serverOptions === void 0 || (_serverOptions = _serverOptions.All_DATA_SOURCES) === null || _serverOptions === void 0 ? void 0 : _serverOptions.PaymentDataSource;
303
+ if (!PaymentDataSourceClass) {
304
+ this.logWarning('PaymentDataSource 不可用,使用无本地持久化的兼容模式');
305
+ return;
306
+ }
307
+ this.paymentDataSource = new PaymentDataSourceClass();
308
+ }
309
+ }, {
310
+ key: "setupPaymentMethodSync",
311
+ value: function setupPaymentMethodSync() {
312
+ var _this3 = this;
313
+ if (!this.paymentDataSource) return;
314
+ this.paymentDataSource.run({
315
+ pubsub: {
316
+ callback: function callback(res) {
317
+ var message = (res === null || res === void 0 ? void 0 : res.data) || res;
318
+ if (!message || message.module !== CUSTOM_PAYMENT_MODULE) return;
319
+ var messageUuid = String(message.message_uuid || '').trim();
320
+ if (messageUuid) _this3.pendingMessageUuids.add(messageUuid);
321
+ _this3.logInfo('收到 custom_payment Ably 消息,等待全量刷新', {
322
+ message_uuid: messageUuid || undefined,
323
+ action: message.action,
324
+ operation: message.operation
325
+ });
326
+ _this3.schedulePaymentMethodRefresh();
327
+ }
328
+ }
329
+ }).catch(function (error) {
330
+ _this3.logError('建立 custom_payment pubsub 订阅失败', {
331
+ error: _this3.getErrorMessage(error)
332
+ });
333
+ });
334
+ }
335
+ }, {
336
+ key: "schedulePaymentMethodRefresh",
337
+ value: function schedulePaymentMethodRefresh() {
338
+ var _this4 = this;
339
+ if (this.syncTimer) clearTimeout(this.syncTimer);
340
+ this.syncTimer = setTimeout(function () {
341
+ _this4.syncTimer = undefined;
342
+ var messageUuids = _toConsumableArray(_this4.pendingMessageUuids);
343
+ _this4.pendingMessageUuids.clear();
344
+ void _this4.refreshPayMethodsSingleFlight({
345
+ trigger: 'ably',
346
+ emitChanged: true,
347
+ messageUuids: messageUuids
348
+ }).catch(function (error) {
349
+ _this4.logError('custom_payment Ably 全量刷新失败,保留旧快照', {
350
+ message_uuids: messageUuids,
351
+ error: _this4.getErrorMessage(error)
352
+ });
353
+ });
354
+ }, PAYMENT_METHOD_SYNC_DEBOUNCE_MS);
152
355
  }
153
356
  }, {
154
- key: "loadPayMethodListAsync",
357
+ key: "refreshPayMethodsSingleFlight",
155
358
  value: function () {
156
- var _loadPayMethodListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
157
- var payMethods;
158
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
159
- while (1) switch (_context3.prev = _context3.next) {
359
+ var _refreshPayMethodsSingleFlight = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(context) {
360
+ var _this5 = this;
361
+ var _context$messageUuids, refreshTask, messageUuids;
362
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
363
+ while (1) switch (_context6.prev = _context6.next) {
160
364
  case 0:
161
- _context3.prev = 0;
162
- _context3.next = 3;
365
+ if (!this.refreshInFlight) {
366
+ _context6.next = 3;
367
+ break;
368
+ }
369
+ if (context.trigger.startsWith('ably')) {
370
+ this.queuedTrailingRefresh = true;
371
+ (_context$messageUuids = context.messageUuids) === null || _context$messageUuids === void 0 || _context$messageUuids.forEach(function (uuid) {
372
+ return _this5.trailingMessageUuids.add(uuid);
373
+ });
374
+ this.logInfo('支付方式刷新进行中,已排队一次尾随刷新', {
375
+ trigger: context.trigger,
376
+ message_uuids: context.messageUuids || []
377
+ });
378
+ }
379
+ return _context6.abrupt("return", this.refreshInFlight);
380
+ case 3:
381
+ refreshTask = this.performRemoteRefresh(context);
382
+ this.refreshInFlight = refreshTask;
383
+ _context6.prev = 5;
384
+ _context6.next = 8;
385
+ return refreshTask;
386
+ case 8:
387
+ return _context6.abrupt("return", _context6.sent);
388
+ case 9:
389
+ _context6.prev = 9;
390
+ if (this.refreshInFlight === refreshTask) this.refreshInFlight = null;
391
+ if (this.queuedTrailingRefresh) {
392
+ this.queuedTrailingRefresh = false;
393
+ messageUuids = _toConsumableArray(this.trailingMessageUuids);
394
+ this.trailingMessageUuids.clear();
395
+ void this.refreshPayMethodsSingleFlight({
396
+ trigger: 'ably.trailing',
397
+ emitChanged: true,
398
+ messageUuids: messageUuids
399
+ }).catch(function (error) {
400
+ _this5.logError('custom_payment 尾随刷新失败,保留当前快照', {
401
+ message_uuids: messageUuids,
402
+ error: _this5.getErrorMessage(error)
403
+ });
404
+ });
405
+ }
406
+ return _context6.finish(9);
407
+ case 13:
408
+ case "end":
409
+ return _context6.stop();
410
+ }
411
+ }, _callee6, this, [[5,, 9, 13]]);
412
+ }));
413
+ function refreshPayMethodsSingleFlight(_x4) {
414
+ return _refreshPayMethodsSingleFlight.apply(this, arguments);
415
+ }
416
+ return refreshPayMethodsSingleFlight;
417
+ }()
418
+ }, {
419
+ key: "performRemoteRefresh",
420
+ value: function () {
421
+ var _performRemoteRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(context) {
422
+ var oldMethods, payMethods, persisted, changed;
423
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
424
+ while (1) switch (_context7.prev = _context7.next) {
425
+ case 0:
426
+ oldMethods = this.store.payMethods;
427
+ _context7.next = 3;
163
428
  return this.fetchRemotePayMethods();
164
429
  case 3:
165
- payMethods = _context3.sent;
166
- this.setPayMethodCache(payMethods);
167
- _context3.next = 7;
168
- return this.core.effects.emit(PAYMENT_METHODS_LOADED_EVENT, payMethods);
169
- case 7:
170
- this.logInfo('getPayMethodListAsync completed successfully', {
171
- payMethods: payMethods
430
+ payMethods = _context7.sent;
431
+ _context7.next = 6;
432
+ return this.replacePayMethodsInSQLite(payMethods);
433
+ case 6:
434
+ persisted = _context7.sent;
435
+ if (!persisted) {
436
+ this.logWarning('SQLite 不可用,支付方式仅用于当前运行时', {
437
+ trigger: context.trigger,
438
+ count: payMethods.length
439
+ });
440
+ }
441
+ this.setPayMethodMirror(payMethods);
442
+ this.hasLoadedPayMethods = true;
443
+ changed = !this.arePayMethodsEqual(oldMethods, payMethods);
444
+ if (!(context.emitChanged && changed)) {
445
+ _context7.next = 14;
446
+ break;
447
+ }
448
+ _context7.next = 14;
449
+ return this.core.effects.emit(PAYMENT_METHODS_CHANGED_EVENT, {
450
+ oldMethods: oldMethods,
451
+ newMethods: this.store.payMethods
172
452
  });
173
- return _context3.abrupt("return", payMethods);
174
- case 11:
175
- _context3.prev = 11;
176
- _context3.t0 = _context3["catch"](0);
177
- console.error('[PaymentServerModule] 获取支付方式列表失败', _context3.t0);
178
- this.logError('getPayMethodListAsync failed', _context3.t0);
179
- return _context3.abrupt("return", []);
453
+ case 14:
454
+ this.logInfo('远端支付方式全量刷新成功', {
455
+ trigger: context.trigger,
456
+ message_uuids: context.messageUuids || [],
457
+ count: payMethods.length,
458
+ persisted: persisted,
459
+ changed: changed
460
+ });
461
+ return _context7.abrupt("return", this.store.payMethods);
180
462
  case 16:
181
463
  case "end":
182
- return _context3.stop();
464
+ return _context7.stop();
183
465
  }
184
- }, _callee3, this, [[0, 11]]);
466
+ }, _callee7, this);
185
467
  }));
186
- function loadPayMethodListAsync() {
187
- return _loadPayMethodListAsync.apply(this, arguments);
468
+ function performRemoteRefresh(_x5) {
469
+ return _performRemoteRefresh.apply(this, arguments);
188
470
  }
189
- return loadPayMethodListAsync;
471
+ return performRemoteRefresh;
190
472
  }()
191
473
  }, {
192
474
  key: "fetchRemotePayMethods",
193
475
  value: function () {
194
- var _fetchRemotePayMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
195
- var _this$app4;
196
- var requester, response, payMethods;
197
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
198
- while (1) switch (_context4.prev = _context4.next) {
476
+ var _fetchRemotePayMethods = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
477
+ var _this$app5;
478
+ var response, payMethods;
479
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
480
+ while (1) switch (_context8.prev = _context8.next) {
199
481
  case 0:
200
- requester = ((_this$app4 = this.app) === null || _this$app4 === void 0 ? void 0 : _this$app4.request) || this.request;
201
- _context4.next = 3;
202
- return requester.get('/shop/pay/custom-payment/all', undefined);
482
+ if (!this.paymentDataSource) {
483
+ _context8.next = 6;
484
+ break;
485
+ }
486
+ _context8.next = 3;
487
+ return this.paymentDataSource.run({
488
+ http: {
489
+ url: '/shop/pay/custom-payment/all'
490
+ }
491
+ });
203
492
  case 3:
204
- response = _context4.sent;
205
- payMethods = (response === null || response === void 0 ? void 0 : response.data) || response || [];
206
- return _context4.abrupt("return", Array.isArray(payMethods) ? payMethods : []);
493
+ _context8.t0 = _context8.sent;
494
+ _context8.next = 9;
495
+ break;
207
496
  case 6:
497
+ _context8.next = 8;
498
+ return (((_this$app5 = this.app) === null || _this$app5 === void 0 ? void 0 : _this$app5.request) || this.request).get('/shop/pay/custom-payment/all', undefined);
499
+ case 8:
500
+ _context8.t0 = _context8.sent;
501
+ case 9:
502
+ response = _context8.t0;
503
+ payMethods = (response === null || response === void 0 ? void 0 : response.data) !== undefined ? response.data : response;
504
+ if (Array.isArray(payMethods)) {
505
+ _context8.next = 13;
506
+ break;
507
+ }
508
+ throw new Error('支付方式全量接口返回值不是数组');
509
+ case 13:
510
+ if (!payMethods.some(function (method) {
511
+ return !method || method.id === undefined || method.id === null;
512
+ })) {
513
+ _context8.next = 15;
514
+ break;
515
+ }
516
+ throw new Error('支付方式全量接口存在缺少 id 的记录');
517
+ case 15:
518
+ return _context8.abrupt("return", payMethods);
519
+ case 16:
208
520
  case "end":
209
- return _context4.stop();
521
+ return _context8.stop();
210
522
  }
211
- }, _callee4, this);
523
+ }, _callee8, this);
212
524
  }));
213
525
  function fetchRemotePayMethods() {
214
526
  return _fetchRemotePayMethods.apply(this, arguments);
@@ -216,14 +528,213 @@ export var PaymentServerModule = /*#__PURE__*/function (_BaseModule) {
216
528
  return fetchRemotePayMethods;
217
529
  }()
218
530
  }, {
219
- key: "shouldFilterPayMethods",
220
- value: function shouldFilterPayMethods(data, config) {
221
- return (data === null || data === void 0 ? void 0 : data.filterPaymentMethods) === true || (config === null || config === void 0 ? void 0 : config.filterPaymentMethods) === true;
531
+ key: "loadPayMethodsFromSQLite",
532
+ value: function () {
533
+ var _loadPayMethodsFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
534
+ var _this6 = this;
535
+ var rows, currentShopScope, scopedRows, methods;
536
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
537
+ while (1) switch (_context9.prev = _context9.next) {
538
+ case 0:
539
+ if (this.dbManager) {
540
+ _context9.next = 2;
541
+ break;
542
+ }
543
+ return _context9.abrupt("return", {
544
+ available: false,
545
+ methods: []
546
+ });
547
+ case 2:
548
+ _context9.prev = 2;
549
+ _context9.next = 5;
550
+ return this.dbManager.getAll(PAYMENT_METHOD_STORE_NAME);
551
+ case 5:
552
+ rows = _context9.sent;
553
+ if (!(!Array.isArray(rows) || rows.length === 0)) {
554
+ _context9.next = 8;
555
+ break;
556
+ }
557
+ return _context9.abrupt("return", {
558
+ available: false,
559
+ methods: []
560
+ });
561
+ case 8:
562
+ currentShopScope = this.resolveCurrentShopScope();
563
+ if (currentShopScope) {
564
+ _context9.next = 12;
565
+ break;
566
+ }
567
+ this.logWarning('无法确认当前店铺,忽略 SQLite 支付方式快照');
568
+ return _context9.abrupt("return", {
569
+ available: false,
570
+ methods: []
571
+ });
572
+ case 12:
573
+ scopedRows = rows.filter(function (row) {
574
+ return String((row === null || row === void 0 ? void 0 : row[SNAPSHOT_SHOP_ID_FIELD]) || '') === currentShopScope;
575
+ });
576
+ if (!(scopedRows.length === 0)) {
577
+ _context9.next = 16;
578
+ break;
579
+ }
580
+ this.logWarning('忽略其他店铺的 SQLite 支付方式快照', {
581
+ currentShopScope: currentShopScope,
582
+ storedShopScopes: _toConsumableArray(new Set(rows.map(function (row) {
583
+ return String((row === null || row === void 0 ? void 0 : row[SNAPSHOT_SHOP_ID_FIELD]) || '');
584
+ }).filter(Boolean)))
585
+ });
586
+ return _context9.abrupt("return", {
587
+ available: false,
588
+ methods: []
589
+ });
590
+ case 16:
591
+ methods = scopedRows.slice().sort(function (left, right) {
592
+ return Number((left === null || left === void 0 ? void 0 : left[SNAPSHOT_ORDER_FIELD]) || 0) - Number((right === null || right === void 0 ? void 0 : right[SNAPSHOT_ORDER_FIELD]) || 0);
593
+ }).map(function (row) {
594
+ return _this6.stripSnapshotFields(row);
595
+ });
596
+ return _context9.abrupt("return", {
597
+ available: true,
598
+ methods: methods
599
+ });
600
+ case 20:
601
+ _context9.prev = 20;
602
+ _context9.t0 = _context9["catch"](2);
603
+ this.logWarning('从 SQLite 读取支付方式失败', {
604
+ error: this.getErrorMessage(_context9.t0)
605
+ });
606
+ return _context9.abrupt("return", {
607
+ available: false,
608
+ methods: []
609
+ });
610
+ case 24:
611
+ case "end":
612
+ return _context9.stop();
613
+ }
614
+ }, _callee9, this, [[2, 20]]);
615
+ }));
616
+ function loadPayMethodsFromSQLite() {
617
+ return _loadPayMethodsFromSQLite.apply(this, arguments);
618
+ }
619
+ return loadPayMethodsFromSQLite;
620
+ }()
621
+ }, {
622
+ key: "replacePayMethodsInSQLite",
623
+ value: function () {
624
+ var _replacePayMethodsInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(payMethods) {
625
+ var previousRows, shopScope, snapshotRows, writeError;
626
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
627
+ while (1) switch (_context10.prev = _context10.next) {
628
+ case 0:
629
+ if (this.dbManager) {
630
+ _context10.next = 2;
631
+ break;
632
+ }
633
+ return _context10.abrupt("return", false);
634
+ case 2:
635
+ _context10.next = 4;
636
+ return this.dbManager.getAll(PAYMENT_METHOD_STORE_NAME);
637
+ case 4:
638
+ previousRows = _context10.sent;
639
+ shopScope = this.resolveCurrentShopScope(payMethods);
640
+ snapshotRows = payMethods.map(function (method, index) {
641
+ return _objectSpread(_objectSpread({}, method), {}, _defineProperty(_defineProperty({}, SNAPSHOT_ORDER_FIELD, index), SNAPSHOT_SHOP_ID_FIELD, shopScope));
642
+ });
643
+ _context10.prev = 7;
644
+ _context10.next = 10;
645
+ return this.dbManager.clear(PAYMENT_METHOD_STORE_NAME);
646
+ case 10:
647
+ if (!(snapshotRows.length > 0)) {
648
+ _context10.next = 13;
649
+ break;
650
+ }
651
+ _context10.next = 13;
652
+ return this.dbManager.bulkAdd(PAYMENT_METHOD_STORE_NAME, snapshotRows);
653
+ case 13:
654
+ return _context10.abrupt("return", true);
655
+ case 16:
656
+ _context10.prev = 16;
657
+ _context10.t0 = _context10["catch"](7);
658
+ writeError = this.getErrorMessage(_context10.t0);
659
+ _context10.prev = 19;
660
+ _context10.next = 22;
661
+ return this.dbManager.clear(PAYMENT_METHOD_STORE_NAME);
662
+ case 22:
663
+ if (!(Array.isArray(previousRows) && previousRows.length > 0)) {
664
+ _context10.next = 25;
665
+ break;
666
+ }
667
+ _context10.next = 25;
668
+ return this.dbManager.bulkAdd(PAYMENT_METHOD_STORE_NAME, previousRows);
669
+ case 25:
670
+ _context10.next = 30;
671
+ break;
672
+ case 27:
673
+ _context10.prev = 27;
674
+ _context10.t1 = _context10["catch"](19);
675
+ this.logError('支付方式 SQLite 快照回滚失败', {
676
+ writeError: writeError,
677
+ rollbackError: this.getErrorMessage(_context10.t1)
678
+ });
679
+ case 30:
680
+ throw new Error("\u652F\u4ED8\u65B9\u5F0F SQLite \u5168\u91CF\u66FF\u6362\u5931\u8D25: ".concat(writeError));
681
+ case 31:
682
+ case "end":
683
+ return _context10.stop();
684
+ }
685
+ }, _callee10, this, [[7, 16], [19, 27]]);
686
+ }));
687
+ function replacePayMethodsInSQLite(_x6) {
688
+ return _replacePayMethodsInSQLite.apply(this, arguments);
689
+ }
690
+ return replacePayMethodsInSQLite;
691
+ }()
692
+ }, {
693
+ key: "resolveCurrentShopScope",
694
+ value: function resolveCurrentShopScope() {
695
+ var _this7 = this,
696
+ _ref2,
697
+ _ref3,
698
+ _ref4,
699
+ _selectedStore$id,
700
+ _payMethods$find;
701
+ var payMethods = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
702
+ var readStorageObject = function readStorageObject(key) {
703
+ try {
704
+ var _this7$app, _this7$app$getStorage;
705
+ var raw = (_this7$app = _this7.app) === null || _this7$app === void 0 || (_this7$app = _this7$app.storage) === null || _this7$app === void 0 || (_this7$app$getStorage = _this7$app.getStorage) === null || _this7$app$getStorage === void 0 ? void 0 : _this7$app$getStorage.call(_this7$app, key);
706
+ if (!raw) return {};
707
+ if (_typeof(raw) === 'object') return raw;
708
+ var parsed = JSON.parse(raw);
709
+ return parsed && _typeof(parsed) === 'object' ? parsed : {};
710
+ } catch (_unused) {
711
+ return {};
712
+ }
713
+ };
714
+ var selectedStore = readStorageObject('selectedStore');
715
+ var core = readStorageObject('core');
716
+ var scope = (_ref2 = (_ref3 = (_ref4 = (_selectedStore$id = selectedStore.id) !== null && _selectedStore$id !== void 0 ? _selectedStore$id : selectedStore.shop_id) !== null && _ref4 !== void 0 ? _ref4 : core.id) !== null && _ref3 !== void 0 ? _ref3 : core.shop_id) !== null && _ref2 !== void 0 ? _ref2 : (_payMethods$find = payMethods.find(function (method) {
717
+ return (method === null || method === void 0 ? void 0 : method.shop_id) != null;
718
+ })) === null || _payMethods$find === void 0 ? void 0 : _payMethods$find.shop_id;
719
+ return scope === undefined || scope === null ? '' : String(scope);
720
+ }
721
+ }, {
722
+ key: "stripSnapshotFields",
723
+ value: function stripSnapshotFields(row) {
724
+ var _snapshotOrder = row[SNAPSHOT_ORDER_FIELD],
725
+ _snapshotShopId = row[SNAPSHOT_SHOP_ID_FIELD],
726
+ method = _objectWithoutProperties(row, [SNAPSHOT_ORDER_FIELD, SNAPSHOT_SHOP_ID_FIELD].map(_toPropertyKey));
727
+ return method;
728
+ }
729
+ }, {
730
+ key: "arePayMethodsEqual",
731
+ value: function arePayMethodsEqual(left, right) {
732
+ return isEqual(left, right);
222
733
  }
223
734
  }, {
224
735
  key: "resolvePayMethods",
225
736
  value: function resolvePayMethods(payMethods, options) {
226
- if (!options.shouldFilter) return payMethods;
737
+ if (!options.shouldFilter) return _toConsumableArray(payMethods);
227
738
  return this.filterPayMethods(payMethods);
228
739
  }
229
740
  }, {
@@ -250,23 +761,28 @@ export var PaymentServerModule = /*#__PURE__*/function (_BaseModule) {
250
761
  return availableMethods;
251
762
  }
252
763
  }, {
253
- key: "setPayMethodCache",
254
- value: function setPayMethodCache(payMethods) {
255
- this.payMethodMemoryCache = payMethods;
256
- this.store.payMethods = payMethods;
764
+ key: "setPayMethodMirror",
765
+ value: function setPayMethodMirror(payMethods) {
766
+ this.store.payMethods = payMethods.map(function (method) {
767
+ return _objectSpread({}, method);
768
+ });
769
+ }
770
+ }, {
771
+ key: "getErrorMessage",
772
+ value: function getErrorMessage(error) {
773
+ return error instanceof Error ? error.message : String(error);
257
774
  }
258
775
  }, {
259
776
  key: "logInfo",
260
777
  value: function logInfo(title, metadata) {
261
778
  try {
262
- if (this.logger) {
263
- this.logger.addLog({
264
- type: 'info',
265
- title: "[PaymentServerModule] ".concat(title),
266
- metadata: metadata || {}
267
- });
268
- }
269
- } catch (_unused) {
779
+ var _this$logger;
780
+ (_this$logger = this.logger) === null || _this$logger === void 0 || _this$logger.addLog({
781
+ type: 'info',
782
+ title: "[PaymentServerModule] ".concat(title),
783
+ metadata: metadata || {}
784
+ });
785
+ } catch (_unused2) {
270
786
  // 日志记录失败不影响主流程
271
787
  }
272
788
  }
@@ -274,14 +790,13 @@ export var PaymentServerModule = /*#__PURE__*/function (_BaseModule) {
274
790
  key: "logWarning",
275
791
  value: function logWarning(title, metadata) {
276
792
  try {
277
- if (this.logger) {
278
- this.logger.addLog({
279
- type: 'warning',
280
- title: "[PaymentServerModule] ".concat(title),
281
- metadata: metadata || {}
282
- });
283
- }
284
- } catch (_unused2) {
793
+ var _this$logger2;
794
+ (_this$logger2 = this.logger) === null || _this$logger2 === void 0 || _this$logger2.addLog({
795
+ type: 'warning',
796
+ title: "[PaymentServerModule] ".concat(title),
797
+ metadata: metadata || {}
798
+ });
799
+ } catch (_unused3) {
285
800
  // 日志记录失败不影响主流程
286
801
  }
287
802
  }
@@ -289,17 +804,29 @@ export var PaymentServerModule = /*#__PURE__*/function (_BaseModule) {
289
804
  key: "logError",
290
805
  value: function logError(title, metadata) {
291
806
  try {
292
- if (this.logger) {
293
- this.logger.addLog({
294
- type: 'error',
295
- title: "[PaymentServerModule] ".concat(title),
296
- metadata: metadata || {}
297
- });
298
- }
299
- } catch (_unused3) {
807
+ var _this$logger3;
808
+ (_this$logger3 = this.logger) === null || _this$logger3 === void 0 || _this$logger3.addLog({
809
+ type: 'error',
810
+ title: "[PaymentServerModule] ".concat(title),
811
+ metadata: metadata || {}
812
+ });
813
+ } catch (_unused4) {
300
814
  // 日志记录失败不影响主流程
301
815
  }
302
816
  }
817
+ }, {
818
+ key: "destroy",
819
+ value: function destroy() {
820
+ var _this$paymentDataSour, _this$paymentDataSour2;
821
+ if (this.syncTimer) clearTimeout(this.syncTimer);
822
+ this.syncTimer = undefined;
823
+ this.pendingMessageUuids.clear();
824
+ this.trailingMessageUuids.clear();
825
+ this.queuedTrailingRefresh = false;
826
+ (_this$paymentDataSour = this.paymentDataSource) === null || _this$paymentDataSour === void 0 || (_this$paymentDataSour2 = _this$paymentDataSour.destroy) === null || _this$paymentDataSour2 === void 0 || _this$paymentDataSour2.call(_this$paymentDataSour);
827
+ this.paymentDataSource = undefined;
828
+ _get(_getPrototypeOf(PaymentServerModule.prototype), "destroy", this).call(this);
829
+ }
303
830
  }]);
304
831
  return PaymentServerModule;
305
832
  }(BaseModule);