@pisell/pisellos 2.3.172 → 2.3.174

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 (83) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +0 -1
  3. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +14 -8
  5. package/dist/modules/BookingContext/utils/productExtend.d.ts +5 -0
  6. package/dist/modules/BookingContext/utils/productExtend.js +61 -23
  7. package/dist/modules/Discount/index.js +0 -1
  8. package/dist/modules/OpenData/index.d.ts +1 -0
  9. package/dist/modules/OpenData/index.js +1 -0
  10. package/dist/modules/OpenData/salesSettings.d.ts +32 -0
  11. package/dist/modules/OpenData/salesSettings.js +80 -0
  12. package/dist/modules/OpenData/types.d.ts +13 -0
  13. package/dist/modules/Order/index.d.ts +3 -25
  14. package/dist/modules/Order/index.js +1313 -1772
  15. package/dist/modules/Order/types.d.ts +0 -7
  16. package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
  17. package/dist/modules/ProductList/index.js +12 -33
  18. package/dist/modules/Rules/index.d.ts +0 -2
  19. package/dist/modules/Rules/index.js +21 -29
  20. package/dist/solution/BaseSales/index.d.ts +1 -16
  21. package/dist/solution/BaseSales/index.js +1325 -1511
  22. package/dist/solution/BookingTicket/index.d.ts +2 -2
  23. package/dist/solution/BookingTicket/index.js +108 -200
  24. package/dist/solution/BookingTicket/types.d.ts +2 -14
  25. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  26. package/dist/solution/BookingTicket/utils/addProductDecision.js +3 -4
  27. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +58 -94
  28. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +0 -1
  29. package/dist/solution/BookingTicket/utils/scan/handleScan.js +1 -2
  30. package/dist/solution/UnifiedBookingSales/index.d.ts +23 -2
  31. package/dist/solution/UnifiedBookingSales/index.js +923 -683
  32. package/dist/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
  33. package/dist/solution/UnifiedBookingSales/salesSettings.js +81 -0
  34. package/dist/utils/platform.d.ts +0 -2
  35. package/dist/utils/platform.js +0 -6
  36. package/lib/index.d.ts +0 -1
  37. package/lib/index.js +0 -12
  38. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  39. package/lib/model/strategy/adapter/promotion/evaluator.js +13 -7
  40. package/lib/modules/BookingContext/utils/productExtend.d.ts +5 -0
  41. package/lib/modules/BookingContext/utils/productExtend.js +36 -3
  42. package/lib/modules/Discount/index.js +0 -1
  43. package/lib/modules/OpenData/index.d.ts +1 -0
  44. package/lib/modules/OpenData/index.js +12 -0
  45. package/lib/modules/OpenData/salesSettings.d.ts +32 -0
  46. package/lib/modules/OpenData/salesSettings.js +70 -0
  47. package/lib/modules/OpenData/types.d.ts +13 -0
  48. package/lib/modules/Order/index.d.ts +3 -25
  49. package/lib/modules/Order/index.js +38 -192
  50. package/lib/modules/Order/types.d.ts +0 -7
  51. package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
  52. package/lib/modules/ProductList/index.js +0 -15
  53. package/lib/modules/Rules/index.d.ts +0 -2
  54. package/lib/modules/Rules/index.js +0 -6
  55. package/lib/solution/BaseSales/index.d.ts +1 -16
  56. package/lib/solution/BaseSales/index.js +9 -89
  57. package/lib/solution/BookingTicket/index.d.ts +2 -2
  58. package/lib/solution/BookingTicket/index.js +2 -38
  59. package/lib/solution/BookingTicket/types.d.ts +2 -14
  60. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  61. package/lib/solution/BookingTicket/utils/addProductDecision.js +3 -4
  62. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +2 -14
  63. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +0 -1
  64. package/lib/solution/BookingTicket/utils/scan/handleScan.js +1 -2
  65. package/lib/solution/UnifiedBookingSales/index.d.ts +23 -2
  66. package/lib/solution/UnifiedBookingSales/index.js +131 -15
  67. package/lib/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
  68. package/lib/solution/UnifiedBookingSales/salesSettings.js +72 -0
  69. package/lib/utils/platform.d.ts +0 -2
  70. package/lib/utils/platform.js +0 -7
  71. package/package.json +1 -1
  72. package/dist/inventory/index.d.ts +0 -92
  73. package/dist/inventory/index.js +0 -509
  74. package/dist/modules/Order/utils/productVoucherGroups.d.ts +0 -15
  75. package/dist/modules/Order/utils/productVoucherGroups.js +0 -115
  76. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +0 -10
  77. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +0 -117
  78. package/lib/inventory/index.d.ts +0 -92
  79. package/lib/inventory/index.js +0 -287
  80. package/lib/modules/Order/utils/productVoucherGroups.d.ts +0 -15
  81. package/lib/modules/Order/utils/productVoucherGroups.js +0 -64
  82. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +0 -10
  83. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +0 -71
