@pisell/pisellos 0.10.79 → 0.10.80

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.
@@ -0,0 +1,9 @@
1
+ // 导出评估器
2
+ export { PromotionEvaluator } from "./evaluator";
3
+
4
+ // 导出适配器
5
+ export { PromotionAdapter } from "./adapter";
6
+ export { default } from "./adapter";
7
+
8
+ // 导出策略配置示例常量
9
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
@@ -7156,7 +7156,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7156
7156
  case 0:
7157
7157
  return _context44.abrupt("return", this.queueCartCommand(function () {
7158
7158
  return _this49.removeProductsFromOrderDraft(identities, options);
7159
- }, Boolean(options === null || options === void 0 ? void 0 : options.isCurrentOrder)));
7159
+ }, Boolean((options === null || options === void 0 ? void 0 : options.isCurrentOrder) || (options === null || options === void 0 ? void 0 : options.beforeApply))));
7160
7160
  case 1:
7161
7161
  case "end":
7162
7162
  return _context44.stop();
@@ -7172,8 +7172,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7172
7172
  key: "removeProductsFromOrderDraft",
7173
7173
  value: function () {
7174
7174
  var _removeProductsFromOrderDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(identities, options) {
7175
- var _this50 = this;
7176
- var _this$store$tempOrder10, mutation, tempOrder, identity, isCurrentOrder, beforeCommit, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator28, _step28, _loop5, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
7175
+ var _options$beforeApply3,
7176
+ _this50 = this;
7177
+ var _this$store$tempOrder10, _this$store$tempOrder11, guarded, mutation, tempOrder, identity, isCurrentOrder, beforeCommit, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator28, _step28, _loop5, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
7177
7178
  return _regeneratorRuntime().wrap(function _callee41$(_context46) {
7178
7179
  while (1) switch (_context46.prev = _context46.next) {
7179
7180
  case 0:
@@ -7183,8 +7184,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7183
7184
  }
7184
7185
  return _context46.abrupt("return", ((_this$store$tempOrder10 = this.store.tempOrder) === null || _this$store$tempOrder10 === void 0 ? void 0 : _this$store$tempOrder10.products) || []);
7185
7186
  case 2:
7187
+ // Validate inside the command queue, before creating or mutating the draft.
7188
+ if (identities.length) options === null || options === void 0 || (_options$beforeApply3 = options.beforeApply) === null || _options$beforeApply3 === void 0 || _options$beforeApply3.call(options);
7189
+ if (!(options !== null && options !== void 0 && options.isCurrentOrder && !options.isCurrentOrder())) {
7190
+ _context46.next = 5;
7191
+ break;
7192
+ }
7193
+ return _context46.abrupt("return", ((_this$store$tempOrder11 = this.store.tempOrder) === null || _this$store$tempOrder11 === void 0 ? void 0 : _this$store$tempOrder11.products) || []);
7194
+ case 5:
7195
+ guarded = Boolean((options === null || options === void 0 ? void 0 : options.isCurrentOrder) || (options === null || options === void 0 ? void 0 : options.beforeApply));
7186
7196
  mutation = this.beginCartMutation({
7187
- forceDraft: Boolean(options === null || options === void 0 ? void 0 : options.isCurrentOrder)
7197
+ forceDraft: guarded
7188
7198
  });
7189
7199
  tempOrder = mutation.draft;
7190
7200
  identity = [mutation.current.order_id, mutation.current.external_sale_number];
@@ -7192,17 +7202,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7192
7202
  var _options$isCurrentOrd3, _options$isCurrentOrd4;
7193
7203
  return _this50.store.tempOrder === mutation.current && mutation.current.order_id === identity[0] && mutation.current.external_sale_number === identity[1] && ((_options$isCurrentOrd3 = options === null || options === void 0 || (_options$isCurrentOrd4 = options.isCurrentOrder) === null || _options$isCurrentOrd4 === void 0 ? void 0 : _options$isCurrentOrd4.call(options)) !== null && _options$isCurrentOrd3 !== void 0 ? _options$isCurrentOrd3 : true);
7194
7204
  };
7195
- beforeCommit = options !== null && options !== void 0 && options.isCurrentOrder ? function () {
7205
+ beforeCommit = guarded ? function () {
7206
+ var _options$beforeApply4;
7207
+ // Inventory validation can await. Recheck the live source snapshot before
7208
+ // publication; never run this row-snapshot guard during finalization.
7209
+ options === null || options === void 0 || (_options$beforeApply4 = options.beforeApply) === null || _options$beforeApply4 === void 0 || _options$beforeApply4.call(options);
7196
7210
  if (!isCurrentOrder()) throw Object.assign(new Error('Order product removal interrupted by an order change'), {
7197
7211
  code: 'AVAILABILITY_SELECTION_STALE'
7198
7212
  });
7199
7213
  } : undefined;
7200
7214
  if (identities.length) {
7201
- _context46.next = 9;
7215
+ _context46.next = 13;
7202
7216
  break;
7203
7217
  }
7204
7218
  return _context46.abrupt("return", tempOrder.products);
7205
- case 9:
7219
+ case 13:
7206
7220
  // 商品删除会同步删除以商品行为主关系的 Notes;快照不完整时禁止产生孤儿 Relation。
7207
7221
  this.ensureSalesNotesLoadedForMutation(tempOrder);
7208
7222
  this.repairDuplicateProductLineIdentities(tempOrder);
@@ -7234,7 +7248,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7234
7248
  }
7235
7249
  linkedBookingUidsToRemove = new Set();
7236
7250
  _iterator28 = _createForOfIteratorHelper(matchedProducts);
7237
- _context46.prev = 22;
7251
+ _context46.prev = 26;
7238
7252
  _loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
7239
7253
  var _metadata11, _metadata12, _metadata13, _metadata14;
7240
7254
  var product, productUid, productBookingUid, isAddTimeProduct;
@@ -7269,33 +7283,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7269
7283
  }, _loop5);
7270
7284
  });
