@pisell/pisellos 2.3.225 → 2.3.227

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.
@@ -302,6 +302,11 @@ export interface UnifiedBookingSalesDiscountResult {
302
302
  summaryAfter?: unknown;
303
303
  }
304
304
  export interface UnifiedBookingSalesApi {
305
+ getDraftDiscountSelection: () => import('./draftDiscounts').DraftDiscountSelection[];
306
+ restoreDraftDiscountSelection: (snapshot: {
307
+ order: Record<string, any>;
308
+ discountSelection?: import('./draftDiscounts').DraftDiscountSelection[];
309
+ }) => Promise<void>;
305
310
  /** Uses cached business settings and evaluates the current store-local clock. */
306
311
  getBusinessAvailability: () => Promise<import('../../modules/BusinessAvailability').BusinessAvailability>;
307
312
  loadOpenData: (params: UnifiedBookingSalesLoadOpenDataParams) => Promise<OpenDataConfig>;
@@ -1,46 +1 @@
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; }
1
+ "use strict";
@@ -131,6 +131,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
131
131
  scannedDiscountList?: Discount[];
132
132
  }>;
133
133
  applyDiscount(options?: {
134
+ /** Draft recovery must remove stale discounts even when no card survives revalidation. */
135
+ force?: boolean;
134
136
  reapplyBookingDiscountProductUids?: string[];
135
137
  reapplyWeighedDiscountProductUids?: string[];
136
138
  preferredEntitlementPassIds?: number[];
@@ -642,7 +644,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
642
644
  generateIdempotencyToken(): string;
643
645
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
644
646
  createOrder(params: CommitOrderParams['query']): {
645
- type: "appointment_booking" | "virtual";
647
+ type: "virtual" | "appointment_booking";
646
648
  platform: string;
647
649
  sales_channel: string;
648
650
  order_sales_channel: string;
@@ -944,7 +944,7 @@ class OrderModule extends _BaseModule.BaseModule {
944
944
  delete tempOrder.discount_list;
945
945
  const discountList = this.store.discount?.getDiscountList() || [];
946
946
  const shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
947
- if (shouldSkipDiscountCalculation) return;
947
+ if (shouldSkipDiscountCalculation && !options?.force) return;
948
948
  const rulesModule = this.store.rules;
949
949
  if (!rulesModule) return;
950
950
  const result = rulesModule.calcDiscount({
@@ -956,7 +956,8 @@ class OrderModule extends _BaseModule.BaseModule {
956
956
  }, {
957
957
  reapplyBookingDiscountProductUids: options?.reapplyBookingDiscountProductUids,
958
958
  reapplyWeighedDiscountProductUids: options?.reapplyWeighedDiscountProductUids,
959
- preferredEntitlementPassIds: options?.preferredEntitlementPassIds
959
+ preferredEntitlementPassIds: options?.preferredEntitlementPassIds,
960
+ force: options?.force
960
961
  });
961
962
  if (result?.productList) {
962
963
  const previousProductsByUid = (0, _utils.indexOrderProductsByUid)(tempOrder.products);
@@ -307,7 +307,7 @@ class RulesModule extends _BaseModule.BaseModule {
307
307
  }
308
308
  });
309
309
  }
310
- const hasDiscountInput = editModeDiscount.length > 0 || addModeDiscount.length > 0 || Boolean(options?.discountId) || Boolean(options?.selectedList?.length) || Boolean(options?.scan);
310
+ const hasDiscountInput = options?.force === true || editModeDiscount.length > 0 || addModeDiscount.length > 0 || Boolean(options?.discountId) || Boolean(options?.selectedList?.length) || Boolean(options?.scan);
311
311
  if (!hasDiscountInput) {
312
312
  return {
313
313
  discountList,
@@ -34,6 +34,8 @@ export interface RulesCalcDiscountParams {
34
34
  orderTotalAmount: number;
35
35
  }
36
36
  export interface RulesCalcDiscountOptions {
37
+ /** Clear stale line discounts when draft revalidation yields no eligible cards. */
38
+ force?: boolean;
37
39
  isSelected?: boolean;
38
40
  discountId?: number;
39
41
  selectedList?: SetDiscountSelectedParams[];
@@ -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 | 5 | 4 | 3 | 6;
346
346
  }[]>;
347
347
  submitTimeSlot(timeSlots: TimeSliceItem): void;
348
348
  private getScheduleDataByIds;
@@ -25,23 +25,27 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
25
25
  notes?: import("../../../modules/Order/types").SalesNote[] | undefined;
26
26
  summary?: import("../../../modules/Order/types").OrderSummary | undefined;
27
27
  small_ticket_data_flag?: number | undefined;
28
- metadata: Record<string, any>;
29
28
  type: string;
29
+ metadata: Record<string, any>;
30
+ business_code?: string | undefined;
31
+ status: string;
30
32
  note: string;
31
33
  holder: Record<string, any> | null;
32
- relation_forms: any[];
34
+ customer_id: number | null;
35
+ bookings: any[];
36
+ payments: any[];
37
+ contacts_info: Record<string, any> | null;
38
+ order_meta_list?: import("../../../modules/Order/types").OrderMetaList | undefined;
39
+ refunds?: any[] | undefined;
33
40
  holder_relations?: import("../../../modules/Order/types").OrderHolderRelation[] | undefined;
34
41
  order_id: number | null;
35
42
  external_sale_number: string;
36
43
  order_number: string | null;
37
44
  shop_order_number: string | null;
38
45
  shop_full_order_number: string | null;
39
- business_code?: string | undefined;
40
46
  sales_channel: string;
41
47
  order_sales_channel: string;
42
- status: string;
43
48
  shipping_status: string;
44
- customer_id: number | null;
45
49
  customer_name: string;
46
50
  country_calling_code: string;
47
51
  phone: string;
@@ -60,12 +64,8 @@ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary
60
64
  delivery_type?: string | undefined;
61
65
  table_number?: Record<string, any> | undefined;
62
66
  schedule_date: string;
63
- bookings: any[];
64
- payments: any[];
65
- contacts_info: Record<string, any> | null;
66
- order_meta_list?: import("../../../modules/Order/types").OrderMetaList | undefined;
67
- refunds?: any[] | undefined;
68
67
  surcharges: any[];
68
+ relation_forms: any[];
69
69
  contacts: any[];
70
70
  };
71
71
  export declare function describeChangedBookings(before: OrderTempOrder['bookings'], after: OrderTempOrder['bookings']): {
@@ -0,0 +1,8 @@
1
+ /** Persist selection intent only; availability and pricing must come from fresh OS data. */
2
+ export interface DraftDiscountSelection {
3
+ id: string;
4
+ code?: string;
5
+ selected: boolean;
6
+ isScan?: boolean;
7
+ }
8
+ export declare function collectDraftDiscountSelection(order: Record<string, any>, runtime?: Record<string, any>[]): DraftDiscountSelection[];
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectDraftDiscountSelection = collectDraftDiscountSelection;
7
+ /** Persist selection intent only; availability and pricing must come from fresh OS data. */
8
+
9
+ const voucherTypes = new Set(['discount_card', 'product_discount_card', 'good_pass', 'entitlement_pass']);
10
+ function collectDraftDiscountSelection(order, runtime) {
11
+ const selections = new Map();
12
+ const append = (discount, line = false) => {
13
+ if (!voucherTypes.has(discount?.tag || discount?.type) || discount.isEditMode) return;
14
+ const id = String(line ? discount.discount?.resource_id || discount.id || '' : discount.id || '');
15
+ if (!id || !Number.isFinite(Number(id)) || Number(id) <= 0) return;
16
+ const machineCode = discount.data?.discount_card_list?.[0] || discount.discount_card_list?.[0] || discount.machinecode || discount.machine_code || discount;
17
+ const code = machineCode.encoded || discount.metadata?.encoded;
18
+ const previous = selections.get(id);
19
+ selections.set(id, {
20
+ id,
21
+ code: typeof code === 'string' && code.trim() ? code.trim() : previous?.code,
22
+ selected: line || discount.isSelected !== false,
23
+ isScan: Boolean(discount.isScan || previous?.isScan)
24
+ });
25
+ };
26
+ // Old venue drafts may have lost the root list on reload, while line discounts retain the code.
27
+ for (const product of order.products || []) {
28
+ for (const discount of product.discount_list || []) append(discount, true);
29
+ for (const bundle of product.product_bundle || []) {
30
+ for (const discount of bundle.discount_list || []) append(discount, true);
31
+ }
32
+ }
33
+ for (const discount of order.discount_list || []) append(discount);
34
+ for (const discount of runtime || []) append(discount);
35
+ return [...selections.values()];
36
+ }
@@ -1,3 +1,4 @@
1
+ import { type DraftDiscountSelection } from './draftDiscounts';
1
2
  import type { Module, ModuleOptions, PisellCore } from '../../types';
2
3
  import type { ProductData } from '../../modules';
3
4
  import type { BookingCalcContext } from '../../modules/BookingContext';
@@ -195,6 +196,12 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
195
196
  protected getRegisteredModuleNames(): readonly string[];
196
197
  protected createSubModule(moduleName: string): Module | null;
197
198
  addNewOrder(): Promise<import("../../modules/Order/types").OrderTempOrder>;
199
+ getDraftDiscountSelection(): DraftDiscountSelection[];
200
+ /** Restore a local draft's cards as editable runtime entries, never as settled historical cards. */
201
+ restoreDraftDiscountSelection(snapshot: {
202
+ order: Record<string, any>;
203
+ discountSelection?: DraftDiscountSelection[];
204
+ }): Promise<void>;
198
205
  syncAuthenticatedOrderCustomer(): Promise<boolean>;
199
206
  private isAuthenticatedCustomerUserPlatform;
200
207
  private resolveDiscountOrderIdentity;
@@ -31,6 +31,7 @@ exports.collectAvailabilityResourceIds = collectAvailabilityResourceIds;
31
31
  exports.normalizeProductForAvailability = normalizeProductForAvailability;
32
32
  var _dayjs = _interopRequireDefault(require("dayjs"));
33
33
  var _lodashEs = require("lodash-es");
34
+ var _draftDiscounts = require("./draftDiscounts");
34
35
  var _modules = require("../../modules");
35
36
  var _pickupTiming = require("../../modules/Order/pickupTiming");
36
37
  var _cacheItemToBookingInput = require("../../modules/BookingContext/utils/cacheItemToBookingInput");
@@ -2097,6 +2098,83 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2097
2098
  }
2098
2099
  return this.store.order?.getTempOrder() || tempOrder;
2099
2100
  }
2101
+ getDraftDiscountSelection() {
2102
+ const order = this.getTempOrder();
2103
+ return order ? (0, _draftDiscounts.collectDraftDiscountSelection)(order, this.getDiscountList()) : [];
2104
+ }
2105
+
2106
+ /** Restore a local draft's cards as editable runtime entries, never as settled historical cards. */
2107
+ async restoreDraftDiscountSelection(snapshot) {
2108
+ const order = this.getTempOrder();
2109
+ if (!order || order.order_id && !isLocalOrderId(order.order_id)) return;
2110
+ const customerId = resolveTempOrderCustomerId(order);
2111
+ // A login/account change must not replay another customer's saved cards.
2112
+ if (resolveTempOrderCustomerId(snapshot.order) !== customerId) return;
2113
+ if (snapshot.order.external_sale_number !== order.external_sale_number) return;
2114
+ const selections = snapshot.discountSelection ?? (0, _draftDiscounts.collectDraftDiscountSelection)(snapshot.order);
2115
+ if (!selections.length) return;
2116
+ const beforeCommit = this.store.order.createCartIntentCommitGuard('scan_promotion', order);
2117
+ const assertCurrent = () => {
2118
+ if (this.getTempOrder() !== order || resolveTempOrderCustomerId(this.getTempOrder()) !== customerId) {
2119
+ throw Object.assign(new Error('The draft discount session ended.'), {
2120
+ code: 'SALES_GUARD_REJECTED'
2121
+ });
2122
+ }
2123
+ };
2124
+ assertCurrent();
2125
+ const discountModule = this.store.order.store.discount;
2126
+ const current = this.getDiscountList();
2127
+ const currentById = new Map(current.map(discount => [String(discount.id), discount]));
2128
+ const codes = [...new Set(selections.filter(selection => selection.code && (selection.isScan || !currentById.has(String(selection.id)))).map(selection => selection.code))];
2129
+ // Scanned cards are absent from prepare/config. Re-query each unique code once;
2130
+ // copying their old config would keep expired cards and stale eligibility alive.
2131
+ const results = await Promise.all(codes.map(code => discountModule.batchSearch(code, {
2132
+ customerId: customerId || undefined
2133
+ })));
2134
+ assertCurrent();
2135
+ const scanned = new Map();
2136
+ for (const result of results) {
2137
+ for (const discount of result.discountList || []) scanned.set(String(discount.id), discount);
2138
+ }
2139
+ const next = new Map(this.getDiscountList().map(discount => [String(discount.id), discount]));
2140
+ for (const selection of selections) {
2141
+ const id = String(selection.id);
2142
+ const revalidated = selection.code && (selection.isScan || !currentById.has(id));
2143
+ const discount = revalidated ? scanned.get(id) : next.get(id);
2144
+ if (!discount) {
2145
+ next.delete(id);
2146
+ continue;
2147
+ }
2148
+ next.set(id, {
2149
+ ...discount,
2150
+ isScan: Boolean(selection.isScan || revalidated),
2151
+ isSelected: selection.selected,
2152
+ isManualSelect: !selection.selected
2153
+ });
2154
+ }
2155
+ beforeCommit();
2156
+ await discountModule.setOriginalDiscountList([...next.values()]);
2157
+ assertCurrent();
2158
+ await discountModule.setDiscountList([...next.values()]);
2159
+ assertCurrent();
2160
+ // One calculation owns both the displayed cards and the restored line prices.
2161
+ this.store.order.applyDiscount({
2162
+ force: true
2163
+ });
2164
+ await this.store.order.recalculateSummary({
2165
+ createIfMissing: true
2166
+ });
2167
+ assertCurrent();
2168
+ const restored = this.store.order.ensureTempOrder();
2169
+ restored.discount_list = this.getDiscountList().filter(discount => discount.isSelected);
2170
+ this.store.order.persistTempOrder();
2171
+ await this.effectsEmit('onDiscountApplied', {
2172
+ productList: restored.products || [],
2173
+ discountList: this.getDiscountList(),
2174
+ selectedDiscountList: restored.discount_list,
2175
+ tempOrder: restored
2176
+ });
2177
+ }
2100
2178
  async syncAuthenticatedOrderCustomer() {
2101
2179
  if (!this.isAuthenticatedCustomerUserPlatform()) return false;
2102
2180
  const authenticatedCustomer = this.core?.getPlugin?.('user')?.get?.();
@@ -302,6 +302,11 @@ export interface UnifiedBookingSalesDiscountResult {
302
302
  summaryAfter?: unknown;
303
303
  }
304
304
  export interface UnifiedBookingSalesApi {
305
+ getDraftDiscountSelection: () => import('./draftDiscounts').DraftDiscountSelection[];
306
+ restoreDraftDiscountSelection: (snapshot: {
307
+ order: Record<string, any>;
308
+ discountSelection?: import('./draftDiscounts').DraftDiscountSelection[];
309
+ }) => Promise<void>;
305
310
  /** Uses cached business settings and evaluates the current store-local clock. */
306
311
  getBusinessAvailability: () => Promise<import('../../modules/BusinessAvailability').BusinessAvailability>;
307
312
  loadOpenData: (params: UnifiedBookingSalesLoadOpenDataParams) => Promise<OpenDataConfig>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.225",
4
+ "version": "2.3.227",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",