@pisell/pisellos 2.2.291 → 2.2.293

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 (174) hide show
  1. package/dist/core/index.d.ts +7 -0
  2. package/dist/core/index.js +108 -65
  3. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  4. package/dist/model/strategy/adapter/itemRule/adapter.js +135 -35
  5. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  6. package/dist/model/strategy/adapter/itemRule/evaluator.js +25 -1
  7. package/dist/model/strategy/adapter/itemRule/type.d.ts +44 -0
  8. package/dist/model/strategy/adapter/itemRule/type.js +19 -1
  9. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  10. package/dist/modules/BookingContext/index.d.ts +3 -0
  11. package/dist/modules/BookingContext/index.js +42 -13
  12. package/dist/modules/BookingContext/types.d.ts +4 -4
  13. package/dist/modules/BookingContext/types.js +3 -3
  14. package/dist/modules/OpenData/types.d.ts +1 -0
  15. package/dist/modules/Order/index.d.ts +18 -3
  16. package/dist/modules/Order/index.js +885 -485
  17. package/dist/modules/Order/salesNotes.d.ts +31 -0
  18. package/dist/modules/Order/salesNotes.js +492 -0
  19. package/dist/modules/Order/types.d.ts +93 -5
  20. package/dist/modules/Order/types.js +5 -0
  21. package/dist/modules/Order/utils.d.ts +12 -0
  22. package/dist/modules/Order/utils.js +96 -31
  23. package/dist/modules/Product/types.d.ts +2 -0
  24. package/dist/modules/ProductList/clientDataVariants.d.ts +50 -0
  25. package/dist/modules/ProductList/clientDataVariants.js +216 -0
  26. package/dist/modules/ProductList/index.d.ts +18 -3
  27. package/dist/modules/ProductList/index.js +220 -38
  28. package/dist/modules/ProductList/types.d.ts +10 -0
  29. package/dist/modules/Quotation/index.d.ts +22 -0
  30. package/dist/modules/Quotation/index.js +293 -28
  31. package/dist/modules/ResourcePlanner/index.d.ts +0 -22
  32. package/dist/modules/ResourcePlanner/index.js +1 -180
  33. package/dist/modules/ResourcePlanner/localClock.d.ts +33 -0
  34. package/dist/modules/ResourcePlanner/localClock.js +183 -0
  35. package/dist/modules/ResourcePlanner/planner.d.ts +5 -14
  36. package/dist/modules/ResourcePlanner/planner.js +2111 -958
  37. package/dist/modules/ResourcePlanner/types.d.ts +359 -187
  38. package/dist/modules/ResourcePlanner/types.js +33 -1
  39. package/dist/plugins/request.d.ts +1 -0
  40. package/dist/server/index.d.ts +17 -2
  41. package/dist/server/index.js +1134 -932
  42. package/dist/server/modules/floor-plan/index.d.ts +4 -0
  43. package/dist/server/modules/floor-plan/index.js +240 -98
  44. package/dist/server/modules/menu/index.js +48 -23
  45. package/dist/server/modules/order/index.d.ts +17 -7
  46. package/dist/server/modules/order/index.js +419 -207
  47. package/dist/server/modules/products/index.d.ts +10 -4
  48. package/dist/server/modules/products/index.js +177 -84
  49. package/dist/server/modules/resource/index.js +21 -13
  50. package/dist/server/utils/product.d.ts +1 -1
  51. package/dist/server/utils/product.js +186 -22
  52. package/dist/server/utils/small-ticket.d.ts +9 -1
  53. package/dist/server/utils/small-ticket.js +131 -84
  54. package/dist/solution/BaseSales/index.d.ts +26 -3
  55. package/dist/solution/BaseSales/index.js +1384 -905
  56. package/dist/solution/BaseSales/types.d.ts +2 -0
  57. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +3 -0
  58. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +10 -3
  59. package/dist/solution/BaseSales/utils.js +6 -3
  60. package/dist/solution/BookingByStep/index.d.ts +4 -4
  61. package/dist/solution/BookingTicket/index.d.ts +1 -1
  62. package/dist/solution/BookingTicket/index.js +4 -2
  63. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  64. package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -3
  65. package/dist/solution/BookingTicket/utils/orderCustomer.js +3 -2
  66. package/dist/solution/RegisterAndLogin/config.d.ts +9 -3
  67. package/dist/solution/RegisterAndLogin/config.js +95 -40
  68. package/dist/solution/RegisterAndLogin/index.js +4 -1
  69. package/dist/solution/ScanOrder/index.d.ts +1 -0
  70. package/dist/solution/ScanOrder/index.js +31 -27
  71. package/dist/solution/ScanOrder/types.d.ts +2 -0
  72. package/dist/solution/ScanOrder/utils.d.ts +1 -0
  73. package/dist/solution/ScanOrder/utils.js +8 -3
  74. package/dist/solution/UnifiedBookingSales/index.d.ts +128 -74
  75. package/dist/solution/UnifiedBookingSales/index.js +3877 -963
  76. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +49 -0
  77. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.js +430 -0
  78. package/dist/solution/UnifiedBookingSales/types.d.ts +161 -77
  79. package/dist/solution/UnifiedBookingSales/types.js +4 -9
  80. package/dist/solution/VenueBooking/index.d.ts +3 -0
  81. package/dist/solution/VenueBooking/index.js +549 -497
  82. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  83. package/dist/solution/VenueBooking/utils/dateSummary.js +3 -1
  84. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +2 -0
  85. package/dist/solution/VenueBooking/utils/slotMerge.js +3 -1
  86. package/dist/utils/platform.d.ts +8 -0
  87. package/dist/utils/platform.js +15 -0
  88. package/lib/core/index.d.ts +7 -0
  89. package/lib/core/index.js +20 -2
  90. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  91. package/lib/model/strategy/adapter/itemRule/adapter.js +73 -4
  92. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  93. package/lib/model/strategy/adapter/itemRule/evaluator.js +23 -1
  94. package/lib/model/strategy/adapter/itemRule/type.d.ts +44 -0
  95. package/lib/model/strategy/adapter/itemRule/type.js +19 -1
  96. package/lib/modules/BookingContext/index.d.ts +3 -0
  97. package/lib/modules/BookingContext/index.js +35 -8
  98. package/lib/modules/BookingContext/types.d.ts +4 -4
  99. package/lib/modules/BookingContext/types.js +3 -3
  100. package/lib/modules/OpenData/types.d.ts +1 -0
  101. package/lib/modules/Order/index.d.ts +18 -3
  102. package/lib/modules/Order/index.js +325 -28
  103. package/lib/modules/Order/salesNotes.d.ts +31 -0
  104. package/lib/modules/Order/salesNotes.js +382 -0
  105. package/lib/modules/Order/types.d.ts +93 -5
  106. package/lib/modules/Order/types.js +4 -0
  107. package/lib/modules/Order/utils.d.ts +12 -0
  108. package/lib/modules/Order/utils.js +85 -16
  109. package/lib/modules/Product/types.d.ts +2 -0
  110. package/lib/modules/ProductList/clientDataVariants.d.ts +50 -0
  111. package/lib/modules/ProductList/clientDataVariants.js +204 -0
  112. package/lib/modules/ProductList/index.d.ts +18 -3
  113. package/lib/modules/ProductList/index.js +137 -8
  114. package/lib/modules/ProductList/types.d.ts +10 -0
  115. package/lib/modules/Quotation/index.d.ts +22 -0
  116. package/lib/modules/Quotation/index.js +158 -11
  117. package/lib/modules/ResourcePlanner/index.d.ts +0 -22
  118. package/lib/modules/ResourcePlanner/index.js +9 -129
  119. package/lib/modules/ResourcePlanner/localClock.d.ts +33 -0
  120. package/lib/modules/ResourcePlanner/localClock.js +205 -0
  121. package/lib/modules/ResourcePlanner/planner.d.ts +5 -14
  122. package/lib/modules/ResourcePlanner/planner.js +1807 -783
  123. package/lib/modules/ResourcePlanner/types.d.ts +359 -187
  124. package/lib/modules/ResourcePlanner/types.js +13 -1
  125. package/lib/plugins/request.d.ts +1 -0
  126. package/lib/server/index.d.ts +17 -2
  127. package/lib/server/index.js +149 -21
  128. package/lib/server/modules/floor-plan/index.d.ts +4 -0
  129. package/lib/server/modules/floor-plan/index.js +60 -7
  130. package/lib/server/modules/menu/index.js +26 -4
  131. package/lib/server/modules/order/index.d.ts +17 -7
  132. package/lib/server/modules/order/index.js +194 -57
  133. package/lib/server/modules/products/index.d.ts +10 -4
  134. package/lib/server/modules/products/index.js +93 -23
  135. package/lib/server/modules/resource/index.js +12 -2
  136. package/lib/server/utils/product.d.ts +1 -1
  137. package/lib/server/utils/product.js +163 -3
  138. package/lib/server/utils/small-ticket.d.ts +9 -1
  139. package/lib/server/utils/small-ticket.js +123 -79
  140. package/lib/solution/BaseSales/index.d.ts +26 -3
  141. package/lib/solution/BaseSales/index.js +396 -70
  142. package/lib/solution/BaseSales/types.d.ts +2 -0
  143. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +3 -0
  144. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +9 -2
  145. package/lib/solution/BaseSales/utils.js +3 -0
  146. package/lib/solution/BookingByStep/index.d.ts +4 -4
  147. package/lib/solution/BookingTicket/index.d.ts +1 -1
  148. package/lib/solution/BookingTicket/index.js +2 -1
  149. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  150. package/lib/solution/BookingTicket/utils/addProductDecision.js +5 -2
  151. package/lib/solution/BookingTicket/utils/orderCustomer.js +2 -1
  152. package/lib/solution/RegisterAndLogin/config.d.ts +9 -3
  153. package/lib/solution/RegisterAndLogin/config.js +49 -8
  154. package/lib/solution/RegisterAndLogin/index.js +4 -1
  155. package/lib/solution/ScanOrder/index.d.ts +1 -0
  156. package/lib/solution/ScanOrder/index.js +5 -1
  157. package/lib/solution/ScanOrder/types.d.ts +2 -0
  158. package/lib/solution/ScanOrder/utils.d.ts +1 -0
  159. package/lib/solution/ScanOrder/utils.js +4 -0
  160. package/lib/solution/UnifiedBookingSales/index.d.ts +128 -74
  161. package/lib/solution/UnifiedBookingSales/index.js +2592 -424
  162. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +49 -0
  163. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +316 -0
  164. package/lib/solution/UnifiedBookingSales/types.d.ts +161 -77
  165. package/lib/solution/UnifiedBookingSales/types.js +4 -6
  166. package/lib/solution/VenueBooking/index.d.ts +3 -0
  167. package/lib/solution/VenueBooking/index.js +33 -9
  168. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  169. package/lib/solution/VenueBooking/utils/dateSummary.js +3 -1
  170. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +2 -0
  171. package/lib/solution/VenueBooking/utils/slotMerge.js +3 -1
  172. package/lib/utils/platform.d.ts +8 -0
  173. package/lib/utils/platform.js +22 -0
  174. package/package.json +1 -1
