@pisell/pisellos 2.3.219 → 2.3.220

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.
@@ -1 +1,46 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "BUY_X_GET_Y_FREE_STRATEGY", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _examples.BUY_X_GET_Y_FREE_STRATEGY;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "ITEM_REWARD_STRATEGY", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _examples.ITEM_REWARD_STRATEGY;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "PromotionAdapter", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _adapter.PromotionAdapter;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "PromotionEvaluator", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _evaluator.PromotionEvaluator;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "X_ITEMS_FOR_Y_PRICE_STRATEGY", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _examples.X_ITEMS_FOR_Y_PRICE_STRATEGY;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "default", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _adapter.default;
40
+ }
41
+ });
42
+ var _evaluator = require("./evaluator");
43
+ var _adapter = _interopRequireWildcard(require("./adapter"));
44
+ var _examples = require("./examples");
45
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
46
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -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(): "normal" | "duration" | "session";
52
+ getProductType(): "normal" | "session" | "duration";
53
53
  }
@@ -55,6 +55,8 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
55
55
  protected store: BaseSalesState;
56
56
  protected otherParams: Record<string, any>;
57
57
  getInventory(): InventoryController | undefined;
58
+ /** Retail and standard POS opt in per sales instance; other hosts retain their member flow. */
59
+ isMemberCartConsistencyEnabled(): boolean;
58
60
  prepareCheckout(signal?: AbortSignal): Promise<CheckoutRuntimeSnapshot | undefined>;
59
61
  protected cacheId: string | undefined;
60
62
  /**
@@ -23,6 +23,7 @@ Object.keys(_types).forEach(function (key) {
23
23
  });
24
24
  });
25
25
  var _Order = require("../../modules/Order");
26
+ var _discountProductLineIdentity = require("../../modules/Order/utils/discountProductLineIdentity");
26
27
  var _pickupTiming = require("../../modules/Order/pickupTiming");
27
28
  var _pickupTiming2 = require("./pickupTiming");
28
29
  var _fulfillmentItemRules = require("./fulfillmentItemRules");
@@ -156,6 +157,14 @@ function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
156
157
  return previous && isBaseSalesManualProductDiscountProduct(previous) ? previous : product;
157
158
  });
158
159
  }
160
+
161
+ /** Rules may split a coupon quantity into rows that still share the original UID. */
162
+ function applyDiscountProductLines(tempOrder, products, discounts, enableMemberCartConsistency) {
163
+ tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, products);
164
+ if (!enableMemberCartConsistency) return;
165
+ (0, _discountProductLineIdentity.ensureUniqueProductLineUids)(tempOrder, discounts);
166
+ (0, _discountProductLineIdentity.consolidateDiscountFreeProductLines)(tempOrder);
167
+ }
159
168
  function isBaseSalesHistoricalDiscountEntry(discount) {
160
169
  return Boolean(discount?.isEditMode || discount?.isDisabled || discount?.order_discount_id != null);
161
170
  }
@@ -517,6 +526,11 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
517
526
  getInventory() {
518
527
  return this.otherParams.inventory;
519
528
  }
529
+
530
+ /** Retail and standard POS opt in per sales instance; other hosts retain their member flow. */
531
+ isMemberCartConsistencyEnabled() {
532
+ return this.otherParams.enableMemberCartConsistency === true;
533
+ }
520
534
  async prepareCheckout(signal) {
521
535
  const inventory = this.getInventory();
522
536
  const hooks = this.otherParams.checkoutHooks;
@@ -2322,7 +2336,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2322
2336
  }
