@pisell/pisellos 2.3.129 → 2.3.131

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 (102) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +3 -1
  3. package/dist/modules/BusinessAvailability/index.d.ts +30 -0
  4. package/dist/modules/BusinessAvailability/index.js +204 -0
  5. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  6. package/dist/modules/FulfillmentTiming/index.js +407 -0
  7. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  8. package/dist/modules/FulfillmentTiming/types.js +1 -0
  9. package/dist/modules/OpenData/types.d.ts +8 -0
  10. package/dist/modules/Order/index.d.ts +11 -2
  11. package/dist/modules/Order/index.js +370 -253
  12. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  13. package/dist/modules/Order/pickupTiming.js +53 -0
  14. package/dist/modules/Order/types.d.ts +13 -1
  15. package/dist/modules/Order/utils.js +16 -6
  16. package/dist/modules/Payment/index.js +9 -10
  17. package/dist/modules/Schedule/index.d.ts +8 -0
  18. package/dist/modules/Schedule/index.js +141 -39
  19. package/dist/modules/index.d.ts +1 -0
  20. package/dist/modules/index.js +1 -0
  21. package/dist/plugins/request.d.ts +7 -0
  22. package/dist/server/utils/small-ticket.d.ts +1 -85
  23. package/dist/server/utils/small-ticket.js +2 -2542
  24. package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
  25. package/dist/shared/payment/loadPaymentMethods.js +66 -0
  26. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  27. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +142 -0
  28. package/dist/shared/receipt/small-ticket.d.ts +85 -0
  29. package/dist/shared/receipt/small-ticket.js +2576 -0
  30. package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  31. package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
  32. package/dist/solution/BaseSales/index.d.ts +28 -15
  33. package/dist/solution/BaseSales/index.js +1346 -1101
  34. package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
  35. package/dist/solution/BaseSales/pickupTiming.js +589 -0
  36. package/dist/solution/BaseSales/types.d.ts +11 -0
  37. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  38. package/dist/solution/BookingByStep/index.d.ts +1 -1
  39. package/dist/solution/BookingTicket/index.d.ts +2 -2
  40. package/dist/solution/BookingTicket/index.js +41 -13
  41. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  42. package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
  43. package/dist/solution/OrderInvoicePreview/index.js +269 -0
  44. package/dist/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  45. package/dist/solution/UnifiedBookingSales/businessAvailability.js +292 -0
  46. package/dist/solution/UnifiedBookingSales/index.d.ts +24 -4
  47. package/dist/solution/UnifiedBookingSales/index.js +953 -709
  48. package/dist/solution/UnifiedBookingSales/types.d.ts +2 -0
  49. package/dist/solution/index.d.ts +1 -0
  50. package/dist/solution/index.js +2 -1
  51. package/lib/index.d.ts +2 -0
  52. package/lib/index.js +21 -1
  53. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  54. package/lib/modules/BusinessAvailability/index.d.ts +30 -0
  55. package/lib/modules/BusinessAvailability/index.js +146 -0
  56. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  57. package/lib/modules/FulfillmentTiming/index.js +359 -0
  58. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  59. package/lib/modules/FulfillmentTiming/types.js +5 -0
  60. package/lib/modules/OpenData/types.d.ts +8 -0
  61. package/lib/modules/Order/index.d.ts +11 -2
  62. package/lib/modules/Order/index.js +101 -14
  63. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  64. package/lib/modules/Order/pickupTiming.js +61 -0
  65. package/lib/modules/Order/types.d.ts +13 -1
  66. package/lib/modules/Order/utils.js +12 -4
  67. package/lib/modules/Payment/index.js +3 -4
  68. package/lib/modules/Schedule/index.d.ts +8 -0
  69. package/lib/modules/Schedule/index.js +68 -12
  70. package/lib/modules/index.d.ts +1 -0
  71. package/lib/modules/index.js +11 -0
  72. package/lib/plugins/request.d.ts +7 -0
  73. package/lib/server/utils/small-ticket.d.ts +1 -85
  74. package/lib/server/utils/small-ticket.js +9 -2305
  75. package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
  76. package/lib/shared/payment/loadPaymentMethods.js +40 -0
  77. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  78. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +86 -0
  79. package/lib/shared/receipt/small-ticket.d.ts +85 -0
  80. package/lib/shared/receipt/small-ticket.js +2342 -0
  81. package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  82. package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
  83. package/lib/solution/BaseSales/index.d.ts +28 -15
  84. package/lib/solution/BaseSales/index.js +161 -25
  85. package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
  86. package/lib/solution/BaseSales/pickupTiming.js +269 -0
  87. package/lib/solution/BaseSales/types.d.ts +11 -0
  88. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  89. package/lib/solution/BookingByStep/index.d.ts +1 -1
  90. package/lib/solution/BookingTicket/index.d.ts +2 -2
  91. package/lib/solution/BookingTicket/index.js +37 -4
  92. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  93. package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
  94. package/lib/solution/OrderInvoicePreview/index.js +192 -0
  95. package/lib/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  96. package/lib/solution/UnifiedBookingSales/businessAvailability.js +138 -0
  97. package/lib/solution/UnifiedBookingSales/index.d.ts +24 -4
  98. package/lib/solution/UnifiedBookingSales/index.js +184 -46
  99. package/lib/solution/UnifiedBookingSales/types.d.ts +2 -0
  100. package/lib/solution/index.d.ts +1 -0
  101. package/lib/solution/index.js +11 -0
  102. package/package.json +1 -1