7271
7285
  _iterator28.s();
7272
- case 25:
7286
+ case 29:
7273
7287
  if ((_step28 = _iterator28.n()).done) {
7274
- _context46.next = 31;
7288
+ _context46.next = 35;
7275
7289
  break;
7276
7290
  }
7277
- return _context46.delegateYield(_loop5(), "t0", 27);
7278
- case 27:
7291
+ return _context46.delegateYield(_loop5(), "t0", 31);
7292
+ case 31:
7279
7293
  if (!_context46.t0) {
7280
- _context46.next = 29;
7294
+ _context46.next = 33;
7281
7295
  break;
7282
7296
  }
7283
- return _context46.abrupt("continue", 29);
7284
- case 29:
7285
- _context46.next = 25;
7297
+ return _context46.abrupt("continue", 33);
7298
+ case 33:
7299
+ _context46.next = 29;
7286
7300
  break;
7287
- case 31:
7288
- _context46.next = 36;
7301
+ case 35:
7302
+ _context46.next = 40;
7289
7303
  break;
7290
- case 33:
7291
- _context46.prev = 33;
7292
- _context46.t1 = _context46["catch"](22);
7304
+ case 37:
7305
+ _context46.prev = 37;
7306
+ _context46.t1 = _context46["catch"](26);
7293
7307
  _iterator28.e(_context46.t1);
7294
- case 36:
7295
- _context46.prev = 36;
7308
+ case 40:
7309
+ _context46.prev = 40;
7296
7310
  _iterator28.f();
7297
- return _context46.finish(36);
7298
- case 39:
7311
+ return _context46.finish(40);
7312
+ case 43:
7299
7313
  if (linkedBookingUidsToRemove.size > 0) {
7300
7314
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
7301
7315
  tempOrder.products = (tempOrder.products || []).filter(function (line) {
@@ -7326,28 +7340,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7326
7340
  }));
7327
7341
  this.removeSalesNotesForMissingProductLines(tempOrder);
7328
7342
  if (!mutation.commit) {
7329
- _context46.next = 47;
7343
+ _context46.next = 51;
7330
7344
  break;
7331
7345
  }
7332
- _context46.next = 46;
7346
+ _context46.next = 50;
7333
7347
  return mutation.commit(beforeCommit);
7334
- case 46:
7348
+ case 50:
7335
7349
  tempOrder = _context46.sent;