2323
2337
  async loadDiscountConfig(params) {
2324
2338
  if (!this.store.order) throw new Error('order 模块未初始化');
2325
- const tempOrder = this.store.order.ensureTempOrder();
2339
+ let tempOrder = this.store.order.ensureTempOrder();
2326
2340
  const orderStore = this.store.order.store || {};
2327
2341
  const discountModule = orderStore.discount;
2328
2342
  const rulesModule = orderStore.rules;
@@ -2337,7 +2351,11 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2337
2351
  let requestEpoch = this.store.order.getCustomerWalletPrepareConfigEpoch?.();
2338
2352
  const isCurrentRequest = () => {
2339
2353
  const currentTempOrder = this.store.order?.getTempOrder?.();
2340
- return Boolean(currentTempOrder && (requestEpoch === undefined || this.store.order?.getCustomerWalletPrepareConfigEpoch?.() === requestEpoch) && this.resolveDiscountConfigCustomerId(currentTempOrder) === customerId && this.getDiscountConfigOrderIdentityKey(currentTempOrder) === requestOrderIdentityKey);
2354
+ const current = Boolean(currentTempOrder && (requestEpoch === undefined || this.store.order?.getCustomerWalletPrepareConfigEpoch?.() === requestEpoch) && this.resolveDiscountConfigCustomerId(currentTempOrder) === customerId && this.getDiscountConfigOrderIdentityKey(currentTempOrder) === requestOrderIdentityKey);
2355
+ // Cart edits can replace the object while member configuration is pending.
2356
+ // Keep the logical-order guard, but apply coupons to its latest rows.
2357
+ if (current && this.isMemberCartConsistencyEnabled()) tempOrder = currentTempOrder;
2358
+ return current;
2341
2359
  };
2342
2360
  const getCurrentResult = () => {
2343
2361
  const currentTempOrder = this.store.order?.getTempOrder?.();
@@ -2466,7 +2484,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2466
2484
  discountList: nextDiscountList
2467
2485
  };
2468
2486
  if (result.productList) {
2469
- tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
2487
+ applyDiscountProductLines(tempOrder, result.productList, result.discountList || nextDiscountList, this.isMemberCartConsistencyEnabled());
2470
2488
  }
2471
2489
  for (const product of tempOrder.products || []) {
2472
2490
  const productUid = product.metadata?.unique_identification_number;
@@ -2559,7 +2577,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2559
2577
  preserveEntitlementSelection: false
2560
2578
  }) || result;
2561
2579
  if (result.productList) {
2562
- tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
2580
+ applyDiscountProductLines(tempOrder, result.productList, result.discountList || nextDiscountList, this.isMemberCartConsistencyEnabled());
2563
2581
  }
2564
2582
  if (result.discountList) {
2565
2583
  nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
@@ -2686,7 +2704,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2686
2704
  discountList: updated
2687
2705
  };
2688
2706
  if (result?.productList) {
2689
- tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
2707
+ applyDiscountProductLines(tempOrder, result.productList, result.discountList || updated, this.isMemberCartConsistencyEnabled());
2690
2708
  }