@@ -0,0 +1,46 @@
1
+ export type PickupTimingSelectionMode = 'asap' | 'scheduled';
2
+ export type PickupTimingSource = 'asap' | 'schedule' | 'pos_manual';
3
+ export interface PickupTimingBookingInput {
4
+ mode: PickupTimingSelectionMode;
5
+ source: PickupTimingSource;
6
+ /** Store-local calendar date and minute; the caller validates availability. */
7
+ date: string;
8
+ time: string;
9
+ /** Absolute timestamp disambiguates a repeated local minute at a DST change. */
10
+ instant?: string;
11
+ timezone?: string;
12
+ frozen?: boolean;
13
+ }
14
+ export interface PickupTimingBookingMetadata {
15
+ unique_identification_number: string;
16
+ is_fulfillment_timing: true;
17
+ fulfillment_timing: {
18
+ method: 'pick_up';
19
+ mode: PickupTimingSelectionMode;
20
+ source: PickupTimingSource;
21
+ instant?: string;
22
+ timezone?: string;
23
+ frozen?: boolean;
24
+ };
25
+ [key: string]: any;
26
+ }
27
+ export interface PickupTimingBooking {
28
+ schedule_id: number | string;
29
+ start_date: string;
30
+ end_date: string;
31
+ start_time: string;
32
+ end_time: string;
33
+ select_date: string;
34
+ duration: 0;
35
+ is_all: 0;
36
+ sub_type: 'minutes';
37
+ like_status: string;
38
+ resources: [];
39
+ metadata: PickupTimingBookingMetadata;
40
+ schedule_event_id?: number | string;
41
+ [key: string]: any;
42
+ }
43
+ /** The explicit marker is the only authority; unlinked ordinary bookings remain ordinary. */
44
+ export declare function isFulfillmentTimingBooking(booking: unknown): boolean;
45
+ /** Update an independent pickup appointment without changing its persisted row identity. */
46
+ export declare function buildPickupTimingBooking(input: PickupTimingBookingInput, existing?: Record<string, any> | null): PickupTimingBooking;
@@ -0,0 +1,53 @@
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ import { createUuidV4 } from "./utils/orderCollectionIdentity";
8
+ /** The explicit marker is the only authority; unlinked ordinary bookings remain ordinary. */
9
+ export function isFulfillmentTimingBooking(booking) {
10
+ var _metadata;
11
+ return (booking === null || booking === void 0 || (_metadata = booking.metadata) === null || _metadata === void 0 ? void 0 : _metadata.is_fulfillment_timing) === true;
12
+ }
13
+
14
+ /** Update an independent pickup appointment without changing its persisted row identity. */
15
+ export function buildPickupTimingBooking(input, existing) {
16
+ var booking = _objectSpread({}, existing || {});
17
+ var metadata = _objectSpread({}, booking.metadata || {});
18
+ // A fulfillment appointment never becomes a product/resource/holder purchase line.
19
+ for (var _i = 0, _arr = ['product_uid', 'product', 'holder', 'holder_id', 'collect_pax', 'capacity']; _i < _arr.length; _i++) {
20
+ var _key = _arr[_i];
21
+ delete booking[_key];
22
+ delete metadata[_key];
23
+ }
24
+ delete metadata.booking_uid;
25
+ return _objectSpread(_objectSpread({}, booking), {}, {
26
+ schedule_id: booking.schedule_id || 0,
27
+ start_date: input.date,
28
+ end_date: input.date,
29
+ start_time: input.time,
30
+ end_time: input.time,
31
+ select_date: input.date,
32
+ duration: 0,
33
+ is_all: 0,
34
+ sub_type: 'minutes',
35
+ like_status: booking.like_status || 'common',
36
+ resources: [],
37
+ metadata: _objectSpread(_objectSpread({}, metadata), {}, {
38
+ unique_identification_number: String(metadata.unique_identification_number || createUuidV4()),
39
+ is_fulfillment_timing: true,
40
+ fulfillment_timing: _objectSpread(_objectSpread(_objectSpread({
41
+ method: 'pick_up',
42
+ mode: input.mode,
43
+ source: input.source
44
+ }, input.instant !== undefined ? {
45
+ instant: input.instant
46
+ } : {}), input.timezone !== undefined ? {
47
+ timezone: input.timezone
48
+ } : {}), input.frozen !== undefined ? {
49
+ frozen: input.frozen
50
+ } : {})
51
+ })
52
+ });
53
+ }
@@ -7,9 +7,10 @@ import type { SubmitPayloadEnhancer } from './utils';
7
7
  import type { PaymentItem } from '../Payment/types';