@@ -12,8 +12,15 @@ declare class PisellOSCore implements PisellCore {
12
12
  context: BusinessContext;
13
13
  server: any;
14
14
  serverOptions?: ServerOptions;
15
+ private serverModulePromise?;
15
16
  constructor(options?: PisellOSOptions);
16
17
  private initialize;
18
+ /**
19
+ * 仅预加载 Server 模块代码,不创建实例、不注册模块、不请求业务数据。
20
+ * 导入失败会清空 Promise,正式 initializeServer 时仍可重新尝试。
21
+ */
22
+ preloadServerModule(): Promise<void>;
23
+ private loadServerModule;
17
24
  /**
18
25
  * 初始化 Server(公开方法,需要外部显式调用并等待)
19
26
  * Server 配置从构造函数传入的 options.server 中获取
@@ -24,8 +24,6 @@ import { EffectsManager } from "../effects";
24
24
  * pisell OS 核心实现
25
25
  */
26
26
  var PisellOSCore = /*#__PURE__*/function () {
27
- // 保存 Server 配置
28
-
29
27
  function PisellOSCore(options) {
30
28
  _classCallCheck(this, PisellOSCore);
31
29
  _defineProperty(this, "plugins", new Map());
@@ -37,6 +35,8 @@ var PisellOSCore = /*#__PURE__*/function () {
37
35
  _defineProperty(this, "server", void 0);
38
36
  // Server 实例
39
37
  _defineProperty(this, "serverOptions", void 0);
38
+ // 保存 Server 配置
39
+ _defineProperty(this, "serverModulePromise", void 0);
40
40
  this.debug = (options === null || options === void 0 ? void 0 : options.debug) || false;
41
41
  this.context = (options === null || options === void 0 ? void 0 : options.context) || {};
42
42
 
@@ -63,6 +63,49 @@ var PisellOSCore = /*#__PURE__*/function () {
63
63
  this.log('[PisellOS] 核心初始化完成');
64
64
  }
65
65
 
66
+ /**
67
+ * 仅预加载 Server 模块代码,不创建实例、不注册模块、不请求业务数据。
68
+ * 导入失败会清空 Promise,正式 initializeServer 时仍可重新尝试。
69
+ */
70
+ }, {
71
+ key: "preloadServerModule",
72
+ value: (function () {
73
+ var _preloadServerModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
74
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
75
+ while (1) switch (_context.prev = _context.next) {
76
+ case 0:
77
+ if (!(this.server || !this.serverOptions)) {
78
+ _context.next = 2;
79
+ break;
80
+ }
81
+ return _context.abrupt("return");
82
+ case 2:
83
+ _context.next = 4;
84
+ return this.loadServerModule();
85
+ case 4:
86
+ case "end":
87
+ return _context.stop();
88
+ }
89
+ }, _callee, this);
90
+ }));
91
+ function preloadServerModule() {
92
+ return _preloadServerModule.apply(this, arguments);
93
+ }
94
+ return preloadServerModule;
95
+ }())
96
+ }, {
97
+ key: "loadServerModule",
98
+ value: function loadServerModule() {
99
+ var _this2 = this;
100
+ if (!this.serverModulePromise) {
101
+ this.serverModulePromise = import("../server").catch(function (error) {
102
+ _this2.serverModulePromise = undefined;
103
+ throw error;
104
+ });
105
+ }
106
+ return this.serverModulePromise;
107
+ }
108
+
66
109
  /**
67
110
  * 初始化 Server(公开方法,需要外部显式调用并等待)
68
111
  * Server 配置从构造函数传入的 options.server 中获取
@@ -70,56 +113,56 @@ var PisellOSCore = /*#__PURE__*/function () {
70
113
  }, {
71
114
  key: "initializeServer",
72
115
  value: (function () {
73
- var _initializeServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
116
+ var _initializeServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
74
117
  var ServerModule, Server;
75
- return _regeneratorRuntime().wrap(function _callee$(_context) {
76
- while (1) switch (_context.prev = _context.next) {
118
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
119
+ while (1) switch (_context2.prev = _context2.next) {
77
120
  case 0:
78
121
  if (!this.server) {
79
- _context.next = 3;
122
+ _context2.next = 3;
80
123
  break;
81
124
  }
82
125
  this.log('Server 已经初始化,跳过重复初始化', 'warn');
83
- return _context.abrupt("return");
126
+ return _context2.abrupt("return");
84
127
  case 3:
85
128
  if (this.serverOptions) {
86
- _context.next = 6;
129
+ _context2.next = 6;
87
130
  break;
88
131
  }
89
132
  this.log('未提供 Server 配置,无法初始化', 'warn');
90
- return _context.abrupt("return");
133
+ return _context2.abrupt("return");
91
134
  case 6:
92
- _context.prev = 6;
93
- _context.next = 9;
94
- return import("../server");
135
+ _context2.prev = 6;
136
+ _context2.next = 9;
137
+ return this.loadServerModule();
95
138
  case 9:
96
- ServerModule = _context.sent;
139
+ ServerModule = _context2.sent;
97
140
  Server = ServerModule.default; // 创建 Server 实例
98
141
  this.server = new Server(this);
99
142
  this.log('Server 实例已创建');
100
143
 
101
144
  // 初始化模块并预加载数据
102
145
  if (!this.serverOptions.modules) {
103
- _context.next = 16;
146
+ _context2.next = 16;
104
147
  break;
105
148
  }
106
- _context.next = 16;
149
+ _context2.next = 16;
107
150
  return this.server.initialize(this.serverOptions.modules, this.serverOptions.autoInitData !== false, options);
108
151
  case 16:
109
152
  this.log('[PisellOS] Server 初始化完成');
110
- _context.next = 24;
153
+ _context2.next = 24;
111
154
  break;
112
155
  case 19:
113
- _context.prev = 19;
114
- _context.t0 = _context["catch"](6);
115
- console.error('[PisellOS] ❌ Server 初始化失败:', _context.t0);
116
- this.log("Server \u521D\u59CB\u5316\u5931\u8D25: ".concat(_context.t0), 'error');
117
- throw _context.t0;
156
+ _context2.prev = 19;
157
+ _context2.t0 = _context2["catch"](6);
158
+ console.error('[PisellOS] ❌ Server 初始化失败:', _context2.t0);
159
+ this.log("Server \u521D\u59CB\u5316\u5931\u8D25: ".concat(_context2.t0), 'error');
160
+ throw _context2.t0;
118
161
  case 24:
119
162
  case "end":
120
- return _context.stop();
163
+ return _context2.stop();
121
164
  }
122
- }, _callee, this, [[6, 19]]);
165
+ }, _callee2, this, [[6, 19]]);
123
166
  }));
