@pisell/pisellos 0.10.71 → 0.10.73

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 (31) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/BookingContext/index.d.ts +2 -2
  3. package/dist/modules/BookingContext/index.js +55 -25
  4. package/dist/modules/BookingContext/types.d.ts +2 -0
  5. package/dist/modules/Order/index.d.ts +13 -4
  6. package/dist/modules/Order/index.js +1401 -764
  7. package/dist/modules/Order/types.d.ts +24 -1
  8. package/dist/modules/Order/types.js +4 -0
  9. package/dist/server/index.js +5 -2
  10. package/dist/solution/BaseSales/index.d.ts +2 -2
  11. package/dist/solution/BaseSales/index.js +8 -8
  12. package/dist/solution/BookingByStep/index.d.ts +1 -1
  13. package/dist/solution/UnifiedBookingSales/index.d.ts +15 -0
  14. package/dist/solution/UnifiedBookingSales/index.js +1082 -596
  15. package/dist/solution/UnifiedBookingSales/types.d.ts +17 -1
  16. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  17. package/lib/modules/BookingContext/index.d.ts +2 -2
  18. package/lib/modules/BookingContext/index.js +42 -10
  19. package/lib/modules/BookingContext/types.d.ts +2 -0
  20. package/lib/modules/Order/index.d.ts +13 -4
  21. package/lib/modules/Order/index.js +284 -24
  22. package/lib/modules/Order/types.d.ts +24 -1
  23. package/lib/modules/Order/types.js +2 -0
  24. package/lib/server/index.js +5 -1
  25. package/lib/solution/BaseSales/index.d.ts +2 -2
  26. package/lib/solution/BaseSales/index.js +2 -2
  27. package/lib/solution/BookingByStep/index.d.ts +1 -1
  28. package/lib/solution/UnifiedBookingSales/index.d.ts +15 -0
  29. package/lib/solution/UnifiedBookingSales/index.js +343 -44
  30. package/lib/solution/UnifiedBookingSales/types.d.ts +17 -1
  31. package/package.json +1 -1