8
8
  import type { ICustomer } from '../AccountList/types';
9
9
  import type { OrderProductDiscountItem } from '../../server/modules/order/types';
10
+ import type { PickupTimingBooking, PickupTimingBookingInput } from './pickupTiming';
10
11
  export type { OrderProductDiscountItem } from '../../server/modules/order/types';
11
12
  export type PickupReferenceMode = 'counter_pickup' | 'table_service';
12
- export type ShopServiceType = 'dine_in' | 'takeaway';
13
+ export type ShopServiceType = 'dine_in' | 'takeaway' | 'pick_up' | 'delivery';
13
14
  export interface ShopServiceData {
14
15
  pickup_reference_mode?: PickupReferenceMode;
15
16
  service_type?: ShopServiceType | '';
@@ -516,7 +517,15 @@ export type OrderProductMergeDecisionResult = boolean | {
516
517
  reason?: string;
517
518
  [key: string]: any;
518
519
  };
520
+ export interface OrderCartIntentCommitContext {
521
+ action: 'add_product' | 'update_product' | 'increase_quantity' | 'scan_promotion';
522
+ tempOrder: OrderTempOrder | null;
523
+ }
519
524
  export interface OrderHooksConfig {
525
+ /** Optional customer-order guard; called synchronously before the first cart write. */
526
+ beforeCartIntentCommit?: (context: OrderCartIntentCommitContext) => void;
527
+ /** Captures tenant/business runtime identity for asynchronous cart intents. */
528
+ getCartIntentScope?: () => unknown;
520
529
  onBeforeMergeProductToOrder?: (context: OrderProductMergeDecisionContext) => OrderProductMergeDecisionResult | Promise<OrderProductMergeDecisionResult>;
521
530
  }
522
531
  /**
@@ -863,6 +872,9 @@ export interface OrderModuleAPI {
863
872
  updateTempOrderCustomer: (customer: UpdateTempOrderCustomerInput) => OrderSnapshot['customer'];
864
873
  updateTempOrderPickupReferenceMode: (mode: PickupReferenceMode) => ShopServiceData;
865
874
  updateTempOrderServiceType: (serviceType: ShopServiceType) => ShopServiceData;
875
+ getPickupTimingBooking: () => PickupTimingBooking | null;
876
+ setPickupTimingBooking: (input: PickupTimingBookingInput) => PickupTimingBooking;
877
+ clearPickupTimingBooking: () => void;
866
878
  updateTempOrderBuzzer: (buzzer: string) => string;
867
879
  updateTempOrderContactsInfo: (contactsInfo: Record<string, any> | null) => Record<string, any> | null;
868
880
  addProductToOrder: (product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions) => Promise<OrderProduct[]>;
@@ -31,6 +31,7 @@ import { getProductHolderConfig } from "../Holder/utils";
31
31
  import { buildProductLineFingerprint, createEmptySummary } from "../../solution/ScanOrder/utils";
32
32
  import { createUuidV4 } from "./utils/orderCollectionIdentity";
33
33
  import { encodeSalesNotes } from "./salesNotes";
34
+ import { isFulfillmentTimingBooking } from "./pickupTiming";
34
35
  dayjs.extend(customParseFormat);
35
36
  var POINT_CARD_SNAPSHOT_TAG = 'point_card';
36
37
  var VIRTUAL_CURRENCY_SNAPSHOT_TAG = 'virtual_currency';
@@ -1266,7 +1267,7 @@ function normalizeSubmitProduct(product) {
1266
1267
  payment_price: formatOptions.virtualSettlementMode ? virtualPrice : (_submitProduct$paymen = submitProduct.payment_price) !== null && _submitProduct$paymen !== void 0 ? _submitProduct$paymen : submitProduct.selling_price
1267
1268
  });
1268
1269
  }
1269
- var SUBMIT_BOOKING_METADATA_WHITELIST = ['unique_identification_number', 'collect_pax', 'capacity', 'holder_id', 'resource_select_type', 'holder'];
1270
+ var SUBMIT_BOOKING_METADATA_WHITELIST = ['unique_identification_number', 'collect_pax', 'capacity', 'holder_id', 'resource_select_type', 'holder', 'is_fulfillment_timing', 'fulfillment_timing'];
1270
1271
  export function normalizeBookingIsAll(booking) {
1271
1272
  return booking.is_all === true || booking.is_all === 1 || booking.is_all === '1' || booking.is_all === 'true' ? 1 : 0;
1272
1273
  }
@@ -1294,16 +1295,22 @@ export function normalizeSubmitBooking(booking) {
1294
1295
  } finally {
1295
1296
  _iterator7.f();
1296
1297
  }
1297
- if (cleanMetadata.holder_id === undefined) cleanMetadata.holder_id = null;
1298
+ if (cleanMetadata.holder_id === undefined && !isFulfillmentTimingBooking(booking)) {
1299
+ cleanMetadata.holder_id = null;
1300
+ }
1298
1301
  var bookingRecord = booking;
1299
1302
  var startDate = bookingRecord.start_date;
1300
1303
  var shouldRestoreSelectDate = bookingRecord.select_date === undefined || bookingRecord.select_date === null || bookingRecord.select_date === '';
1301
1304
  var selectDateFromStartDate = typeof startDate === 'string' ? startDate.split(/\s+/)[0] : startDate;
1302
- return _objectSpread(_objectSpread(_objectSpread({}, booking), shouldRestoreSelectDate && selectDateFromStartDate ? {
1305
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, booking), shouldRestoreSelectDate && selectDateFromStartDate ? {
1303
1306
  select_date: selectDateFromStartDate
1304
1307
  } : {}), {}, {
1305
1308
  is_all: normalizeBookingIsAll(bookingRecord),
1306
- sub_type: normalizeBookingSubType(bookingRecord),
1309
+ sub_type: normalizeBookingSubType(bookingRecord)
1310
+ }, isFulfillmentTimingBooking(booking) ? {
1311
+ like_status: bookingRecord.like_status || 'common',
1312
+ schedule_id: bookingRecord.schedule_id || 0
1313
+ } : {}), {}, {
1307
1314
  metadata: cleanMetadata
1308
1315
  });
1309
1316
  }
@@ -1392,6 +1399,7 @@ function hasBoundBookingResource(bookings) {
1392
1399
  if (!Array.isArray(bookings)) return false;
1393
1400
  return bookings.some(function (booking) {
1394
1401
  if (!booking || _typeof(booking) !== 'object') return false;
1402
+ if (isFulfillmentTimingBooking(booking)) return false;
1395
1403
  if (Number(booking.parent_id) === 0) return false;
1396
1404
  var resources = booking.resources;
1397
1405
  if (!Array.isArray(resources)) return false;
@@ -1426,7 +1434,9 @@ export function resolveSubmitOrderType(params) {
1426
1434
  return 'table-order';
1427
1435
  }
1428
1436
  if (currentType) return currentType;
1429
- if (Array.isArray(bookings) && bookings.length > 0) {
1437
+ if (Array.isArray(bookings) && bookings.some(function (booking) {
1438
+ return !isFulfillmentTimingBooking(booking);
1439
+ })) {
1430
1440
  return businessCode === 'dine_in' ? 'table-order' : 'appointment_booking';
1431
1441
  }
1432
1442
  return 'virtual';
@@ -1510,7 +1520,7 @@ export function buildSubmitPayload(params) {
1510
1520
  schedule_date: scheduleDate,
1511
1521
  // created_at: tempOrder.created_at || formatDateTime(now), 和后端协定这个字段先不提交到接口
1512
1522
  bookings: (tempOrder.bookings || []).filter(function (booking) {
1513
- return Number(booking.parent_id) !== 0;
1523
+ return isFulfillmentTimingBooking(booking) || Number(booking.parent_id) !== 0;
1514
1524
  }).map(function (booking) {
1515
1525
  return normalizeSubmitBooking(booking);
1516
1526
  }),
@@ -20,6 +20,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
20
20
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
21
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
22
22
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ import { loadPaymentMethods } from "../../shared/payment/loadPaymentMethods";
23
24
  import { BaseModule } from "../BaseModule";
24
25
  import { PaymentStatus, PaymentMethodType, RoundingRule } from "./types";
25
26
  import { getUniqueId } from "../Cart/utils";
@@ -363,37 +364,35 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
363
364
  key: "getPayMethodListAsync",
364
365
  value: (function () {
365
366
  var _getPayMethodListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
366
- var response, payMethods;
367
+ var payMethods;
367
368
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
368
369
  while (1) switch (_context3.prev = _context3.next) {
369
370
  case 0:
370
371
  this.logInfo('Starting getPayMethodListAsync');
371
372
  _context3.prev = 1;
372
373
  _context3.next = 4;
373
- return this.request.get('/pay/custom-payment/all', {
374
+ return loadPaymentMethods(this.request, {
375
+ transport: 'os-server',
374
376
  filterPaymentMethods: true
375
- }, {
376
- osServer: true
377
377
  });
378
378
  case 4:
379
- response = _context3.sent;
380
- payMethods = (response === null || response === void 0 ? void 0 : response.data) || response || [];
379
+ payMethods = _context3.sent;
381
380
  this.logInfo('getPayMethodListAsync completed successfully', {
382
381
  payMethods: payMethods
383
382
  });
384
383
  return _context3.abrupt("return", payMethods);
385
- case 10:
386
- _context3.prev = 10;
384
+ case 9:
385
+ _context3.prev = 9;
387
386
  _context3.t0 = _context3["catch"](1);
388
387
  console.error('[PaymentModule] 获取支付方式列表失败', _context3.t0);
389
388
  this.logError('getPayMethodListAsync failed', _context3.t0);
390
389
  // 如果所有操作都失败,返回空数组
391
390
  return _context3.abrupt("return", []);
392
- case 15:
391
+ case 14:
393
392
  case "end":
394
393
  return _context3.stop();
395
394
  }
396
- }, _callee3, this, [[1, 10]]);
395
+ }, _callee3, this, [[1, 9]]);
397
396
  }));
398
397
  function getPayMethodListAsync() {
399
398
  return _getPayMethodListAsync.apply(this, arguments);
@@ -10,6 +10,10 @@ export declare class ScheduleModule extends BaseModule implements Module, Schedu
10
10
  private openCache;
11
11
  private fatherModule;
12
12
  private hasLoadedScheduleList;
13
+ private scheduleListPromise;
14
+ private scheduleListRequestVersion;
15
+ private scheduleCatalogScope;
16
+ private otherParams;
13
17
  constructor(name?: string, version?: string);
14
18
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
15
19
  /**
@@ -19,6 +23,9 @@ export declare class ScheduleModule extends BaseModule implements Module, Schedu
19
23
  * scheduleModule.updateOtherParams({ openCache: true, cacheId: 'cache-2' });
20
24
  */
21
25
  updateOtherParams(params: Record<string, any>): void;
26
+ private syncScheduleCatalogScope;
27
+ private resetScheduleCatalog;
28
+ destroy(): void;
22
29
  /**
23
30
  * 加载当前店铺下所有 schedule
24
31
  *
@@ -27,6 +34,7 @@ export declare class ScheduleModule extends BaseModule implements Module, Schedu
27
34
  loadAllSchedule(options?: {
28
35
  useCache?: boolean;
29
36
  }): Promise<void>;
37
+ private loadScheduleCatalog;
30
38
  setScheduleList(list: ScheduleItem[]): void;
31
39
  private syncScheduleMap;
32
40
  getScheduleList(): ScheduleItem[];
@@ -10,6 +10,8 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
10
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
11
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
12
12
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
14
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
13
15
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
14
16
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
15
17
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -45,49 +47,52 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
45
47
  _defineProperty(_assertThisInitialized(_this), "openCache", false);
46
48
  _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
47
49
  _defineProperty(_assertThisInitialized(_this), "hasLoadedScheduleList", false);
50
+ _defineProperty(_assertThisInitialized(_this), "scheduleListPromise", null);
51
+ _defineProperty(_assertThisInitialized(_this), "scheduleListRequestVersion", 0);
52
+ _defineProperty(_assertThisInitialized(_this), "scheduleCatalogScope", '');
53
+ _defineProperty(_assertThisInitialized(_this), "otherParams", {});
48
54
  return _this;
49
55
  }
50
56
  _createClass(ScheduleModule, [{
51
57
  key: "initialize",
52
58
  value: function () {
53
59
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
54
- var _options$otherParams, _options$otherParams2;
60
+ var _options$initialState;
61
+ var initialScheduleList, hasInitialScheduleList;
55
62
  return _regeneratorRuntime().wrap(function _callee$(_context) {
56
63
  while (1) switch (_context.prev = _context.next) {
57
64
  case 0:
65
+ // The store proxies initialState, so capture its input before resets write through it.
66
+ initialScheduleList = (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.scheduleList;
67
+ hasInitialScheduleList = Array.isArray(initialScheduleList);
68
+ this.resetScheduleCatalog();
58
69
  this.core = core;
59
70
 
60
71
  // 获取依赖的插件
61
72
  this.request = core.getPlugin('request');
62
73
  if (this.request) {
63
- _context.next = 4;
74
+ _context.next = 7;
64
75
  break;
65
76
  }
66
77
  throw new Error('ScheduleModule 需要 request 插件支持');
67
- case 4:
78
+ case 7:
68
79
  // if (options?.initialState) {
69
80
  // this.state = { ...this.state, ...options.initialState }
70
81
  // }
71
82
  this.store = options === null || options === void 0 ? void 0 : options.store;
83
+ this.updateOtherParams(options.otherParams || {});
72
84
  if (options.initialState) {
73
- this.store.scheduleList = options.initialState.scheduleList;
85
+ this.store.scheduleList = hasInitialScheduleList ? initialScheduleList : [];
74
86
  this.syncScheduleMap();
75
87
  this.store.availabilityDateList = options.initialState.availabilityDateList;
76
- this.hasLoadedScheduleList = Array.isArray(options.initialState.scheduleList);
88
+ this.hasLoadedScheduleList = hasInitialScheduleList;
77
89
  } else {
78
90
  this.store.scheduleList = [];
79
91
  this.store.map = new Map();
80
92
  this.store.availabilityDateList = [];
81
93
  this.hasLoadedScheduleList = false;
82
94
  }
83
- if ((_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
84
- this.openCache = options.otherParams.openCache;
85
- this.cacheId = options.otherParams.cacheId;
86
- }
87
- if ((_options$otherParams2 = options.otherParams) !== null && _options$otherParams2 !== void 0 && _options$otherParams2.fatherModule) {
88
- this.fatherModule = options.otherParams.fatherModule;
89
- }
90
- case 8:
95
+ case 10:
91
96
  case "end":
92
97
  return _context.stop();
93
98
  }
@@ -109,9 +114,41 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
109
114
  value: function updateOtherParams(params) {
110
115
  var _otherParams$openCach;
111
116
  var otherParams = params || {};
117
+ this.otherParams = _objectSpread({}, otherParams);
112
118
  this.openCache = (_otherParams$openCach = otherParams.openCache) !== null && _otherParams$openCach !== void 0 ? _otherParams$openCach : false;
113
119
  this.cacheId = otherParams.cacheId;
114
120
  this.fatherModule = otherParams.fatherModule;
121
+ this.syncScheduleCatalogScope();
122
+ }
123
+ }, {
124
+ key: "syncScheduleCatalogScope",
125
+ value: function syncScheduleCatalogScope() {
126
+ var _this$core, _params$businessCode;
127
+ var context = (_this$core = this.core) === null || _this$core === void 0 ? void 0 : _this$core.context;
128
+ var shopId = typeof (context === null || context === void 0 ? void 0 : context.getData) === 'function' ? context.getData('shop_id') : context === null || context === void 0 ? void 0 : context.shop_id;
129
+ var params = this.otherParams;
130
+ var scope = JSON.stringify([this.cacheId, this.fatherModule, (_params$businessCode = params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : params.business_code, params.channel, params.platform, params.businessTimezone, shopId].map(function (value) {
131
+ return String(value !== null && value !== void 0 ? value : '').trim();
132
+ }));
133
+ if (scope !== this.scheduleCatalogScope) {
134
+ this.resetScheduleCatalog();
135
+ this.scheduleCatalogScope = scope;
136
+ }
137
+ }
138
+ }, {
139
+ key: "resetScheduleCatalog",
140
+ value: function resetScheduleCatalog() {
141
+ this.scheduleListRequestVersion += 1;
142
+ this.scheduleListPromise = null;
143
+ this.hasLoadedScheduleList = false;
144
+ this.store.scheduleList = [];
145
+ this.store.map = new Map();
146
+ }
147
+ }, {
148
+ key: "destroy",
149
+ value: function destroy() {
150
+ this.resetScheduleCatalog();
151
+ _get(_getPrototypeOf(ScheduleModule.prototype), "destroy", this).call(this);
115
152
  }
116
153
 
117
154
  /**
@@ -123,37 +160,99 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
123
160
  key: "loadAllSchedule",
124
161
  value: (function () {
125
162
  var _loadAllSchedule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
126
- var _options$useCache, _scheduleList$data;
163
+ var _options$useCache;
127
164
  var options,
128
- scheduleList,
165
+ useCache,
166
+ requestVersion,
167
+ promise,
129
168
  _args2 = arguments;
130
169
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
131
170
  while (1) switch (_context2.prev = _context2.next) {
132
171
  case 0:
133
172
  options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
134
- _context2.next = 3;
135
- return this.request.get("/schedule", {
136
- num: 999
137
- }, {
138
- useCache: (_options$useCache = options.useCache) !== null && _options$useCache !== void 0 ? _options$useCache : true
139
- });
140
- case 3:
141
- scheduleList = _context2.sent;
142
- this.setScheduleList(((_scheduleList$data = scheduleList.data) === null || _scheduleList$data === void 0 ? void 0 : _scheduleList$data.list) || []);
143
- case 5:
173
+ this.syncScheduleCatalogScope();
174
+ useCache = (_options$useCache = options.useCache) !== null && _options$useCache !== void 0 ? _options$useCache : true;
175
+ if (!useCache) {
176
+ _context2.next = 8;
177
+ break;
178
+ }
179
+ if (!this.scheduleListPromise) {
180
+ _context2.next = 6;
181
+ break;
182
+ }
183
+ return _context2.abrupt("return", this.scheduleListPromise);
184
+ case 6:
185
+ if (!this.hasLoadedScheduleList) {
186
+ _context2.next = 8;
187
+ break;
188
+ }
189
+ return _context2.abrupt("return");
190
+ case 8:
191
+ requestVersion = ++this.scheduleListRequestVersion;
192
+ promise = this.loadScheduleCatalog(useCache, requestVersion);
193
+ this.scheduleListPromise = promise;
194
+ _context2.prev = 11;
195
+ _context2.next = 14;
196
+ return promise;
197
+ case 14:
198
+ _context2.prev = 14;
199
+ if (this.scheduleListPromise === promise) {
200
+ this.scheduleListPromise = null;
201
+ }
202
+ return _context2.finish(14);
203
+ case 17:
144
204
  case "end":
145
205
  return _context2.stop();
146
206
  }
147
- }, _callee2, this);
207
+ }, _callee2, this, [[11,, 14, 17]]);
148
208
  }));
149
209
  function loadAllSchedule() {
150
210
  return _loadAllSchedule.apply(this, arguments);
151
211
  }
152
212
  return loadAllSchedule;
153
213
  }())
214
+ }, {
215
+ key: "loadScheduleCatalog",
216
+ value: function () {
217
+ var _loadScheduleCatalog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(useCache, requestVersion) {
218
+ var response, _response$data;
219
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
220
+ while (1) switch (_context3.prev = _context3.next) {
221
+ case 0:
222
+ _context3.next = 2;
223
+ return this.request.get("/schedule", {
224
+ num: 999
225
+ }, {
226
+ useCache: useCache
227
+ });
228
+ case 2:
229
+ response = _context3.sent;
230
+ if (!(response.code !== undefined && Number(response.code) !== 200 || response.status === false || typeof response.status === 'number' && response.status >= 400 || response.success === false)) {
231
+ _context3.next = 5;
232
+ break;
233
+ }
234
+ throw new Error(response.message || 'Schedule catalog request failed');
235
+ case 5:
236
+ this.syncScheduleCatalogScope();
237
+ // A refresh or a different runtime may have superseded this request.
238
+ if (requestVersion === this.scheduleListRequestVersion) {
239
+ this.setScheduleList(((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list) || []);
240
+ }
241
+ case 7:
242
+ case "end":
243
+ return _context3.stop();
244
+ }
245
+ }, _callee3, this);
246
+ }));
247
+ function loadScheduleCatalog(_x3, _x4) {
248
+ return _loadScheduleCatalog.apply(this, arguments);
249
+ }
250
+ return loadScheduleCatalog;
251
+ }()
154
252
  }, {
155
253
  key: "setScheduleList",
156
254
  value: function setScheduleList(list) {
255
+ this.syncScheduleCatalogScope();
157
256
  this.store.scheduleList = list;
158
257
  this.syncScheduleMap();
159
258
  this.hasLoadedScheduleList = true;
@@ -168,20 +267,22 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
168
267
  }, {
169
268
  key: "getScheduleList",
170
269
  value: function getScheduleList() {
270
+ this.syncScheduleCatalogScope();
171
271
  return this.store.scheduleList || [];
172
272
  }
173
273
  }, {
174
274
  key: "isScheduleListLoaded",
175
275
  value: function isScheduleListLoaded() {
276
+ this.syncScheduleCatalogScope();
176
277
  return this.hasLoadedScheduleList;
177
278
  }
178
279
  }, {
179
280
  key: "loadScheduleAvailableDate",
180
281
  value: function () {
181
- var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
282
+ var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref) {
182
283
  var startDate, endDate, custom_page_id, channel, dates, res, responseData, dateList, otherProductIds;
183
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
184
- while (1) switch (_context3.prev = _context3.next) {
284
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
285
+ while (1) switch (_context4.prev = _context4.next) {
185
286
  case 0:
186
287
  startDate = _ref.startDate, endDate = _ref.endDate, custom_page_id = _ref.custom_page_id, channel = _ref.channel;
187
288
  // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天,需要把 startDate 置为今天
@@ -193,12 +294,12 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
193
294
  dates = disableAllDates(dates);
194
295
  // 如果 endDate 在今天之前,则不用查接口,直接返回 dates
195
296
  if (!dayjs(endDate).isBefore(dayjs(), 'day')) {
196
- _context3.next = 6;
297
+ _context4.next = 6;
197
298
  break;
198
299
  }
199
- return _context3.abrupt("return", dates);
300
+ return _context4.abrupt("return", dates);
200
301
  case 6:
201
- _context3.next = 8;
302
+ _context4.next = 8;
202
303
  return this.request.get("/schedule/product/availability/v2", {
203
304
  start_date: startDate,
204
305
  end_date: endDate,
@@ -206,7 +307,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
206
307
  channel: channel
207
308
  });
208
309
  case 8:
209
- res = _context3.sent;
310
+ res = _context4.sent;
210
311
  responseData = res.data || {};
211
312
  dateList = Array.isArray(responseData.date_list) ? responseData.date_list : [];
212
313
  otherProductIds = Array.isArray(responseData.other_product_ids) ? responseData.other_product_ids : [];
@@ -214,10 +315,10 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
214
315
  this.setOtherProductsIds(otherProductIds);
215
316
  // 如果没有schedule或者结束日期在今天之前,则所有日期均不可用
216
317
  if (!(!dateList.length && !otherProductIds.length || dayjs(endDate).isBefore(dayjs(), 'day'))) {
217
- _context3.next = 16;
318
+ _context4.next = 16;
218
319
  break;
219
320
  }
220
- return _context3.abrupt("return", dates);
321
+ return _context4.abrupt("return", dates);
221
322
  case 16:
222
323
  if (otherProductIds.length) {
223
324
  // 如果后端有返回 other_product_ids ,意味着有 duration 商品,则今天以及今天以后的日期均可用
@@ -235,14 +336,14 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
235
336
  });
236
337
  }
237
338
  dates = disableDatesBeforeOneDay(dates);
238
- return _context3.abrupt("return", dates);
339
+ return _context4.abrupt("return", dates);
239
340
  case 19:
240
341
  case "end":
241
- return _context3.stop();
342
+ return _context4.stop();
242
343
  }
243
- }, _callee3, this);
344
+ }, _callee4, this);
244
345
  }));
245
- function loadScheduleAvailableDate(_x3) {
346
+ function loadScheduleAvailableDate(_x5) {
246
347
  return _loadScheduleAvailableDate.apply(this, arguments);
247
348
  }
248
349
  return loadScheduleAvailableDate;
@@ -252,6 +353,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
252
353
  value: function getScheduleListByIds(ids) {
253
354
  var _this2 = this,
254
355
  _this$store$scheduleL;
356
+ this.syncScheduleCatalogScope();
255
357
  var idSet = new Set(ids.map(function (id) {
256
358
  return String(id);
257
359
  }));
@@ -17,6 +17,7 @@ export * from './Schedule';
17
17
  export * from './Quotation';
18
18
  export * from './ScanOrderLogger';
19
19
  export * from './OpenData';
20
+ export * from './FulfillmentTiming';
20
21
  export * from './BookingContext';
21
22
  export * from './Holder';
22
23
  export * from './ResourcePlanner';
@@ -17,6 +17,7 @@ export * from "./Schedule";
17
17
  export * from "./Quotation";
18
18
  export * from "./ScanOrderLogger";
19
19
  export * from "./OpenData";
20
+ export * from "./FulfillmentTiming";
20
21
  export * from "./BookingContext";
21
22
  export * from "./Holder";
22
23
  export * from "./ResourcePlanner";
@@ -56,6 +56,13 @@ export interface CacheProps {
56
56
  * 请求配置
57
57
  */
58
58
  export interface RequestOptions {
59
+ /** Customer-only, credential-free GET /open/document/{id} on picoding. */
60
+ publicInvoiceDocument?: boolean;
61
+ /** Route through the host's configured picoding environment. */
62
+ pisell2?: boolean;
63
+ /** Let the caller handle read-only preview failures without host navigation/toasts. */
64
+ manualErrorHandling?: boolean;
65
+ skipErrorHandler?: boolean;
59
66
  url?: string;
60
67
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
61
68
  headers?: Record<string, string>;