124
167
  function initializeServer(_x) {
125
168
  return _initializeServer.apply(this, arguments);
@@ -151,7 +194,7 @@ var PisellOSCore = /*#__PURE__*/function () {
151
194
  }, {
152
195
  key: "registerPlugin",
153
196
  value: function registerPlugin(plugin, options) {
154
- var _this2 = this;
197
+ var _this3 = this;
155
198
  if (this.plugins.has(plugin.name)) {
156
199
  this.log("\u63D2\u4EF6 ".concat(plugin.name, " \u5DF2\u7ECF\u6CE8\u518C\u8FC7\uFF0C\u5C06\u88AB\u8986\u76D6"), 'warn');
157
200
  }
@@ -179,7 +222,7 @@ var PisellOSCore = /*#__PURE__*/function () {
179
222
  var result = plugin.initialize();
180
223
  if (result instanceof Promise) {
181
224
  result.catch(function (err) {
182
- _this2.log("\u63D2\u4EF6 ".concat(plugin.name, " \u521D\u59CB\u5316\u5931\u8D25: ").concat(err.message), 'error');
225
+ _this3.log("\u63D2\u4EF6 ".concat(plugin.name, " \u521D\u59CB\u5316\u5931\u8D25: ").concat(err.message), 'error');
183
226
  throw err;
184
227
  });
185
228
  }
@@ -205,7 +248,7 @@ var PisellOSCore = /*#__PURE__*/function () {
205
248
  }, {
206
249
  key: "registerModule",
207
250
  value: function registerModule(module, options) {
208
- var _this3 = this;
251
+ var _this4 = this;
209
252
  if (this.modules.has(module.name)) {
210
253
  this.log("\u6A21\u5757 ".concat(module.name, " \u5DF2\u7ECF\u6CE8\u518C\u8FC7\uFF0C\u5C06\u88AB\u8986\u76D6"), 'warn');
211
254
  }
@@ -247,7 +290,7 @@ var PisellOSCore = /*#__PURE__*/function () {
247
290
  }
248
291
  // 预先给模块初始化值系统
249
292
  var _createStore = createStore((options === null || options === void 0 ? void 0 : options.initialState) || {}, module.name, function (path, value) {
250
- _this3.effects.emit("".concat(module.name, ":changed"), {
293
+ _this4.effects.emit("".concat(module.name, ":changed"), {
251
294
  path: path,
252
295
  value: value
253
296
  });
@@ -262,7 +305,7 @@ var PisellOSCore = /*#__PURE__*/function () {
262
305
  }, options));
263
306
  if (result instanceof Promise) {
264
307
  result.catch(function (err) {
265
- _this3.log("\u6A21\u5757 ".concat(module.name, " \u521D\u59CB\u5316\u5931\u8D25: ").concat(err.message), 'error');
308
+ _this4.log("\u6A21\u5757 ".concat(module.name, " \u521D\u59CB\u5316\u5931\u8D25: ").concat(err.message), 'error');
266
309
  throw err;
267
310
  });
268
311
  }
@@ -307,100 +350,100 @@ var PisellOSCore = /*#__PURE__*/function () {
307
350
  }, {
308
351
  key: "destroy",
309
352
  value: function () {
310
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
353
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
311
354
  var _iterator4, _step4, _step4$value, name, module, _iterator5, _step5, _step5$value, _name, plugin;
312
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
313
- while (1) switch (_context2.prev = _context2.next) {
355
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
356
+ while (1) switch (_context3.prev = _context3.next) {
314
357
  case 0:
315
358
  // 先销毁模块
316
359
  _iterator4 = _createForOfIteratorHelper(this.modules.entries());
317
- _context2.prev = 1;
360
+ _context3.prev = 1;
318
361
  _iterator4.s();
319
362
  case 3:
320
363
  if ((_step4 = _iterator4.n()).done) {
321
- _context2.next = 17;
364
+ _context3.next = 17;
322
365
  break;
323
366
  }
324
367
  _step4$value = _slicedToArray(_step4.value, 2), name = _step4$value[0], module = _step4$value[1];
325
368
  if (!module.destroy) {
326
- _context2.next = 15;
369
+ _context3.next = 15;
327
370
  break;
328
371
  }
329
- _context2.prev = 6;
330
- _context2.next = 9;
372
+ _context3.prev = 6;
373
+ _context3.next = 9;
331
374
  return Promise.resolve(module.destroy());
332
375
  case 9:
333
376
  this.log("\u6A21\u5757 ".concat(name, " \u5DF2\u9500\u6BC1"));
334
- _context2.next = 15;
377
+ _context3.next = 15;
335
378
  break;
336
379
  case 12:
337
- _context2.prev = 12;
338
- _context2.t0 = _context2["catch"](6);
339
- this.log("\u9500\u6BC1\u6A21\u5757 ".concat(name, " \u65F6\u51FA\u9519: ").concat(_context2.t0), 'error');
380
+ _context3.prev = 12;
381
+ _context3.t0 = _context3["catch"](6);
382
+ this.log("\u9500\u6BC1\u6A21\u5757 ".concat(name, " \u65F6\u51FA\u9519: ").concat(_context3.t0), 'error');
340
383
  case 15:
341
- _context2.next = 3;
384
+ _context3.next = 3;
342
385
  break;
343
386
  case 17:
344
- _context2.next = 22;
387
+ _context3.next = 22;
345
388
  break;
346
389
  case 19:
347
- _context2.prev = 19;
348
- _context2.t1 = _context2["catch"](1);
349
- _iterator4.e(_context2.t1);
390
+ _context3.prev = 19;
391
+ _context3.t1 = _context3["catch"](1);
392
+ _iterator4.e(_context3.t1);
350
393
  case 22:
351
- _context2.prev = 22;
394
+ _context3.prev = 22;
352
395
  _iterator4.f();
353
- return _context2.finish(22);
396
+ return _context3.finish(22);
354
397
  case 25:
355
398
  this.modules.clear();
356
399
 
357
400
  // 再销毁插件
358
401
  _iterator5 = _createForOfIteratorHelper(this.plugins.entries());
359
- _context2.prev = 27;
402
+ _context3.prev = 27;
360
403
  _iterator5.s();
361
404
  case 29:
362
405
  if ((_step5 = _iterator5.n()).done) {
363
- _context2.next = 43;
406
+ _context3.next = 43;
364
407
  break;
365
408
  }
366
409
  _step5$value = _slicedToArray(_step5.value, 2), _name = _step5$value[0], plugin = _step5$value[1];
367
410
  if (!plugin.destroy) {
368
- _context2.next = 41;
411
+ _context3.next = 41;
369
412
  break;
370
413
  }
371
- _context2.prev = 32;
372
- _context2.next = 35;
414
+ _context3.prev = 32;
415
+ _context3.next = 35;
373
416
  return Promise.resolve(plugin.destroy());
374
417
  case 35:
375
418
  this.log("\u63D2\u4EF6 ".concat(_name, " \u5DF2\u9500\u6BC1"));
376
- _context2.next = 41;
419
+ _context3.next = 41;
377
420
  break;
378
421
  case 38:
379
- _context2.prev = 38;
380
- _context2.t2 = _context2["catch"](32);
381
- this.log("\u9500\u6BC1\u63D2\u4EF6 ".concat(_name, " \u65F6\u51FA\u9519: ").concat(_context2.t2), 'error');
422
+ _context3.prev = 38;
423
+ _context3.t2 = _context3["catch"](32);
424
+ this.log("\u9500\u6BC1\u63D2\u4EF6 ".concat(_name, " \u65F6\u51FA\u9519: ").concat(_context3.t2), 'error');
382
425
  case 41:
383
- _context2.next = 29;
426
+ _context3.next = 29;
384
427
  break;
385
428
  case 43:
386
- _context2.next = 48;
429
+ _context3.next = 48;
387
430
  break;
388
431
  case 45:
389
- _context2.prev = 45;
390
- _context2.t3 = _context2["catch"](27);
391
- _iterator5.e(_context2.t3);
432
+ _context3.prev = 45;
433
+ _context3.t3 = _context3["catch"](27);
434
+ _iterator5.e(_context3.t3);
392
435
  case 48:
393
- _context2.prev = 48;
436
+ _context3.prev = 48;
394
437
  _iterator5.f();
395
- return _context2.finish(48);
438
+ return _context3.finish(48);
396
439
  case 51:
397
440
  this.plugins.clear();
398
441
  this.log('PisellOS 核心已销毁');
399
442
  case 53:
400
443
  case "end":
401
- return _context2.stop();
444
+ return _context3.stop();
402
445
  }
403
- }, _callee2, this, [[1, 19, 22, 25], [6, 12], [27, 45, 48, 51], [32, 38]]);
446
+ }, _callee3, this, [[1, 19, 22, 25], [6, 12], [27, 45, 48, 51], [32, 38]]);
404
447
  }));
405
448
  function destroy() {
406
449
  return _destroy.apply(this, arguments);
@@ -1,6 +1,6 @@
1
1
  import type { EvaluationResult, RuntimeContext, ActionEffect } from '../../type';
2
2
  import type { BusinessAdapter } from '../type';
3
- import { type ItemRuleBusinessData, type QuantityCheckResult, type PrefillItemResult, type QuantityLimitResult } from './type';
3
+ import { type ItemRuleBusinessData, type QuantityCheckResult, type PrefillItemResult, type QuantityLimitResult, type AllergyRequirement } from './type';
4
4
  /**
5
5
  * ItemRule 适配器
6
6
  *
@@ -14,7 +14,10 @@ export declare class ItemRuleAdapter implements BusinessAdapter {
14
14
  transformResult(result: EvaluationResult, businessData?: ItemRuleBusinessData): {
15
15
  quantityChecks: QuantityCheckResult[];
16
16
  prefillItems: PrefillItemResult[];
17
+ allergyRequirements: AllergyRequirement[];
17
18
  };
19
+ private processAllergyCheck;
20
+ private normalizeAllergyDataSourceItems;
18
21
  formatConfig(result: EvaluationResult, businessData?: ItemRuleBusinessData): {
19
22
  result: EvaluationResult;
20
23
  businessData?: ItemRuleBusinessData;
@@ -1,4 +1,8 @@
1
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
5
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
2
6
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
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."); }
4
8
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
@@ -31,18 +35,22 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
31
35
  _createClass(ItemRuleAdapter, [{
32
36
  key: "prepareContext",
33
37
  value: function prepareContext(businessData) {
38
+ var _ref;
34
39
  var pax = businessData.pax,
35
40
  cartItems = businessData.cartItems,
36
41
  serviceType = businessData.serviceType,
42
+ channel = businessData.channel,
37
43
  submissionIndex = businessData.submissionIndex,
38
44
  custom = businessData.custom;
45
+ var resolvedChannel = String((_ref = channel !== null && channel !== void 0 ? channel : custom === null || custom === void 0 ? void 0 : custom.channel) !== null && _ref !== void 0 ? _ref : '').trim();
39
46
  return {
40
47
  entities: {
41
48
  cartItems: cartItems,
42
49
  historicalItems: businessData.historicalItems || [],
43
- pax: pax
50
+ pax: pax,
51
+ currentProduct: businessData.currentProduct
44
52
  },
45
- attributes: _objectSpread({
53
+ attributes: _objectSpread(_objectSpread({
46
54
  serviceType: serviceType || '',
47
55
  totalPax: pax.total,
48
56
  adultPax: pax.adult,
@@ -52,7 +60,9 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
52
60
  cartTotalQuantity: cartItems.reduce(function (sum, item) {
53
61
  return sum + item.quantity;
54
62
  }, 0)
55
- }, custom),
63
+ }, custom), {}, {
64
+ channel: resolvedChannel
65
+ }),
56
66
  metadata: {
57
67
  timestamp: Date.now()
58
68
  }
@@ -63,10 +73,12 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
63
73
  value: function transformResult(result, businessData) {
64
74
  var quantityChecks = [];
65
75
  var prefillItems = [];
76
+ var allergyRequirements = [];
66
77
  if (!result.applicable || !businessData) {
67
78
  return {
68
79
  quantityChecks: quantityChecks,
69
- prefillItems: prefillItems
80
+ prefillItems: prefillItems,
81
+ allergyRequirements: allergyRequirements
70
82
  };
71
83
  }
72
84
  var _iterator = _createForOfIteratorHelper(result.matchedActions),
@@ -82,6 +94,9 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
82
94
  } else if (action.type === ITEM_RULE_ACTION_TYPES.PREFILL_CART) {
83
95
  var items = this.processPrefillCart(action, businessData);
84
96
  prefillItems.push.apply(prefillItems, _toConsumableArray(items));
97
+ } else if (action.type === ITEM_RULE_ACTION_TYPES.ALLERGY_CHECK) {
98
+ var requirement = this.processAllergyCheck(action, result, businessData);
99
+ if (requirement) allergyRequirements.push(requirement);
85
100
  }
86
101
  }
87
102
  } catch (err) {
@@ -91,9 +106,94 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
91
106
  }
92
107
  return {
93
108
  quantityChecks: quantityChecks,
94
- prefillItems: prefillItems
109
+ prefillItems: prefillItems,
110
+ allergyRequirements: allergyRequirements
95
111
  };
96
112
  }
113
+
114
+ // ============================================
115
+ // Allergy Check 处理
116
+ // ============================================
117
+ }, {
118
+ key: "processAllergyCheck",
119
+ value: function processAllergyCheck(action, result, businessData) {
120
+ var _currentProduct$produ, _productTargets$find, _target$dataSource, _action$priority, _target$product_varia;
121
+ var config = action.config;
122
+ var currentProduct = businessData.currentProduct;
123
+ if (!config || config.targetType !== 'product' || config.promptScope !== 'once_per_order_product' || !Array.isArray(config.targets) || !currentProduct) {
124
+ return null;
125
+ }
126
+ var currentProductId = Number(currentProduct.product_id);
127
+ var currentVariantId = Number((_currentProduct$produ = currentProduct.product_variant_id) !== null && _currentProduct$produ !== void 0 ? _currentProduct$produ : 0);
128
+ if (!Number.isFinite(currentProductId) || currentProductId <= 0) return null;
129
+ var productTargets = config.targets.filter(function (item) {
130
+ return Number(item.product_id) === currentProductId;
131
+ });
132
+ var target = (_productTargets$find = productTargets.find(function (item) {
133
+ var _item$product_variant;
134
+ return currentVariantId > 0 && Number((_item$product_variant = item.product_variant_id) !== null && _item$product_variant !== void 0 ? _item$product_variant : 0) === currentVariantId;
135
+ })) !== null && _productTargets$find !== void 0 ? _productTargets$find : productTargets.find(function (item) {
136
+ var _item$product_variant2;
137
+ return Number((_item$product_variant2 = item.product_variant_id) !== null && _item$product_variant2 !== void 0 ? _item$product_variant2 : 0) <= 0;
138
+ });
139
+ if (!target || ((_target$dataSource = target.dataSource) === null || _target$dataSource === void 0 ? void 0 : _target$dataSource.type) !== 'inline') return null;
140
+ var items = this.normalizeAllergyDataSourceItems(target.dataSource.items);
141
+ if (!items.length) return null;
142
+ return _objectSpread(_objectSpread({
143
+ strategyId: result.config.metadata.id,
144
+ ruleId: action.id,
145
+ priority: (_action$priority = action.priority) !== null && _action$priority !== void 0 ? _action$priority : 0,
146
+ targetType: 'product',
147
+ product_id: currentProductId
148
+ }, Number((_target$product_varia = target.product_variant_id) !== null && _target$product_varia !== void 0 ? _target$product_varia : 0) > 0 ? {
149
+ product_variant_id: Number(target.product_variant_id)
150
+ } : {}), {}, {
151
+ dataSource: {
152
+ type: 'inline',
153
+ items: items
154
+ },
155
+ promptScope: config.promptScope,
156
+ allowNote: config.allowNote === true
157
+ });
158
+ }
159
+ }, {
160
+ key: "normalizeAllergyDataSourceItems",
161
+ value: function normalizeAllergyDataSourceItems(items) {
162
+ if (!Array.isArray(items)) return [];
163
+ var uniqueIds = new Set();
164
+ var normalized = [];
165
+ var _iterator2 = _createForOfIteratorHelper(items),
166
+ _step2;
167
+ try {
168
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
169
+ var _item$id;
170
+ var item = _step2.value;
171
+ var id = String((_item$id = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id !== void 0 ? _item$id : '').trim();
172
+ var rawLabel = item === null || item === void 0 ? void 0 : item.label;
173
+ var label = typeof rawLabel === 'string' ? rawLabel.trim() : Object.entries(rawLabel || {}).reduce(function (labels, _ref2) {
174
+ var _ref3 = _slicedToArray(_ref2, 2),
175
+ locale = _ref3[0],
176
+ value = _ref3[1];
177
+ if (typeof value === 'string' && value.trim().length > 0) {
178
+ labels[locale] = value.trim();
179
+ }
180
+ return labels;
181
+ }, {});
182
+ var hasLabel = typeof label === 'string' ? label.length > 0 : Object.keys(label).length > 0;
183
+ if (!id || !hasLabel || uniqueIds.has(id)) continue;
184
+ uniqueIds.add(id);
185
+ normalized.push({
186
+ id: id,
187
+ label: label
188
+ });
189
+ }
190
+ } catch (err) {
191
+ _iterator2.e(err);
192
+ } finally {
193
+ _iterator2.f();
194
+ }
195
+ return normalized;
196
+ }
97
197
  }, {
98
198
  key: "formatConfig",
99
199
  value: function formatConfig(result, businessData) {
@@ -178,19 +278,19 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
178
278
  }));
179
279
  var quantity = 0;
180
280
  var countFromItems = function countFromItems(items) {
181
- var _iterator2 = _createForOfIteratorHelper(items),
182
- _step2;
281
+ var _iterator3 = _createForOfIteratorHelper(items),
282
+ _step3;
183
283
  try {
184
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
185
- var item = _step2.value;
284
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
285
+ var item = _step3.value;
186
286
  if (targetIds.has(item.product_id)) {
187
287
  quantity += item.quantity;
188
288
  }
189
289
  }
190
290
  } catch (err) {
191
- _iterator2.e(err);
291
+ _iterator3.e(err);
192
292
  } finally {
193
- _iterator2.f();
293
+ _iterator3.f();
194
294
  }
195
295
  };
196
296
  if (scope === 'cumulative') {
@@ -214,11 +314,11 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
214
314
  var requiredMax;
215
315
  var requiredExact;
216
316
  var mustInclude;
217
- var _iterator3 = _createForOfIteratorHelper(rules),
218
- _step3;
317
+ var _iterator4 = _createForOfIteratorHelper(rules),
318
+ _step4;
219
319
  try {
220
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
221
- var rule = _step3.value;
320
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
321
+ var rule = _step4.value;
222
322
  var resolvedValue = this.resolveQuantityValue(rule, businessData);
223
323
  switch (rule.comparison) {
224
324
  case 'minimum':
@@ -260,9 +360,9 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
260
360
  }
261
361
  }
262
362
  } catch (err) {
263
- _iterator3.e(err);
363
+ _iterator4.e(err);
264
364
  } finally {
265
- _iterator3.f();
365
+ _iterator4.f();
266
366
  }
267
367
  return {
268
368
  passed: failedRules.length === 0,
@@ -336,11 +436,11 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
336
436
  var requiredMax;
337
437
  var requiredExact;
338
438
  var mustInclude;
339
- var _iterator4 = _createForOfIteratorHelper(quantityRules),
340
- _step4;
439
+ var _iterator5 = _createForOfIteratorHelper(quantityRules),
440
+ _step5;
341
441
  try {
342
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
343
- var rule = _step4.value;
442
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
443
+ var rule = _step5.value;
344
444
  var resolvedValue = this.resolveQuantityValue(rule, businessData);
345
445
  switch (rule.comparison) {
346
446
  case 'minimum':
@@ -370,9 +470,9 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
370
470
  }
371
471
  }
372
472
  } catch (err) {
373
- _iterator4.e(err);
473
+ _iterator5.e(err);
374
474
  } finally {
375
- _iterator4.f();
475
+ _iterator5.f();
376
476
  }
377
477
  var remainingMax = this.calculateRemainingMax(scope, requiredMax, targets, businessData);
378
478
  var formattedValidationMessage = this.formatValidationMessage(validationMessage, requiredMin, requiredMax, requiredExact);
@@ -412,19 +512,19 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
412
512
  return t.product_id;
413
513
  }));
414
514
  var historicalQty = 0;
415
- var _iterator5 = _createForOfIteratorHelper(historicalItems),
416
- _step5;
515
+ var _iterator6 = _createForOfIteratorHelper(historicalItems),
516
+ _step6;
417
517
  try {
418
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
419
- var item = _step5.value;
518
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
519
+ var item = _step6.value;
420
520
  if (targetIds.has(item.product_id)) {
421
521
  historicalQty += item.quantity;
422
522
  }
423
523
  }
424
524
  } catch (err) {
425
- _iterator5.e(err);
525
+ _iterator6.e(err);
426
526
  } finally {
427
- _iterator5.f();
527
+ _iterator6.f();
428
528
  }
429
529
  return Math.max(0, requiredMax - historicalQty);
430
530
  }
@@ -438,11 +538,11 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
438
538
  var config = action.config;
439
539
  if (!(config !== null && config !== void 0 && config.products)) return [];
440
540
  var results = [];
441
- var _iterator6 = _createForOfIteratorHelper(config.products),
442
- _step6;
541
+ var _iterator7 = _createForOfIteratorHelper(config.products),
542
+ _step7;
443
543
  try {
444
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
445
- var prefillProduct = _step6.value;
544
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
545
+ var prefillProduct = _step7.value;
446
546
  var quantity = this.resolvePrefillQuantity(prefillProduct.quantityFrom, prefillProduct.quantity, businessData);
447
547
  if (quantity <= 0) continue;
448
548
  results.push({
@@ -453,9 +553,9 @@ export var ItemRuleAdapter = /*#__PURE__*/function () {
453
553
  });
454
554
  }
455
555
  } catch (err) {
456
- _iterator6.e(err);
556
+ _iterator7.e(err);
457
557
  } finally {
458
- _iterator6.f();
558
+ _iterator7.f();
459
559
  }
460
560
  return results;
461
561
  }