@@ -59,6 +59,12 @@ export interface UnifiedBookingSalesPrepareAvailabilityProjectionParams {
59
59
  dateRange?: Partial<AvailabilityDateRange>;
60
60
  catalogScope?: UnifiedBookingSalesCatalogScope;
61
61
  rawProducts?: Record<string, any>[];
62
+ /** Keep an independent catalog/projection without replacing the public sales catalog. Defaults to true. */
63
+ publishCatalog?: boolean;
64
+ /** Await remote occupancy refresh instead of stale-while-revalidate. Ignores rawResources; does not lock resources. */
65
+ refreshOccupancies?: boolean;
66
+ /** Enforce configured sale cutoffs and disable manual POS availability overrides for this context. Defaults to false. */
67
+ strictAvailability?: boolean;
62
68
  rawResources?: Record<string, any>[];
63
69
  rawOccupancies?: AvailabilityOccupancy[];
64
70
  editingProductLineUids?: string[];
@@ -152,10 +158,20 @@ export interface UnifiedBookingSalesAddRetailProductParams {
152
158
  productId?: number | string;
153
159
  quantity?: number;
154
160
  productLoadParams?: ProductListLoadProductsParams;
161
+ salesNotes?: SalesNoteDraftInput[];
162
+ availabilityCommitGuard?: () => void;
155
163
  }
156
164
  export interface ContextualCommitAvailabilitySelectionParams {
157
- mode: 'add' | 'edit';
165
+ mode: 'add' | 'edit' | 'replace';
166
+ /** Local UI intent guard, checked again immediately before the Order mutation. */
167
+ availabilityCommitGuard?: () => void;
158
168
  productLineUid?: string;
169
+ /**
170
+ * Confirmed complete Party extras set (configured, service-datetime-repriced retail source products).
171
+ * Required for replace; edit opts into the same atomic path. Existing extras keep their own
172
+ * metadata.unique_identification_number; new extras omit it. [] explicitly removes all owned extras.
173
+ */
174
+ relatedRetailProducts?: Record<string, any>[];
159
175
  orderProduct: Record<string, any>;
160
176
  candidate: ContextualProductTimeRange;
161
177
  requirementSelections: AvailabilityRequirementSelection[];
@@ -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; }
@@ -12,7 +12,7 @@ export * from './utils';
12
12
  export declare function __clearBookingContextSharedCacheForTest(): void;
13
13
  /** 稳定序列化 config 查询参数,用于判断是否与上次 loadBookingConfig 一致。 */
14
14
  export declare function buildBookingConfigQueryKey(params?: LoadBookingConfigParams): string;
15
- /** 稳定序列化资源列表查询(date + bookingIds),用于跳过重复 loadResources。 */
15
+ /** 稳定序列化资源列表查询(date + bookingIds + resourceIds)。 */
16
16
  export declare function buildBookingResourcesQueryKey(params?: LoadBookingResourcesParams): string;
17
17
  export declare class BookingContextModule extends BaseModule implements Module, BookingContextModuleAPI {
18
18
  protected defaultName: string;
@@ -22,7 +22,7 @@ export declare class BookingContextModule extends BaseModule implements Module,
22
22
  private otherParams;
23
23
  /** 上次成功 loadBookingConfig 的 query key;命中则不再请求。 */
24
24
  private lastConfigQueryKey;
25
- /** 上次成功 loadResources 的 query key(date|bookingIds);命中则不再请求。 */
25
+ /** 上次成功 loadResources 的 query key(接口合同 + 日期/预约/资源范围)。 */
26
26
  private lastResourcesQueryKey;
27
27
  constructor(name?: string, version?: string);
28
28
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
@@ -190,12 +190,38 @@ function resolveBookingConfigRequest(platform, params = {}) {
190
190
  key: `${endpoint}:${JSON.stringify(sortedQuery)}`
191
191
  };
192
192
  }
193
+ function normalizeBookingResourceIds(ids) {
194
+ return [...new Set((ids || []).map(id => String(id).trim()).filter(Boolean))].sort();
195
+ }
193
196
 
194
- /** 稳定序列化资源列表查询(date + bookingIds),用于跳过重复 loadResources。 */
197
+ /** 稳定序列化资源列表查询(date + bookingIds + resourceIds)。 */
195
198
  function buildBookingResourcesQueryKey(params = {}) {
196
199
  const date = toScheduleQueryDate(params.date);
197
200
  const ids = (params.bookingIds || []).filter(id => typeof id === 'number' && Number.isFinite(id)).sort((a, b) => a - b);
198
- return `${date}|${ids.join(',')}`;
201
+ const resourceIds = normalizeBookingResourceIds(params.resourceIds);
202
+ return `${date}|${ids.join(',')}${resourceIds.length ? `|resources:${JSON.stringify(resourceIds)}` : ''}`;
203
+ }
204
+ function resolveBookingResourcesRequest(platform, params) {
205
+ const date = toScheduleQueryDate(params.date);
206
+ const isCustomerPlatform = (0, _platform.isCustomerUserPlatform)(platform);
207
+ const resourceIds = normalizeBookingResourceIds(params.resourceIds);
208
+ return {
209
+ // The customer endpoint uses the same inclusive date range as DateModule.
210
+ // Keep the public date contract and the staff endpoint's existing query.
211
+ query: isCustomerPlatform ? {
212
+ start_date: date,
213
+ end_date: date,
214
+ ...(resourceIds.length ? {
215
+ resource_ids: resourceIds
216
+ } : {})
217
+ } : {
218
+ date
219
+ },
220
+ key: `${isCustomerPlatform ? 'customer' : 'staff'}:${buildBookingResourcesQueryKey({
221
+ ...params,
222
+ date
223
+ })}`
224
+ };
199
225
  }
200
226
  class BookingContextModule extends _BaseModule.BaseModule {
201
227
  defaultName = 'bookingContext';
@@ -207,7 +233,7 @@ class BookingContextModule extends _BaseModule.BaseModule {
207
233
  otherParams = {};
208
234
  /** 上次成功 loadBookingConfig 的 query key;命中则不再请求。 */
209
235
  lastConfigQueryKey = null;
210
- /** 上次成功 loadResources 的 query key(date|bookingIds);命中则不再请求。 */
236
+ /** 上次成功 loadResources 的 query key(接口合同 + 日期/预约/资源范围)。 */
211
237
  lastResourcesQueryKey = null;
212
238
  constructor(name, version) {
213
239
  super(name, version);
@@ -277,9 +303,13 @@ class BookingContextModule extends _BaseModule.BaseModule {
277
303
  }
278
304
  async loadResources(params = {}, options = {}) {
279
305
  const date = toScheduleQueryDate(params.date ?? this.store.date);
280
- const resourcesKey = buildBookingResourcesQueryKey({
306
+ const {
307
+ query,
308
+ key: resourcesKey
309
+ } = resolveBookingResourcesRequest(this.otherParams?.platform, {
281
310
  date,
282
- bookingIds: params.bookingIds
311
+ bookingIds: params.bookingIds,
312
+ resourceIds: params.resourceIds
283
313
  });
284
314
  if (!options.forceRefresh && this.lastResourcesQueryKey === resourcesKey) {
285
315
  return this.getResourcesOrigin();
@@ -295,9 +325,7 @@ class BookingContextModule extends _BaseModule.BaseModule {
295
325
  if (!pending) {
296
326
  const requestPromise = (async () => {
297
327
  try {
298
- const res = await this.request.get('/schedule/resource/list', {
299
- date
300
- }, RESOURCE_LIST_CACHE);
328
+ const res = await this.request.get('/schedule/resource/list', query, RESOURCE_LIST_CACHE);
301
329
  const {
302
330
  list
303
331
  } = (0, _formatResourceList.formatResourceListAndMap)(res?.data, params.bookingIds || []);
@@ -323,7 +351,9 @@ class BookingContextModule extends _BaseModule.BaseModule {
323
351
  const configKey = resolveBookingConfigRequest(this.otherParams?.platform, params.bookingConfigParams).key;
324
352
  const dateInput = params.date ?? this.store.date ?? (0, _dayjs.default)();
325
353
  const queryDate = toScheduleQueryDate(dateInput);
326
- const resourcesKey = buildBookingResourcesQueryKey({
354
+ const {
355
+ key: resourcesKey
356
+ } = resolveBookingResourcesRequest(this.otherParams?.platform, {
327
357
  date: queryDate,
328
358
  bookingIds: params.bookingIds
329
359
  });
@@ -339,7 +369,9 @@ class BookingContextModule extends _BaseModule.BaseModule {
339
369
  return this.getState();
340
370
  }
341
371
  const configKey = resolveBookingConfigRequest(this.otherParams?.platform, params.bookingConfigParams).key;
342
- const resourcesKey = buildBookingResourcesQueryKey({
372
+ const {
373
+ key: resourcesKey
374
+ } = resolveBookingResourcesRequest(this.otherParams?.platform, {
343
375
  date: queryDate,
344
376
  bookingIds: params.bookingIds
345
377
  });
@@ -22,6 +22,8 @@ export interface LoadBookingConfigParams {
22
22
  export interface LoadBookingResourcesParams {
23
23
  /** 查询日期,`YYYY-MM-DD`;缺省用 store 内已 set 的 date,再缺省为当天。 */
24
24
  date?: string;
25
+ /** 用户端查询的资源 ID;PC/H5 资源接口需要显式范围才会返回对应实体。 */
26
+ resourceIds?: Array<number | string>;
25
27
  /** 编辑态排除容量占用用的 booking id 列表。 */
26
28
  bookingIds?: number[];
27
29
  }
@@ -1,11 +1,11 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { OrderModuleAPI, CommitOrderParams, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, CancelOrderParams, ChangeBookingStatusParams, CheckoutOrderParams } from './types';
3
+ import { OrderModuleAPI, CommitOrderParams, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductsOptions, UpdateOrderProductQuantityParams, CancelOrderParams, ChangeBookingStatusParams, CheckoutOrderParams } from './types';
4
4
  import { CartItem } from '../Cart/types';
5
5
  import { type SubmitPayloadEnhancer } from './utils';
6
6
  import { type PickupTimingBooking, type PickupTimingBookingInput } from './pickupTiming';
7
7
  import { type ProductVoucherGroup } from './utils/productVoucherGroups';
8
- import type { OrderAmountSnapshot, AddProductBookingInput, AddProductToOrderOptions, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, OrderPaymentUpdateOptions, OrderPaymentUpdateResult, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView, OrderHooksConfig, OrderCartIntentCommitContext, ReplaceTempOrderOptions, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions, RemoveProductsFromOrderOptions, SalesNote, SalesNotesMutationSnapshot, SetSalesNoteInput, PickupReferenceMode, PointCardSnapshotMergeContext, PointCardSnapshotItem, ShopServiceData, ShopServiceType } from './types';
8
+ import type { OrderAmountSnapshot, AddProductBookingInput, AddProductToOrderOptions, ReplaceBookingProductWithRelatedRetailParams, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, OrderPaymentUpdateOptions, OrderPaymentUpdateResult, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView, OrderHooksConfig, OrderCartIntentCommitContext, ReplaceTempOrderOptions, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions, RemoveProductsFromOrderOptions, SalesNote, SalesNotesMutationSnapshot, SetSalesNoteInput, PickupReferenceMode, PointCardSnapshotMergeContext, PointCardSnapshotItem, ShopServiceData, ShopServiceType } from './types';
9
9
  import type { ICustomer } from '../AccountList/types';
10
10
  import type { Discount } from '../Discount/types';
11
11
  import { UnavailableReason } from '../Rules/types';
@@ -347,6 +347,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
347
347
  private applyOrderProductsDepositSummary;
348
348
  recalculateSummary(options?: {
349
349
  createIfMissing?: boolean;
350
+ isCurrentOrder?: () => boolean;
350
351
  }): Promise<OrderSummary | null>;
351
352
  getOrderSummary(): Promise<OrderSummary>;
352
353
  updateTempOrderNote(note: string): string;
@@ -497,6 +498,13 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
497
498
  */
498
499
  addProductToOrder(product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions): Promise<OrderProduct[]>;
499
500
  private addProductToOrderDraft;
501
+ /**
502
+ * Replaces one local Party booking and its confirmed children on a detached draft.
503
+ * All fallible preparation precedes a guarded synchronous publication; never rolls
504
+ * an old whole-order snapshot over concurrent edits or a newly selected order.
505
+ */
506
+ replaceBookingProductWithRelatedRetail(params: ReplaceBookingProductWithRelatedRetailParams): Promise<OrderProduct[]>;
507
+ private replaceBookingProductWithRelatedRetailDraft;
500
508
  /**
501
509
  * 批量添加商品行,所有行追加完成后只触发一次促销、折扣、summary 重算与持久化。
502
510
  *
@@ -525,8 +533,9 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
525
533
  private applyOrderProductUpdateToTempOrder;
526
534
  updateOrderProduct(params: UpdateOrderProductParams): Promise<OrderProduct[]>;
527
535
  private updateOrderProductDraft;
528
- updateOrderProducts(paramsList: UpdateOrderProductParams[]): Promise<OrderProduct[]>;
536
+ updateOrderProducts(paramsList: UpdateOrderProductParams[], options?: UpdateOrderProductsOptions): Promise<OrderProduct[]>;
529
537
  private updateOrderProductsDraft;
538
+ private updateOrderProductsGuarded;
530
539
  updateOrderProductQuantity(params: UpdateOrderProductQuantityParams): Promise<OrderProduct[]>;
531
540
  private updateOrderProductQuantityDraft;
532
541
  updateOrderBooking(params: UpdateOrderBookingParams): any[];
@@ -692,6 +701,6 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
692
701
  getOrderInfo(order_id: number): Promise<any>;
693
702
  getVouchers(): any[];
694
703
  }
695
- export type { OrderHolderRelation, AddProductToOrderOptions, OrderMetaList, PointCardSnapshotItem, VirtualCurrencySnapshotItem, RemoveProductsFromOrderOptions, SalesNote, SalesNoteDraftInput, SalesNoteLocalizedSelection, SalesNoteLocalizedText, SalesNoteRelation, SalesNoteTextInput, SetSalesNoteInput, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, } from './types';
704
+ export type { OrderHolderRelation, AddProductToOrderOptions, OrderMetaList, PointCardSnapshotItem, VirtualCurrencySnapshotItem, RemoveProductsFromOrderOptions, SalesNote, SalesNoteDraftInput, SalesNoteLocalizedSelection, SalesNoteLocalizedText, SalesNoteRelation, SalesNoteTextInput, SetSalesNoteInput, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductsOptions, UpdateOrderProductQuantityParams, } from './types';
696
705
  export { isFulfillmentTimingBooking } from './pickupTiming';
697
706
  export type { PickupTimingBooking, PickupTimingBookingInput, PickupTimingBookingMetadata, PickupTimingSelectionMode, PickupTimingSource, } from './pickupTiming';