@@ -1,10 +0,0 @@
1
- import type { GlobalScanHandleResult, GlobalScanHostBridge } from '../../types';
2
- import { type GlobalScanApplyHost } from './applyGlobalScan';
3
- import type { GlobalScanFormattedResult } from './formatGlobalScan';
4
- export interface ProductVoucherCollectionScanHost extends GlobalScanApplyHost {
5
- waitForCustomerDiscounts(): Promise<void>;
6
- loadCustomerDiscounts(): Promise<Record<string, any>[]>;
7
- }
8
- /** Collect voucher candidates after customer binding and coupon loading finish.
9
- * Never expand a wristband's result to other orders of the same customer. */
10
- export declare function applyProductVoucherCollectionScan(host: ProductVoucherCollectionScanHost, formatted: GlobalScanFormattedResult, bridge: GlobalScanHostBridge): Promise<GlobalScanHandleResult>;
@@ -1,117 +0,0 @@
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
- import { applyGlobalScan } from "./applyGlobalScan";
11
- /** Collect voucher candidates after customer binding and coupon loading finish.
12
- * Never expand a wristband's result to other orders of the same customer. */
13
- export function applyProductVoucherCollectionScan(_x, _x2, _x3) {
14
- return _applyProductVoucherCollectionScan.apply(this, arguments);
15
- }
16
- function _applyProductVoucherCollectionScan() {
17
- _applyProductVoucherCollectionScan = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(host, formatted, bridge) {
18
- var assertCurrent, vouchers, result;
19
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
20
- while (1) switch (_context2.prev = _context2.next) {
21
- case 0:
22
- assertCurrent = function assertCurrent() {
23
- var _bridge$isCurrent;
24
- if (((_bridge$isCurrent = bridge.isCurrent) === null || _bridge$isCurrent === void 0 ? void 0 : _bridge$isCurrent.call(bridge)) === false) {
25
- throw new DOMException('Scan session ended', 'AbortError');
26
- }
27
- };
28
- vouchers = [];
29
- assertCurrent();
30
- _context2.next = 5;
31
- return applyGlobalScan(_objectSpread(_objectSpread({}, host), {}, {
32
- setOrderCustomer: function setOrderCustomer(customer) {
33
- assertCurrent();
34
- host.setOrderCustomer(customer);
35
- },
36
- addProductToOrder: function addProductToOrder(product, booking) {
37
- assertCurrent();
38
- return host.addProductToOrder(product, booking);
39
- }
40
- }), formatted, _objectSpread(_objectSpread({}, bridge), {}, {
41
- applyPromotionCode: bridge.applyPromotionCode && ( /*#__PURE__*/function () {
42
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(code, customerId, options) {
43
- var promotion;
44
- return _regeneratorRuntime().wrap(function _callee$(_context) {
45
- while (1) switch (_context.prev = _context.next) {
46
- case 0:
47
- _context.next = 2;
48
- return host.waitForCustomerDiscounts();
49
- case 2:
50
- assertCurrent();
51
- _context.next = 5;
52
- return bridge.applyPromotionCode(code, customerId, _objectSpread(_objectSpread({}, options), {}, {
53
- productVouchersOnly: true,
54
- suppressFailureNotification: true
55
- }));
56
- case 5:
57
- promotion = _context.sent;
58
- assertCurrent();
59
- // An empty successful search is different from a swallowed request error.
60
- if (Array.isArray(promotion.scannedDiscountList)) {
61
- _context.next = 9;
62
- break;
63
- }
64
- throw new Error('Could not resolve scanned vouchers');
65
- case 9:
66
- vouchers = promotion.scannedDiscountList;
67
- return _context.abrupt("return", promotion);
68
- case 11:
69
- case "end":
70
- return _context.stop();
71
- }
72
- }, _callee);
73
- }));
74
- return function (_x4, _x5, _x6) {
75
- return _ref.apply(this, arguments);
76
- };
77
- }())
78
- }));
79
- case 5:
80
- result = _context2.sent;
81
- assertCurrent();
82
- if (!(formatted.searchType === 'wallet' && result.status === 'success')) {
83
- _context2.next = 13;
84
- break;
85
- }
86
- _context2.next = 10;
87
- return host.loadCustomerDiscounts();
88
- case 10:
89
- vouchers = _context2.sent;
90
- assertCurrent();
91
- return _context2.abrupt("return", _objectSpread(_objectSpread({}, result), {}, {
92
- redemption: {
93
- source: 'wallet',
94
- vouchers: vouchers
95
- }
96
- }));
97
- case 13:
98
- if (!(formatted.searchType === 'walletPass')) {
99
- _context2.next = 15;
100
- break;
101
- }
102
- return _context2.abrupt("return", _objectSpread(_objectSpread({}, result), {}, {
103
- redemption: {
104
- source: 'scan',
105
- vouchers: vouchers
106
- }
107
- }));
108
- case 15:
109
- return _context2.abrupt("return", result);
110
- case 16:
111
- case "end":
112
- return _context2.stop();
113
- }
114
- }, _callee2);
115
- }));
116
- return _applyProductVoucherCollectionScan.apply(this, arguments);
117
- }
@@ -1,92 +0,0 @@
1
- /** Optional, instance-scoped sales inventory. Never stored in ProductData or order payloads. */
2
- export type InventoryRecord = Record<string, any>;
3
- export type InventoryRefreshReason = 'catalog-entry' | 'detail-open' | 'checkout' | 'manual';
4
- export interface InventoryAvailability {
5
- status: 'ready' | 'loading' | 'stale' | 'error' | 'unmapped';
6
- quantity?: number;
7
- message?: string;
8
- }
9
- export interface InventorySelectionAvailability {
10
- availability: InventoryAvailability;
11
- /** Stock remaining after other cart lines using the same inventory key. */
12
- availableQuantity: number;
13
- /** The existing line can still be reduced when stock is unavailable. */
14
- retainedQuantity: number;
15
- maxQuantity: number;
16
- }
17
- export interface InventorySource {
18
- readonly scopeKey: string;
19
- assertCurrent(): void;
20
- keyOf(product: InventoryRecord, variant?: InventoryRecord): string | undefined;
21
- read(context: {
22
- reason: InventoryRefreshReason;
23
- signal: AbortSignal;
24
- }): Promise<ReadonlyMap<string, {
25
- quantity: number | null;
26
- message?: string;
27
- }>>;
28
- message(reason: 'unavailable' | 'unmapped' | 'insufficient', values?: {
29
- key: string;
30
- quantity: number;
31
- }): string;
32
- }
33
- export interface CheckoutInventoryLine {
34
- readonly lineId: string;
35
- readonly productId: string | number;
36
- readonly variantId: string | number;
37
- readonly quantity: number;
38
- readonly inventoryKey: string;
39
- }
40
- export interface CheckoutRuntimeSnapshot {
41
- readonly scopeKey: string;
42
- readonly revision: number;
43
- readonly lines: readonly CheckoutInventoryLine[];
44
- }
45
- export interface SalesCheckoutHooks {
46
- beforeCheckout?(context: {
47
- items: readonly InventoryRecord[];
48
- signal?: AbortSignal;
49
- }): Promise<void>;
50
- }
51
- export declare const salesGuardError: (message: string) => Error & {
52
- code: string;
53
- };
54
- export declare class InventoryController {
55
- private readonly source;
56
- readonly identity: symbol;
57
- readonly scopeKey: string;
58
- private entries;
59
- private lastQuantities;
60
- private products;
61
- private keys;
62
- private catalogProducts;
63
- private listeners;
64
- private revision;
65
- private state;
66
- private pending?;
67
- private disposed;
68
- constructor(source: InventorySource);
69
- getRevision: () => number;
70
- subscribe: (listener: () => void) => () => void;
71
- private publish;
72
- private assertCurrent;
73
- activate(): void;
74
- dispose(): void;
75
- invalidate(): void;
76
- /** Catalog replaces identities; partial detail only merges its variants, never its prices. */
77
- registerProducts(products: readonly InventoryRecord[], complete?: boolean): void;
78
- /** Consumers share I/O; cancelling one detail does not cancel another consumer. */
79
- refresh(context: {
80
- reason: InventoryRefreshReason;
81
- signal?: AbortSignal;
82
- force?: boolean;
83
- }): Promise<void>;
84
- availabilityForKey(key?: string): InventoryAvailability;
85
- availability(product: InventoryRecord, variantId?: string | number): InventoryAvailability;
86
- private keyForLine;
87
- /** Advisory UI limit only. The serialized cart guard remains authoritative. */
88
- selectionAvailability(product: InventoryRecord, variantId: string | number, items: readonly InventoryRecord[], editingItem?: InventoryRecord): InventorySelectionAvailability;
89
- private totals;
90
- validate(proposed: readonly InventoryRecord[], current?: readonly InventoryRecord[], allowReductions?: boolean): void;
91
- freezeCheckout(items: readonly InventoryRecord[]): CheckoutRuntimeSnapshot;
92
- }
@@ -1,287 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.salesGuardError = exports.InventoryController = void 0;
7
- /** Optional, instance-scoped sales inventory. Never stored in ProductData or order payloads. */
8
-
9
- const salesGuardError = message => Object.assign(new Error(message), {
10
- code: 'SALES_GUARD_REJECTED'
11
- });
12
- exports.salesGuardError = salesGuardError;
13
- const cancelled = () => Object.assign(new Error('Inventory request cancelled'), {
14
- name: 'AbortError'
15
- });
16
- const variantIdentity = (productId, variantId) => JSON.stringify([String(productId), String(variantId ?? 0)]);
17
- class InventoryController {
18
- identity = Symbol('sales-inventory-instance');
19
- scopeKey;
20
- entries = new Map();
21
- lastQuantities = new Map();
22
- products = new Map();
23
- keys = new Map();
24
- catalogProducts = new Map();
25
- listeners = new Set();
26
- revision = 0;
27
- state = 'stale';
28
- pending;
29
- disposed = false;
30
- constructor(source) {
31
- this.source = source;
32
- this.scopeKey = source.scopeKey;
33
- }
34
- getRevision = () => this.revision;
35
- subscribe = listener => {
36
- this.listeners.add(listener);
37
- return () => {
38
- this.listeners.delete(listener);
39
- };
40
- };
41
- publish() {
42
- this.revision += 1;
43
- this.listeners.forEach(listener => {
44
- try {
45
- listener();
46
- } catch {/* A view cannot interrupt a stock update. */}
47
- });
48
- }
49
- assertCurrent(signal) {
50
- if (this.disposed || signal?.aborted) throw cancelled();
51
- this.source.assertCurrent();
52
- }
53
- activate() {
54
- this.disposed = false;
55
- }
56
- dispose() {
57
- this.disposed = true;
58
- this.invalidate();
59
- }
60
- invalidate() {
61
- this.pending?.controller.abort();
62
- this.pending = undefined;
63
- this.state = 'stale';
64
- this.publish();
65
- }
66
-
67
- /** Catalog replaces identities; partial detail only merges its variants, never its prices. */
68
- registerProducts(products, complete = false) {
69
- this.assertCurrent();
70
- let changed = false;
71
- for (const product of products) {
72
- const id = String(product.id ?? product.product_id);
73
- if (complete && this.catalogProducts.get(id) === product) continue;
74
- if (complete) this.catalogProducts.set(id, product);
75
- const previous = this.products.get(id);
76
- if (complete) for (const variantId of previous?.keys() || []) this.keys.delete(variantIdentity(id, variantId));
77
- const variants = complete ? new Map() : new Map(previous);
78
- const list = product.variant?.length ? product.variant : [{
79
- id: 0,
80
- code: product.code
81
- }];
82
- for (const variant of list) {
83
- const variantId = String(variant.id ?? variant.product_variant_id ?? 0);
84
- const key = this.source.keyOf(product, variant) ?? previous?.get(variantId);
85
- variants.set(variantId, key);
86
- this.keys.set(variantIdentity(id, variantId), key);
87
- }
88
- if (!previous || previous.size !== variants.size || [...variants].some(([id, key]) => previous.get(id) !== key)) changed = true;
89
- this.products.set(id, variants);
90
- }
91
- if (changed) this.publish();
92
- }
93
-
94
- /** Consumers share I/O; cancelling one detail does not cancel another consumer. */
95
- async refresh(context) {
96
- this.assertCurrent(context.signal);
97
- if (context.force) this.invalidate();
98
- let read = this.pending;
99
- if (!read) {
100
- read = {
101
- controller: new AbortController(),
102
- consumers: 0,
103
- promise: Promise.resolve()
104
- };
105
- const current = read;
106
- this.pending = current;
107
- this.state = 'loading';
108
- this.publish();
109
- current.promise = (async () => {
110
- try {
111
- const entries = await this.source.read({
112
- reason: context.reason,
113
- signal: current.controller.signal
114
- });
115
- this.assertCurrent(current.controller.signal);
116
- if (this.pending !== current) throw cancelled();
117
- this.entries = entries;
118
- for (const [key, stock] of entries) if (stock.quantity !== null && Number.isSafeInteger(stock.quantity) && stock.quantity >= 0) this.lastQuantities.set(key, stock.quantity);
119
- this.state = 'ready';
120
- } catch (error) {
121
- if (this.pending !== current || current.controller.signal.aborted) throw cancelled();
122
- this.state = 'error';
123
- throw error;
124
- } finally {
125
- if (this.pending === current) {
126
- this.pending = undefined;
127
- this.publish();
128
- }
129
- }
130
- })();
131
- }
132
- read.consumers += 1;
133
- try {
134
- if (!context.signal) await read.promise;else await new Promise((resolve, reject) => {
135
- const signal = context.signal;
136
- const abort = () => reject(cancelled());
137
- signal.addEventListener('abort', abort, {
138
- once: true
139
- });
140
- read.promise.then(resolve, reject).finally(() => signal.removeEventListener('abort', abort));
141
- if (signal.aborted) abort();
142
- });
143
- this.assertCurrent(context.signal);
144
- } finally {
145
- read.consumers -= 1;
146
- if (this.pending === read && read.consumers === 0) this.invalidate();
147
- }
148
- }
149
- availabilityForKey(key) {
150
- const stock = key ? this.entries.get(key) : undefined;
151
- const quantity = key ? this.lastQuantities.get(key) : undefined;
152
- if (this.state !== 'ready') return {
153
- status: this.state,
154
- quantity,
155
- message: this.source.message('unavailable')
156
- };
157
- if (!stock) return {
158
- status: 'unmapped',
159
- quantity,
160
- message: this.source.message('unmapped')
161
- };
162
- if (stock.quantity === null || !Number.isSafeInteger(stock.quantity) || stock.quantity < 0) return {
163
- status: 'error',
164
- quantity,
165
- message: stock.message || this.source.message('unavailable')
166
- };
167
- return {
168
- status: 'ready',
169
- quantity: stock.quantity
170
- };
171
- }
172
- availability(product, variantId) {
173
- const id = product.id ?? product.product_id;
174
- if (variantId !== undefined && variantId !== null) return this.availabilityForKey(this.keys.get(variantIdentity(id, variantId)));
175
- const keys = [...new Set(this.products.get(String(id))?.values() || [])];
176
- const states = keys.map(key => this.availabilityForKey(key));
177
- if (!states.length) return this.availabilityForKey();
178
- // Unmapped variants are not offered by this source. Exclude even their last
179
- // known quantities, while preserving errors on variants that are configured.
180
- const mappedStates = states.filter(entry => entry.status !== 'unmapped');
181
- if (!mappedStates.length) return {
182
- status: 'unmapped',
183
- message: this.source.message('unmapped')
184
- };
185
- const quantity = mappedStates.every(entry => entry.quantity !== undefined) ? mappedStates.reduce((sum, entry) => sum + entry.quantity, 0) : undefined;
186
- const failed = mappedStates.find(entry => entry.status !== 'ready');
187
- if (quantity !== undefined && !Number.isSafeInteger(quantity)) return {
188
- status: 'error',
189
- message: this.source.message('unavailable')
190
- };
191
- return {
192
- status: failed?.status || 'ready',
193
- quantity,
194
- message: failed?.message
195
- };
196
- }
197
- keyForLine(item) {
198
- return this.keys.get(variantIdentity(item.product_id, item.product_variant_id ?? item.product_sku?.product_variant_id));
199
- }
200
- /** Advisory UI limit only. The serialized cart guard remains authoritative. */
201
- selectionAvailability(product, variantId, items, editingItem) {
202
- const identity = variantIdentity(product.id ?? product.product_id, variantId);
203
- const key = this.keys.get(identity);
204
- let availability = this.availabilityForKey(key);
205
- let reserved = 0;
206
- let retainedQuantity = 0;
207
- for (const item of items) {
208
- const matches = key ? this.keyForLine(item) === key : variantIdentity(item.product_id, item.product_variant_id ?? item.product_sku?.product_variant_id) === identity;
209
- if (!matches) continue;
210
- const count = Number(item.num ?? item.quantity);
211
- if (!Number.isSafeInteger(count) || count < 0) {
212
- availability = {
213
- ...availability,
214
- status: 'error',
215
- message: this.source.message('unavailable')
216
- };
217
- continue;
218
- }
219
- if (item === editingItem) retainedQuantity = count;else reserved += count;
220
- }
221
- if (!Number.isSafeInteger(reserved)) {
222
- availability = {
223
- ...availability,
224
- status: 'error',
225
- message: this.source.message('unavailable')
226
- };
227
- }
228
- const availableQuantity = availability.status === 'ready' ? Math.max(0, availability.quantity - reserved) : 0;
229
- return {
230
- availability,
231
- availableQuantity,
232
- retainedQuantity,
233
- maxQuantity: Math.max(availableQuantity, retainedQuantity)
234
- };
235
- }
236
- totals(items) {
237
- const totals = new Map();
238
- for (const item of items) {
239
- const key = this.keyForLine(item);
240
- const identity = key ? JSON.stringify(['inventory', key]) : variantIdentity(item.product_id, item.product_variant_id);
241
- const quantity = Number(item.num ?? item.quantity);
242
- if (!Number.isSafeInteger(quantity) || quantity < 0) throw salesGuardError(this.source.message('unavailable'));
243
- if (!quantity) continue;
244
- const total = (totals.get(identity)?.quantity || 0) + quantity;
245
- if (!Number.isSafeInteger(total)) throw salesGuardError(this.source.message('unavailable'));
246
- totals.set(identity, {
247
- key,
248
- quantity: total
249
- });
250
- }
251
- return totals;
252
- }
253
- validate(proposed, current = [], allowReductions = true) {
254
- this.assertCurrent();
255
- const previous = this.totals(current);
256
- for (const [identity, {
257
- key,
258
- quantity
259
- }] of this.totals(proposed)) {
260
- if (allowReductions && quantity <= (previous.get(identity)?.quantity || 0)) continue;
261
- const stock = this.availabilityForKey(key);
262
- if (stock.status !== 'ready') throw salesGuardError(stock.message || this.source.message('unavailable'));
263
- if (quantity > stock.quantity) throw salesGuardError(this.source.message('insufficient', {
264
- key: key,
265
- quantity: stock.quantity
266
- }));
267
- }
268
- }
269
- freezeCheckout(items) {
270
- if (!items.length || items.some(item => Number(item.num ?? item.quantity) <= 0)) {
271
- throw salesGuardError(this.source.message('unavailable'));
272
- }
273
- this.validate(items, [], false);
274
- return Object.freeze({
275
- scopeKey: this.scopeKey,
276
- revision: this.revision,
277
- lines: Object.freeze(items.map((item, index) => Object.freeze({
278
- lineId: String(item.metadata?.unique_identification_number ?? item.unique_identification_number ?? item.order_detail_id ?? index),
279
- productId: item.product_id,
280
- variantId: item.product_variant_id ?? item.product_sku?.product_variant_id ?? 0,
281
- quantity: Number(item.num ?? item.quantity),
282
- inventoryKey: this.keyForLine(item)
283
- })))
284
- });
285
- }
286
- }
287
- exports.InventoryController = InventoryController;
@@ -1,15 +0,0 @@
1
- import type { Discount } from '../../Discount/types';
2
- import type { OrderTempOrder } from '../types';
3
- /** Runtime-only allocation constraints. Never copied into order/product metadata. */
4
- export interface ProductVoucherGroup {
5
- key: string;
6
- discountIds: Array<number | string>;
7
- }
8
- export declare function productVoucherGroupKey(order: OrderTempOrder, product: any): string | undefined;
9
- export declare function isUsableProductVoucher(discount: Discount): boolean;
10
- export declare function voucherGroupError(): Error & {
11
- code: string;
12
- };
13
- export declare function allowsProductVoucher(order: OrderTempOrder | null | undefined, product: any, discount: Discount): boolean;
14
- /** Reductions stay possible when a voucher expires; checkout always requires full coverage. */
15
- export declare function validateProductVoucherGroups(order: OrderTempOrder, discounts: Discount[], previous?: OrderTempOrder, requireCoverage?: boolean): void;
@@ -1,64 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.allowsProductVoucher = allowsProductVoucher;
7
- exports.isUsableProductVoucher = isUsableProductVoucher;
8
- exports.productVoucherGroupKey = productVoucherGroupKey;
9
- exports.validateProductVoucherGroups = validateProductVoucherGroups;
10
- exports.voucherGroupError = voucherGroupError;
11
- var _availability = require("../../Discount/availability");
12
- var _dayjs = _interopRequireDefault(require("dayjs"));
13
- var _utils = require("../../../solution/ShopDiscount/utils");
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
- /** Runtime-only allocation constraints. Never copied into order/product metadata. */
16
-
17
- function productVoucherGroupKey(order, product) {
18
- const uid = product?.metadata?.unique_identification_number ?? product?.unique_identification_number;
19
- return order._extend?.productsByUid?.[String(uid)]?.productVoucherGroupKey;
20
- }
21
- function isUsableProductVoucher(discount) {
22
- return (discount.tag || discount.type) === 'good_pass' && !discount.isEditMode && !discount.isDisabled && !(0, _availability.getDiscountUsageBlockReason)(discount) && !(0, _utils.getDiscountTimeUnavailableReason)(discount, (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss'));
23
- }
24
- function voucherGroupError() {
25
- return Object.assign(new Error('The selected items no longer match the available vouchers. Please adjust your selection.'), {
26
- code: 'PRODUCT_VOUCHER_GROUP_INVALID'
27
- });
28
- }
29
- function allowsProductVoucher(order, product, discount) {
30
- const groups = order?._extend?.productVoucherGroups;
31
- if (!order || !groups?.length) return true;
32
- const key = productVoucherGroupKey(order, product);
33
- if (!key) return !groups.some(group => group.discountIds.some(id => String(id) === String(discount.id)));
34
- return (discount.tag || discount.type) === 'good_pass' && Boolean(groups.find(group => group.key === key)?.discountIds.some(id => String(id) === String(discount.id)));
35
- }
36
-
37
- /** Reductions stay possible when a voucher expires; checkout always requires full coverage. */
38
- function validateProductVoucherGroups(order, discounts, previous, requireCoverage = false) {
39
- const groups = order._extend?.productVoucherGroups;
40
- if (!groups?.length) return;
41
- const usedIds = new Set();
42
- const byId = new Map(discounts.filter(isUsableProductVoucher).map(discount => [String(discount.id), discount]));
43
- const quantity = item => Number(item.num ?? item.product_quantity ?? 0);
44
- for (const group of groups) {
45
- const items = order.products.filter(item => productVoucherGroupKey(order, item) === group.key);
46
- const selected = items.reduce((sum, item) => sum + quantity(item), 0);
47
- const before = previous?.products.filter(item => productVoucherGroupKey(previous, item) === group.key).reduce((sum, item) => sum + quantity(item), 0) ?? 0;
48
- if (!requireCoverage && previous && selected <= before) continue;
49
- const ids = new Set(group.discountIds.map(String).filter(id => byId.has(id)));
50
- if (!Number.isInteger(selected) || selected < 0 || selected > ids.size) throw voucherGroupError();
51
- if (!requireCoverage) continue;
52
- for (const item of items) {
53
- const applied = (item.discount_list || []).filter(entry => (entry.type || entry.tag) === 'good_pass');
54
- // Rules splits a good_pass allocation into one physical line per instance.
55
- const id = String(applied[0]?.discount?.resource_id ?? '');
56
- const voucher = byId.get(id);
57
- if (quantity(item) !== 1 || applied.length !== 1 || !ids.has(id) || !voucher?.isAvailable || voucher.config?.isAvailable === false || usedIds.has(id)) throw voucherGroupError();
58
- usedIds.add(id);
59
- }
60
- }
61
- if (order.products.some(item => !groups.some(group => group.key === productVoucherGroupKey(order, item)))) {
62
- throw voucherGroupError();
63
- }
64
- }
@@ -1,10 +0,0 @@
1
- import type { GlobalScanHandleResult, GlobalScanHostBridge } from '../../types';
2
- import { type GlobalScanApplyHost } from './applyGlobalScan';
3
- import type { GlobalScanFormattedResult } from './formatGlobalScan';
4
- export interface ProductVoucherCollectionScanHost extends GlobalScanApplyHost {
5
- waitForCustomerDiscounts(): Promise<void>;
6
- loadCustomerDiscounts(): Promise<Record<string, any>[]>;
7
- }
8
- /** Collect voucher candidates after customer binding and coupon loading finish.
9
- * Never expand a wristband's result to other orders of the same customer. */
10
- export declare function applyProductVoucherCollectionScan(host: ProductVoucherCollectionScanHost, formatted: GlobalScanFormattedResult, bridge: GlobalScanHostBridge): Promise<GlobalScanHandleResult>;