7336
- case 47:
7337
- _context46.next = 49;
7338
- return this.finalizeAfterProductsMutation(tempOrder, options !== null && options !== void 0 && options.isCurrentOrder ? {
7350
+ case 51:
7351
+ _context46.next = 53;
7352
+ return this.finalizeAfterProductsMutation(tempOrder, guarded ? {
7339
7353
  isCurrentOrder: isCurrentOrder
7340
7354
  } : undefined);
7341
- case 49:
7355
+ case 53:
7342
7356
  this.logInfo('removeProductsFromOrder success', {
7343
7357
  identities: identities
7344
7358
  });
7345
7359
  return _context46.abrupt("return", tempOrder.products);
7346
- case 51:
7360
+ case 55:
7347
7361
  case "end":
7348
7362
  return _context46.stop();
7349
7363
  }
7350
- }, _callee41, this, [[22, 33, 36, 39]]);
7364
+ }, _callee41, this, [[26, 37, 40, 43]]);
7351
7365
  }));
7352
7366
  function removeProductsFromOrderDraft(_x53, _x54) {
7353
7367
  return _removeProductsFromOrderDraft.apply(this, arguments);
@@ -9144,8 +9158,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
9144
9158
  }, {
9145
9159
  key: "getVouchers",
9146
9160
  value: function getVouchers() {
9147
- var _this$store$tempOrder11;
9148
- return ((_this$store$tempOrder11 = this.store.tempOrder) === null || _this$store$tempOrder11 === void 0 ? void 0 : _this$store$tempOrder11.vouchers) || [];
9161
+ var _this$store$tempOrder12;
9162
+ return ((_this$store$tempOrder12 = this.store.tempOrder) === null || _this$store$tempOrder12 === void 0 ? void 0 : _this$store$tempOrder12.vouchers) || [];
9149
9163
  }
9150
9164
  }], [{
9151
9165
  key: "populateSavedAmounts",
@@ -482,6 +482,8 @@ export interface ReplaceBookingProductWithRelatedRetailParams {
482
482
  * 预约合并行减量时仍删除最新真实行,再把剩余代表行移动到被删除代表行原位置。
483
483
  */
484
484
  export interface RemoveProductsFromOrderOptions {
485
+ /** Synchronous, read-only validation before draft mutation and again before publication after async guards; may throw. Never called during finalization. */
486
+ beforeApply?: () => void;
485
487
  /** Prevent an asynchronous deletion/finalization from crossing order or business scopes. */
486
488
  isCurrentOrder?: () => boolean;
487
489
  preserveDisplayPosition?: {
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  date: string;
327
327
  status: string;
328
328
  week: string;
329
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
329
+ weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
330
330
  }[]>;
331
331
  submitTimeSlot(timeSlots: TimeSliceItem): void;
332
332
  private getScheduleDataByIds;
@@ -373,7 +373,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
373
373
  };
374
374
  setOtherData(key: string, value: any): void;
375
375
  getOtherData(key: string): any;
376
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
376
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
377
377
  /**
378
378
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
379
379
  *
@@ -479,7 +479,19 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
479
479
  * 加车两阶段主决策(规格弹窗 / 资源编辑 / 直接加车)。
480
480
  * 与 ticketBooking `handleSelectProduct` + `handleBooking4Service` 等价。
481
481
  */
482
- decideAddProduct(item: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
482
+ decideAddProduct(item: any, options?: Partial<AddProductDecideContext>): {
483
+ action: "reloadCatalog";
484
+ } | {
485
+ action: "add";
486
+ cacheItem: any;
487
+ } | {
488
+ action: "requiresDetail";
489
+ payload: AddProductRequiresDetailPayload;
490
+ } | {
491
+ action: "requiresBookingEdit";
492
+ cacheItem: any;
493
+ payload: import("./utils/addProductDecision").AddProductRequiresBookingEditPayload;
494
+ };
483
495
  /** 规格弹窗 callback 后的第二段决策。 */
484
496
  decideAfterDetail(cacheItem: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
485
497
  /**
@@ -4790,19 +4790,28 @@ class OrderModule extends _BaseModule.BaseModule {
4790
4790
  * await order.removeProductsFromOrder([identityA, identityB]);
4791
4791
  */
4792
4792
  async removeProductsFromOrder(identities, options) {
4793
- return this.queueCartCommand(() => this.removeProductsFromOrderDraft(identities, options), Boolean(options?.isCurrentOrder));
4793
+ return this.queueCartCommand(() => this.removeProductsFromOrderDraft(identities, options), Boolean(options?.isCurrentOrder || options?.beforeApply));
4794
4794
  }
4795
4795
  async removeProductsFromOrderDraft(identities, options) {
4796
4796
  if (options?.isCurrentOrder && !options.isCurrentOrder()) {
4797
4797
  return this.store.tempOrder?.products || [];
4798
4798
  }
4799
+ // Validate inside the command queue, before creating or mutating the draft.
4800
+ if (identities.length) options?.beforeApply?.();
4801
+ if (options?.isCurrentOrder && !options.isCurrentOrder()) {
4802
+ return this.store.tempOrder?.products || [];
4803
+ }
4804
+ const guarded = Boolean(options?.isCurrentOrder || options?.beforeApply);
4799
4805
  const mutation = this.beginCartMutation({
4800
- forceDraft: Boolean(options?.isCurrentOrder)
4806
+ forceDraft: guarded
4801
4807
  });
4802
4808
  let tempOrder = mutation.draft;
4803
4809
  const identity = [mutation.current.order_id, mutation.current.external_sale_number];
4804
4810
  const isCurrentOrder = () => this.store.tempOrder === mutation.current && mutation.current.order_id === identity[0] && mutation.current.external_sale_number === identity[1] && (options?.isCurrentOrder?.() ?? true);
4805
- const beforeCommit = options?.isCurrentOrder ? () => {
4811
+ const beforeCommit = guarded ? () => {
4812
+ // Inventory validation can await. Recheck the live source snapshot before
4813
+ // publication; never run this row-snapshot guard during finalization.
4814
+ options?.beforeApply?.();
4806
4815
  if (!isCurrentOrder()) throw Object.assign(new Error('Order product removal interrupted by an order change'), {
4807
4816
  code: 'AVAILABILITY_SELECTION_STALE'
4808
4817
  });
@@ -4875,7 +4884,7 @@ class OrderModule extends _BaseModule.BaseModule {
4875
4884
  (0, _holderRelations.removeProductHolderRelations)(tempOrder, productsBeforeRemove.filter(product => !tempOrder.products.includes(product)));
4876
4885
  this.removeSalesNotesForMissingProductLines(tempOrder);
4877
4886
  if (mutation.commit) tempOrder = await mutation.commit(beforeCommit);
4878
- await this.finalizeAfterProductsMutation(tempOrder, options?.isCurrentOrder ? {
4887
+ await this.finalizeAfterProductsMutation(tempOrder, guarded ? {
4879
4888
  isCurrentOrder
4880
4889
  } : undefined);
4881
4890
  this.logInfo('removeProductsFromOrder success', {
@@ -482,6 +482,8 @@ export interface ReplaceBookingProductWithRelatedRetailParams {
482
482
  * 预约合并行减量时仍删除最新真实行,再把剩余代表行移动到被删除代表行原位置。
483
483
  */
484
484
  export interface RemoveProductsFromOrderOptions {
485
+ /** Synchronous, read-only validation before draft mutation and again before publication after async guards; may throw. Never called during finalization. */
486
+ beforeApply?: () => void;
485
487
  /** Prevent an asynchronous deletion/finalization from crossing order or business scopes. */
486
488
  isCurrentOrder?: () => boolean;
487
489
  preserveDisplayPosition?: {
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  date: string;
327
327
  status: string;
328
328
  week: string;
329
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
329
+ weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
330
330
  }[]>;
331
331
  submitTimeSlot(timeSlots: TimeSliceItem): void;
332
332
  private getScheduleDataByIds;
@@ -373,7 +373,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
373
373
  };
374
374
  setOtherData(key: string, value: any): void;
375
375
  getOtherData(key: string): any;
376
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
376
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
377
377
  /**
378
378
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
379
379
  *
@@ -479,7 +479,19 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
479
479
  * 加车两阶段主决策(规格弹窗 / 资源编辑 / 直接加车)。
480
480
  * 与 ticketBooking `handleSelectProduct` + `handleBooking4Service` 等价。
481
481
  */
482
- decideAddProduct(item: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
482
+ decideAddProduct(item: any, options?: Partial<AddProductDecideContext>): {
483
+ action: "reloadCatalog";
484
+ } | {
485
+ action: "add";
486
+ cacheItem: any;
487
+ } | {
488
+ action: "requiresDetail";
489
+ payload: AddProductRequiresDetailPayload;
490
+ } | {
491
+ action: "requiresBookingEdit";
492
+ cacheItem: any;
493
+ payload: import("./utils/addProductDecision").AddProductRequiresBookingEditPayload;
494
+ };
483
495
  /** 规格弹窗 callback 后的第二段决策。 */
484
496
  decideAfterDetail(cacheItem: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
485
497
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.10.79",
4
+ "version": "0.10.80",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",