2691
2709
  if (result?.discountList) {
2692
2710
  nextDiscountList = result.discountList;
@@ -2774,7 +2792,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2774
2792
  const orderStore = this.store.order.store || {};
2775
2793
  const discountModule = orderStore.discount;
2776
2794
  if (result.productList) {
2777
- tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
2795
+ applyDiscountProductLines(tempOrder, result.productList, result.discountList || this.getDiscountList(), this.isMemberCartConsistencyEnabled());
2778
2796
  }
2779
2797
  if (result.discountList) {
2780
2798
  _Order.OrderModule.populateSavedAmounts(tempOrder.products, result.discountList);
@@ -4416,6 +4434,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4416
4434
  const currentOrderCustomerId = this.getCurrentOrderCustomerId();
4417
4435
  const resolvedChannels = paramsList.map(params => this.getPriceQueryChannel(params.channel));
4418
4436
  const authoritativeProducts = await this.resolveProductBookingPriceGroups(paramsList, currentOrderCustomerId);
4437
+ if (paramsList.some((params, index) => params.requireAuthoritativePrice && !authoritativeProducts[index])) {
4438
+ throw new Error('The current customer product price is unavailable. Please retry before paying.');
4439
+ }
4419
4440
  const plans = paramsList.map((params, index) => {
4420
4441
  if (!isPos) return null;
4421
4442
  const product = authoritativeProducts[index];
@@ -305,6 +305,8 @@ export interface BaseSalesQuotationDurationConfig {
305
305
  }
306
306
  export interface BaseSalesCalculateProductBookingPriceParams {
307
307
  product: Record<string, any>;
308
+ /** Fail closed when the current customer price cannot be resolved; no old-line fallback. */
309
+ requireAuthoritativePrice?: boolean;
308
310
  booking?: {
309
311
  start_date?: string;
310
312
  start_time?: string;
@@ -342,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
342
342
  date: string;
343
343
  status: string;
344
344
  week: string;
345
- weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
345
+ weekNum: 0 | 1 | 2 | 6 | 4 | 5 | 3;
346
346
  }[]>;
347
347
  submitTimeSlot(timeSlots: TimeSliceItem): void;
348
348
  private getScheduleDataByIds;
@@ -32,6 +32,8 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
32
32
  private orderCustomerDiscountRefreshCustomerId;
33
33
  private orderCustomerDiscountRefreshTarget;
34
34
  private orderCustomerPromotionRefreshInFlight;
35
+ private orderCustomerRefreshTask;
36
+ private orderCustomerRefreshRevision;
35
37
  private orderCustomerContactRequest;
36
38
  private readonly customerResolveRequests;
37
39
  protected loadOpenDataInFlight: Promise<OpenDataConfig> | null;
@@ -283,6 +285,9 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
283
285
  setOrderCustomer(customer: ICustomer | null, options?: {
284
286
  source?: OrderCustomerChangePayload['source'];
285
287
  }): void;
288
+ /** Shared by customer changes and an explicit retry; keep the selected customer/cart intact. */
289
+ private refreshMemberCartContext;
290
+ retryOrderCustomerRefresh(): Promise<void>;
286
291
  private resetOrderCustomerContactInfo;
287
292
  /** Explicit edits, including clearing the contact, must win over a pending default. */
288
293
  updateTempOrderContactsInfo(contact: Record<string, any> | null): Record<string, any> | null;
@@ -321,6 +326,8 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
321
326
  private buildOrderCustomerPayload;
322
327
  protected refreshDiscountConfigAfterOrderCustomerChange(customerId: number | null): Promise<void>;
323
328
  protected waitForOrderCustomerPromotionRefresh(): Promise<void>;
329
+ /** Wait before reading cart rows: member coupons can split or consolidate them. */
330
+ waitForOrderCustomerRefresh(): Promise<void>;
324
331
  protected prepareProductPriceQueryContext(customerId?: number | string): Promise<void>;
325
332
  protected preferAuthoritativeProductQueryPrice(): boolean;
326
333
  /**
@@ -168,6 +168,9 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
168
168
  orderCustomerDiscountRefreshCustomerId = null;
169
169
  orderCustomerDiscountRefreshTarget = null;
170
170
  orderCustomerPromotionRefreshInFlight = null;
171
+ // Retain the settled result too: a failed refresh must remain observable by checkout callers.
172
+ orderCustomerRefreshTask = Promise.resolve();
173
+ orderCustomerRefreshRevision = 0;
171
174
  orderCustomerContactRequest = null;
172
175
  customerResolveRequests = new Map();
173
176
  loadOpenDataInFlight = null;
@@ -1084,13 +1087,17 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1084
1087
  }
1085
1088
  return;
1086
1089
  }
1090
+ const enableMemberCartConsistency = this.isMemberCartConsistencyEnabled();
1087
1091
  const next = this.buildOrderCustomerPayload();
1088
1092
  this.core.effects.emit(`${this.name}:onOrderCustomerChange`, next && options?.source ? {
1089
1093
  ...next,
1090
1094
  source: options.source
1091
1095
  } : next);
1092
- this.refreshDiscountConfigAfterOrderCustomerChange(patch.customer_id);
1093
- // 客户切换可能改变可用促销/赠品;触发一次重算(recursion-safe)。
1096
+ if (enableMemberCartConsistency) {
1097
+ this.refreshMemberCartContext(patch.customer_id);
1098
+ return;
1099
+ }
1100
+ void this.refreshDiscountConfigAfterOrderCustomerChange(patch.customer_id);
1094
1101
  const promotionRefreshTask = this.store.order.applyPromotion().then(() => undefined);
1095
1102
  this.orderCustomerPromotionRefreshInFlight = promotionRefreshTask;
1096
1103
  void promotionRefreshTask.then(() => {
@@ -1102,6 +1109,31 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1102
1109
  this.orderCustomerPromotionRefreshInFlight = null;
1103
1110
  });
1104
1111
  }
1112
+
1113
+ /** Shared by customer changes and an explicit retry; keep the selected customer/cart intact. */
1114
+ refreshMemberCartContext(customerId) {
1115
+ const revision = ++this.orderCustomerRefreshRevision;
1116
+ const orderKey = this.getCustomerContactOrderKey();
1117
+ const isCurrent = () => revision === this.orderCustomerRefreshRevision && this.getCustomerContactOrderKey() === orderKey && Number(this.store.order.getOrderCustomer()?.customer_id || 0) === Number(customerId || 0);
1118
+ const task = (async () => {
1119
+ if (customerId) await this.refreshDiscountConfigAfterOrderCustomerChange(customerId);else await this.loadDiscountConfig({
1120
+ force: true
1121
+ });
1122
+ if (isCurrent()) await this.store.order.applyPromotion();
1123
+ })();
1124
+ this.orderCustomerRefreshTask = task;
1125
+ this.orderCustomerPromotionRefreshInFlight = task;
1126
+ void task.catch(error => {
1127
+ if (isCurrent()) console.error('[BookingTicket] Member cart refresh failed', error);
1128
+ }).finally(() => {
1129
+ if (this.orderCustomerPromotionRefreshInFlight === task) this.orderCustomerPromotionRefreshInFlight = null;
1130
+ });
1131
+ }
1132
+ async retryOrderCustomerRefresh() {
1133
+ if (!this.isMemberCartConsistencyEnabled()) return;
1134
+ this.refreshMemberCartContext(this.store.order.getOrderCustomer()?.customer_id ?? null);
1135
+ await this.waitForOrderCustomerRefresh();
1136
+ }
1105
1137
  resetOrderCustomerContactInfo() {
1106
1138
  this.orderCustomerContactRequest = null;
1107
1139
  const order = this.getTempOrder();
@@ -1220,6 +1252,8 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1220
1252
  * 清空下单客户(协议字段 + snapshot)。
1221
1253
  */
1222
1254
  clearOrderCustomer(options) {
1255
+ const enableMemberCartConsistency = this.isMemberCartConsistencyEnabled();
1256
+ const refreshRevision = enableMemberCartConsistency ? ++this.orderCustomerRefreshRevision : undefined;
1223
1257
  this.orderCustomerContactRequest = null;
1224
1258
  if (!options?.preserveContactInfo) this.resetOrderCustomerContactInfo();
1225
1259
  if (!options?.preserveContactInfo) this.store.order.updateTempOrderContactsInfo(null);
@@ -1231,9 +1265,11 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1231
1265
  void discountModule?.setOriginalDiscountList?.([]);
1232
1266
  void discountModule?.setDiscountList?.([]);
1233
1267
  this.store.order.applyDiscount();
1234
- void this.store.order.recalculateSummary({
1268
+ const customerOrderKey = enableMemberCartConsistency ? this.getCustomerContactOrderKey() : undefined;
1269
+ const refreshTask = this.store.order.recalculateSummary({
1235
1270
  createIfMissing: true
1236
1271
  }).then(() => {
1272
+ if (enableMemberCartConsistency && (this.orderCustomerRefreshRevision !== refreshRevision || this.getCustomerContactOrderKey() !== customerOrderKey)) return;
1237
1273
  const tempOrder = this.store.order.ensureTempOrder();
1238
1274
  this.store.order.persistTempOrder();
1239
1275
  return this.effectsEmit('onDiscountApplied', {
@@ -1242,7 +1278,9 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1242
1278
  selectedDiscountList: tempOrder.discount_list || [],
1243
1279
  tempOrder
1244
1280
  });
1245
- }).catch(error => {
1281
+ });
1282
+ if (enableMemberCartConsistency) this.orderCustomerRefreshTask = refreshTask.then(() => undefined);
1283
+ void (enableMemberCartConsistency ? this.orderCustomerRefreshTask : refreshTask).catch(error => {
1246
1284
  console.error('Failed to recalculate summary after clearing customer:', error);
1247
1285
  });
1248
1286
  this.core.effects.emit(`${this.name}:onOrderCustomerChange`, null);
@@ -1326,6 +1364,14 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1326
1364
  waitForOrderCustomerPromotionRefresh() {
1327
1365
  return this.orderCustomerPromotionRefreshInFlight || Promise.resolve();
1328
1366
  }
1367
+
1368
+ /** Wait before reading cart rows: member coupons can split or consolidate them. */
1369
+ async waitForOrderCustomerRefresh() {
1370
+ if (!this.isMemberCartConsistencyEnabled()) return;
1371
+ // Customer-change listeners run synchronously before setOrderCustomer assigns its task.
1372
+ await Promise.resolve();
1373
+ await this.orderCustomerRefreshTask;
1374
+ }
1329
1375
  async prepareProductPriceQueryContext(customerId) {
1330
1376
  // onOrderCustomerChange 的订阅回调会立即开始重报价,而客户 Wallet/优惠资产
1331
1377
  // 在事件派发后才创建异步刷新任务。先让出一个微任务,确保能观察到该任务。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.219",
4
+ "version": "2.3.220",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",