@pisell/pisellos 2.3.197 → 2.3.199

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/modules/Date/index.d.ts +1 -1
  2. package/dist/modules/Date/index.js +60 -14
  3. package/dist/modules/Date/types.d.ts +5 -0
  4. package/dist/modules/Schedule/index.d.ts +7 -1
  5. package/dist/modules/Schedule/index.js +155 -39
  6. package/dist/modules/Schedule/types.d.ts +2 -0
  7. package/dist/modules/bookingReadValidation.d.ts +6 -0
  8. package/dist/modules/bookingReadValidation.js +72 -0
  9. package/dist/plugins/request.d.ts +2 -0
  10. package/dist/shared/receipt/small-ticket.d.ts +1 -0
  11. package/dist/shared/receipt/small-ticket.js +4 -1
  12. package/dist/solution/BookingByStep/index.d.ts +17 -3
  13. package/dist/solution/BookingByStep/index.js +666 -356
  14. package/dist/solution/BookingTicket/index.d.ts +14 -2
  15. package/dist/solution/OrderInvoicePreview/index.js +4 -3
  16. package/lib/modules/Date/index.d.ts +1 -1
  17. package/lib/modules/Date/index.js +28 -5
  18. package/lib/modules/Date/types.d.ts +5 -0
  19. package/lib/modules/Schedule/index.d.ts +7 -1
  20. package/lib/modules/Schedule/index.js +68 -4
  21. package/lib/modules/Schedule/types.d.ts +2 -0
  22. package/lib/modules/bookingReadValidation.d.ts +6 -0
  23. package/lib/modules/bookingReadValidation.js +56 -0
  24. package/lib/plugins/request.d.ts +2 -0
  25. package/lib/shared/receipt/small-ticket.d.ts +1 -0
  26. package/lib/shared/receipt/small-ticket.js +4 -1
  27. package/lib/solution/BookingByStep/index.d.ts +17 -3
  28. package/lib/solution/BookingByStep/index.js +212 -12
  29. package/lib/solution/BookingTicket/index.d.ts +14 -2
  30. package/lib/solution/OrderInvoicePreview/index.js +1 -0
  31. package/package.json +1 -1
@@ -15,7 +15,7 @@ export declare class DateModule extends BaseModule implements Module, DateModule
15
15
  getDateRange(): ITime[];
16
16
  getResourceDates(params: IGetAvailableTimeListParams): Promise<ITime[]>;
17
17
  getDateList(): ITime[];
18
- setDateList(dateList: ITime[]): void;
18
+ setDateList(dateList: ITime[], replaceDates?: boolean): void;
19
19
  fetchResourceDates(params: IGetAvailableTimeListParams): Promise<any>;
20
20
  /**
21
21
  * 将时间向上取整到下一个10分钟整数
@@ -27,6 +27,7 @@ import dayjs from 'dayjs';
27
27
  import { BaseModule } from "../BaseModule";
28
28
  import { disableAllDates, generateMonthDates, handleAvailableDateByResource, handleAvailableDatesByRules } from "./utils";
29
29
  import cloneDeep from 'lodash-es/cloneDeep';
30
+ import { isBookingResourceList } from "../bookingReadValidation";
30
31
  export var DateModule = /*#__PURE__*/function (_BaseModule) {
31
32
  _inherits(DateModule, _BaseModule);
32
33
  var _super = _createSuper(DateModule);
@@ -104,11 +105,12 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
104
105
  key: "getResourceDates",
105
106
  value: function () {
106
107
  var _getResourceDates = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
107
- var _params$query, currentDateList, currentDateListMap, resourceIds, hasResource, dates;
108
+ var _params$assertCurrent2;
109
+ var _params$query, currentDateList, currentDateListMap, resourceIds, hasResource, dates, _params$assertCurrent;
108
110
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
109
111
  while (1) switch (_context2.prev = _context2.next) {
110
112
  case 0:
111
- if (!params.useCache) {
113
+ if (!(params.useCache && params.errorMode !== 'throw')) {
112
114
  _context2.next = 7;
113
115
  break;
114
116
  }
@@ -131,17 +133,27 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
131
133
  }
132
134
  return _context2.abrupt("return", currentDateList);
133
135
  case 7:
134
- _context2.next = 9;
136
+ _context2.prev = 7;
137
+ _context2.next = 10;
135
138
  return this.getResourceAvailableTimeList(params);
136
- case 9:
139
+ case 10:
137
140
  dates = _context2.sent;
138
- this.setDateList(dates);
141
+ _context2.next = 17;
142
+ break;
143
+ case 13:
144
+ _context2.prev = 13;
145
+ _context2.t0 = _context2["catch"](7);
146
+ (_params$assertCurrent = params.assertCurrent) === null || _params$assertCurrent === void 0 || _params$assertCurrent.call(params);
147
+ throw _context2.t0;
148
+ case 17:
149
+ (_params$assertCurrent2 = params.assertCurrent) === null || _params$assertCurrent2 === void 0 || _params$assertCurrent2.call(params);
150
+ this.setDateList(dates, params.errorMode === 'throw');
139
151
  return _context2.abrupt("return", dates);
140
- case 12:
152
+ case 20:
141
153
  case "end":
142
154
  return _context2.stop();
143
155
  }
144
- }, _callee2, this);
156
+ }, _callee2, this, [[7, 13]]);
145
157
  }));
146
158
  function getResourceDates(_x3) {
147
159
  return _getResourceDates.apply(this, arguments);
@@ -156,6 +168,16 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
156
168
  }, {
157
169
  key: "setDateList",
158
170
  value: function setDateList(dateList) {
171
+ var replaceDates = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
172
+ if (replaceDates) {
173
+ var incoming = new Map(dateList.map(function (date) {
174
+ return [date.date, date];
175
+ }));
176
+ this.store.dateList = [].concat(_toConsumableArray((this.store.dateList || []).filter(function (date) {
177
+ return !incoming.has(date.date);
178
+ })), _toConsumableArray(cloneDeep(dateList)));
179
+ return;
180
+ }
159
181
  // this.store.dateList = dateList;
160
182
  // 并不能直接简单的进行复制
161
183
  // 我们需要把每一天的资源都进行一个合并
@@ -210,25 +232,43 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
210
232
  end_date: end_date,
211
233
  resource_ids: resource_ids,
212
234
  front_end_cache_id: useCache && this.cacheId
213
- }, {
235
+ }, _objectSpread({
214
236
  useCache: useCache
215
- });
237
+ }, params.bookingRead ? {
238
+ bookingRead: true
239
+ } : {}));
216
240
  case 6:
217
241
  res = _context3.sent;
242
+ if (!(params.errorMode === 'throw')) {
243
+ _context3.next = 10;
244
+ break;
245
+ }
246
+ if (!(!res || res.code !== undefined && Number(res.code) !== 200 || res.status === false || res.success === false || typeof res.status === 'number' && res.status >= 400 || !isBookingResourceList(res.data))) {
247
+ _context3.next = 10;
248
+ break;
249
+ }
250
+ throw new Error((res === null || res === void 0 ? void 0 : res.message) || 'Invalid booking resource response');
251
+ case 10:
218
252
  // 校正资源时间段数据
219
253
  if (res !== null && res !== void 0 && res.data && Array.isArray(res.data)) {
220
254
  res.data = this.correctResourceTimeSlots(res.data);
221
255
  }
222
256
  return _context3.abrupt("return", res);
223
- case 11:
224
- _context3.prev = 11;
257
+ case 14:
258
+ _context3.prev = 14;
225
259
  _context3.t0 = _context3["catch"](3);
260
+ if (!(params.errorMode === 'throw')) {
261
+ _context3.next = 18;
262
+ break;
263
+ }
264
+ throw _context3.t0;
265
+ case 18:
226
266
  console.error(_context3.t0);
227
- case 14:
267
+ case 19:
228
268
  case "end":
229
269
  return _context3.stop();
230
270
  }
231
- }, _callee3, this, [[3, 11]]);
271
+ }, _callee3, this, [[3, 14]]);
232
272
  }));
233
273
  function fetchResourceDates(_x4) {
234
274
  return _fetchResourceDates.apply(this, arguments);
@@ -363,8 +403,14 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
363
403
  case 18:
364
404
  _context4.prev = 18;
365
405
  _context4.t0 = _context4["catch"](7);
406
+ if (!(params.errorMode === 'throw')) {
407
+ _context4.next = 22;
408
+ break;
409
+ }
410
+ throw _context4.t0;
411
+ case 22:
366
412
  return _context4.abrupt("return", disableAllDates(dates));
367
- case 21:
413
+ case 23:
368
414
  case "end":
369
415
  return _context4.stop();
370
416
  }
@@ -44,6 +44,11 @@ export interface DateModuleAPI {
44
44
  getResourceDates: (params: IGetAvailableTimeListParams) => Promise<ITime[]>;
45
45
  }
46
46
  export interface IGetAvailableTimeListParams {
47
+ /** BookingByStep opts in; existing solutions retain unavailable-on-error behavior. */
48
+ errorMode?: 'unavailable' | 'throw';
49
+ bookingRead?: boolean;
50
+ /** Check the selection is still current before committing a response. */
51
+ assertCurrent?: () => void;
47
52
  url?: string;
48
53
  /** 是否使用缓存 */
49
54
  useCache?: boolean;
@@ -14,6 +14,9 @@ export declare class ScheduleModule extends BaseModule implements Module, Schedu
14
14
  private scheduleListRequestVersion;
15
15
  private scheduleCatalogScope;
16
16
  private otherParams;
17
+ private catalogVersion;
18
+ private destroyed;
19
+ private availabilityRequestVersion;
17
20
  constructor(name?: string, version?: string);
18
21
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
19
22
  /**
@@ -34,12 +37,15 @@ export declare class ScheduleModule extends BaseModule implements Module, Schedu
34
37
  loadAllSchedule(options?: {
35
38
  useCache?: boolean;
36
39
  }): Promise<void>;
40
+ getScheduleCatalogVersion(): number;
41
+ /** Resolve only after the current scope has a successful catalog. */
42
+ ensureScheduleReady(): Promise<void>;
37
43
  private loadScheduleCatalog;
38
44
  setScheduleList(list: ScheduleItem[]): void;
39
45
  private syncScheduleMap;
40
46
  getScheduleList(): ScheduleItem[];
41
47
  isScheduleListLoaded(): boolean;
42
- loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, }: LoadScheduleAvailableDateParams): Promise<import("../Date/types").ITime[]>;
48
+ loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, assertCurrent, }: LoadScheduleAvailableDateParams): Promise<import("../Date/types").ITime[]>;
43
49
  getScheduleListByIds(ids: number[]): ScheduleItem[];
44
50
  setAvailabilityScheduleDateList(list: ScheduleAvailabilityDateItem[]): void;
45
51
  getAvailabilityScheduleDateList(): ScheduleAvailabilityDateItem[];
@@ -30,6 +30,7 @@ import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
30
30
  import { generateMonthDates, disableAllDates, disableDatesBeforeOneDay } from "../Date/utils";
31
31
  import { calcScheduleDateRange } from "./utils";
32
32
  import { getDateIsInSchedule } from "./getDateIsInSchedule";
33
+ import { isBookingAvailabilityData, isBookingScheduleList } from "../bookingReadValidation";
33
34
  dayjs.extend(isSameOrBefore);
34
35
  dayjs.extend(isSameOrAfter);
35
36
  export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
@@ -51,31 +52,35 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
51
52
  _defineProperty(_assertThisInitialized(_this), "scheduleListRequestVersion", 0);
52
53
  _defineProperty(_assertThisInitialized(_this), "scheduleCatalogScope", '');
53
54
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
55
+ _defineProperty(_assertThisInitialized(_this), "catalogVersion", 0);
56
+ _defineProperty(_assertThisInitialized(_this), "destroyed", false);
57
+ _defineProperty(_assertThisInitialized(_this), "availabilityRequestVersion", 0);
54
58
  return _this;
55
59
  }
56
60
  _createClass(ScheduleModule, [{
57
61
  key: "initialize",
58
62
  value: function () {
59
63
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
60
- var _options$initialState;
64
+ var _options$initialState, _options$otherParams;
61
65
  var initialScheduleList, hasInitialScheduleList;
62
66
  return _regeneratorRuntime().wrap(function _callee$(_context) {
63
67
  while (1) switch (_context.prev = _context.next) {
64
68
  case 0:
65
69
  // The store proxies initialState, so capture its input before resets write through it.
66
70
  initialScheduleList = (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.scheduleList;
67
- hasInitialScheduleList = Array.isArray(initialScheduleList);
71
+ hasInitialScheduleList = ((_options$otherParams = options.otherParams) === null || _options$otherParams === void 0 ? void 0 : _options$otherParams.scheduleCatalogCache) !== 'memory' && Array.isArray(initialScheduleList);
72
+ this.destroyed = false;
68
73
  this.resetScheduleCatalog();
69
74
  this.core = core;
70
75
 
71
76
  // 获取依赖的插件
72
77
  this.request = core.getPlugin('request');
73
78
  if (this.request) {
74
- _context.next = 7;
79
+ _context.next = 8;
75
80
  break;
76
81
  }
77
82
  throw new Error('ScheduleModule 需要 request 插件支持');
78
- case 7:
83
+ case 8:
79
84
  // if (options?.initialState) {
80
85
  // this.state = { ...this.state, ...options.initialState }
81
86
  // }
@@ -92,7 +97,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
92
97
  this.store.availabilityDateList = [];
93
98
  this.hasLoadedScheduleList = false;
94
99
  }
95
- case 10:
100
+ case 11:
96
101
  case "end":
97
102
  return _context.stop();
98
103
  }
@@ -138,6 +143,8 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
138
143
  }, {
139
144
  key: "resetScheduleCatalog",
140
145
  value: function resetScheduleCatalog() {
146
+ this.catalogVersion += 1;
147
+ this.availabilityRequestVersion += 1;
141
148
  this.scheduleListRequestVersion += 1;
142
149
  this.scheduleListPromise = null;
143
150
  this.hasLoadedScheduleList = false;
@@ -147,6 +154,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
147
154
  }, {
148
155
  key: "destroy",
149
156
  value: function destroy() {
157
+ this.destroyed = true;
150
158
  this.resetScheduleCatalog();
151
159
  _get(_getPrototypeOf(ScheduleModule.prototype), "destroy", this).call(this);
152
160
  }
@@ -212,37 +220,116 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
212
220
  return loadAllSchedule;
213
221
  }())
214
222
  }, {
215
- key: "loadScheduleCatalog",
216
- value: function () {
217
- var _loadScheduleCatalog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(useCache, requestVersion) {
218
- var response, _response$data;
223
+ key: "getScheduleCatalogVersion",
224
+ value: function getScheduleCatalogVersion() {
225
+ this.syncScheduleCatalogScope();
226
+ return this.catalogVersion;
227
+ }
228
+
229
+ /** Resolve only after the current scope has a successful catalog. */
230
+ }, {
231
+ key: "ensureScheduleReady",
232
+ value: (function () {
233
+ var _ensureScheduleReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
234
+ var scope;
219
235
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
220
236
  while (1) switch (_context3.prev = _context3.next) {
221
237
  case 0:
222
- _context3.next = 2;
238
+ if (this.destroyed) {
239
+ _context3.next = 20;
240
+ break;
241
+ }
242
+ this.syncScheduleCatalogScope();
243
+ scope = this.scheduleCatalogScope;
244
+ _context3.prev = 3;
245
+ _context3.next = 6;
246
+ return this.loadAllSchedule();
247
+ case 6:
248
+ _context3.next = 15;
249
+ break;
250
+ case 8:
251
+ _context3.prev = 8;
252
+ _context3.t0 = _context3["catch"](3);
253
+ if (!this.destroyed) {
254
+ _context3.next = 12;
255
+ break;
256
+ }
257
+ throw Object.assign(new Error('Schedule catalog was closed'), {
258
+ name: 'AbortError'
259
+ });
260
+ case 12:
261
+ this.syncScheduleCatalogScope();
262
+ if (!(scope === this.scheduleCatalogScope)) {
263
+ _context3.next = 15;
264
+ break;
265
+ }
266
+ throw _context3.t0;
267
+ case 15:
268
+ this.syncScheduleCatalogScope();
269
+ if (!(!this.destroyed && this.hasLoadedScheduleList && !this.scheduleListPromise)) {
270
+ _context3.next = 18;
271
+ break;
272
+ }
273
+ return _context3.abrupt("return");
274
+ case 18:
275
+ _context3.next = 0;
276
+ break;
277
+ case 20:
278
+ throw Object.assign(new Error('Schedule catalog was closed'), {
279
+ name: 'AbortError'
280
+ });
281
+ case 21:
282
+ case "end":
283
+ return _context3.stop();
284
+ }
285
+ }, _callee3, this, [[3, 8]]);
286
+ }));
287
+ function ensureScheduleReady() {
288
+ return _ensureScheduleReady.apply(this, arguments);
289
+ }
290
+ return ensureScheduleReady;
291
+ }())
292
+ }, {
293
+ key: "loadScheduleCatalog",
294
+ value: function () {
295
+ var _loadScheduleCatalog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(useCache, requestVersion) {
296
+ var _response$data;
297
+ var response, _response$data2;
298
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
299
+ while (1) switch (_context4.prev = _context4.next) {
300
+ case 0:
301
+ _context4.next = 2;
223
302
  return this.request.get("/schedule", {
224
303
  num: 999
225
- }, {
226
- useCache: useCache
227
- });
304
+ }, _objectSpread({
305
+ useCache: this.otherParams.scheduleCatalogCache === 'memory' ? false : useCache
306
+ }, this.otherParams.bookingRead ? {
307
+ bookingRead: true
308
+ } : {}));
228
309
  case 2:
229
- response = _context3.sent;
310
+ response = _context4.sent;
230
311
  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;
312
+ _context4.next = 5;
232
313
  break;
233
314
  }
234
315
  throw new Error(response.message || 'Schedule catalog request failed');
235
316
  case 5:
317
+ if (!((this.otherParams.bookingRead || this.otherParams.scheduleCatalogCache === 'memory') && !isBookingScheduleList(response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list))) {
318
+ _context4.next = 7;
319
+ break;
320
+ }
321
+ throw new Error('Invalid schedule catalog response');
322
+ case 7:
236
323
  this.syncScheduleCatalogScope();
237
324
  // A refresh or a different runtime may have superseded this request.
238
325
  if (requestVersion === this.scheduleListRequestVersion) {
239
- this.setScheduleList(((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list) || []);
326
+ this.setScheduleList(((_response$data2 = response.data) === null || _response$data2 === void 0 ? void 0 : _response$data2.list) || []);
240
327
  }
241
- case 7:
328
+ case 9:
242
329
  case "end":
243
- return _context3.stop();
330
+ return _context4.stop();
244
331
  }
245
- }, _callee3, this);
332
+ }, _callee4, this);
246
333
  }));
247
334
  function loadScheduleCatalog(_x3, _x4) {
248
335
  return _loadScheduleCatalog.apply(this, arguments);
@@ -256,6 +343,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
256
343
  this.store.scheduleList = list;
257
344
  this.syncScheduleMap();
258
345
  this.hasLoadedScheduleList = true;
346
+ this.catalogVersion += 1;
259
347
  }
260
348
  }, {
261
349
  key: "syncScheduleMap",
@@ -279,13 +367,15 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
279
367
  }, {
280
368
  key: "loadScheduleAvailableDate",
281
369
  value: function () {
282
- var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref) {
283
- var startDate, endDate, custom_page_id, channel, dates, res, responseData, dateList, otherProductIds;
284
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
285
- while (1) switch (_context4.prev = _context4.next) {
370
+ var _loadScheduleAvailableDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref) {
371
+ var startDate, endDate, custom_page_id, channel, assertCurrent, requestVersion, scope, dates, res, response, responseData, dateList, otherProductIds;
372
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
373
+ while (1) switch (_context5.prev = _context5.next) {
286
374
  case 0:
287
- startDate = _ref.startDate, endDate = _ref.endDate, custom_page_id = _ref.custom_page_id, channel = _ref.channel;
288
- // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天,需要把 startDate 置为今天
375
+ startDate = _ref.startDate, endDate = _ref.endDate, custom_page_id = _ref.custom_page_id, channel = _ref.channel, assertCurrent = _ref.assertCurrent;
376
+ this.syncScheduleCatalogScope();
377
+ requestVersion = ++this.availabilityRequestVersion;
378
+ scope = this.scheduleCatalogScope; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天,需要把 startDate 置为今天
289
379
  if (dayjs(startDate).isBefore(dayjs(), 'day')) {
290
380
  startDate = dayjs().format('YYYY-MM-DD');
291
381
  }
@@ -294,20 +384,46 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
294
384
  dates = disableAllDates(dates);
295
385
  // 如果 endDate 在今天之前,则不用查接口,直接返回 dates
296
386
  if (!dayjs(endDate).isBefore(dayjs(), 'day')) {
297
- _context4.next = 6;
387
+ _context5.next = 9;
298
388
  break;
299
389
  }
300
- return _context4.abrupt("return", dates);
301
- case 6:
302
- _context4.next = 8;
390
+ return _context5.abrupt("return", dates);
391
+ case 9:
392
+ _context5.next = 11;
303
393
  return this.request.get("/schedule/product/availability/v2", {
304
394
  start_date: startDate,
305
395
  end_date: endDate,
306
396
  custom_page_id: custom_page_id,
307
397
  channel: channel
398
+ }, this.otherParams.bookingRead ? {
399
+ bookingRead: true
400
+ } : undefined).catch(function (error) {
401
+ assertCurrent === null || assertCurrent === void 0 || assertCurrent();
402
+ throw error;
308
403
  });
309
- case 8:
310
- res = _context4.sent;
404
+ case 11:
405
+ res = _context5.sent;
406
+ assertCurrent === null || assertCurrent === void 0 || assertCurrent();
407
+ if (!this.otherParams.bookingRead) {
408
+ _context5.next = 20;
409
+ break;
410
+ }
411
+ response = res;
412
+ if (!(!response || response.code !== undefined && Number(response.code) !== 200 || response.status === false || response.success === false || typeof response.status === 'number' && response.status >= 400 || !isBookingAvailabilityData(response.data))) {
413
+ _context5.next = 17;
414
+ break;
415
+ }
416
+ throw new Error((response === null || response === void 0 ? void 0 : response.message) || 'Invalid schedule availability response');
417
+ case 17:
418
+ this.syncScheduleCatalogScope();
419
+ if (!(this.destroyed || scope !== this.scheduleCatalogScope || requestVersion !== this.availabilityRequestVersion)) {
420
+ _context5.next = 20;
421
+ break;
422
+ }
423
+ throw Object.assign(new Error('Schedule availability context changed'), {
424
+ name: 'AbortError'
425
+ });
426
+ case 20:
311
427
  responseData = res.data || {};
312
428
  dateList = Array.isArray(responseData.date_list) ? responseData.date_list : [];
313
429
  otherProductIds = Array.isArray(responseData.other_product_ids) ? responseData.other_product_ids : [];
@@ -315,11 +431,11 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
315
431
  this.setOtherProductsIds(otherProductIds);
316
432
  // 如果没有schedule或者结束日期在今天之前,则所有日期均不可用
317
433
  if (!(!dateList.length && !otherProductIds.length || dayjs(endDate).isBefore(dayjs(), 'day'))) {
318
- _context4.next = 16;
434
+ _context5.next = 27;
319
435
  break;
320
436
  }
321
- return _context4.abrupt("return", dates);
322
- case 16:
437
+ return _context5.abrupt("return", dates);
438
+ case 27:
323
439
  if (otherProductIds.length) {
324
440
  // 如果后端有返回 other_product_ids ,意味着有 duration 商品,则今天以及今天以后的日期均可用
325
441
  dates.forEach(function (n) {
@@ -336,12 +452,12 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
336
452
  });
337
453
  }
338
454
  dates = disableDatesBeforeOneDay(dates);
339
- return _context4.abrupt("return", dates);
340
- case 19:
455
+ return _context5.abrupt("return", dates);
456
+ case 30:
341
457
  case "end":
342
- return _context4.stop();
458
+ return _context5.stop();
343
459
  }
344
- }, _callee4, this);
460
+ }, _callee5, this);
345
461
  }));
346
462
  function loadScheduleAvailableDate(_x5) {
347
463
  return _loadScheduleAvailableDate.apply(this, arguments);
@@ -397,7 +513,7 @@ export var ScheduleModule = /*#__PURE__*/function (_BaseModule) {
397
513
  cacheId: this.cacheId,
398
514
  fatherModule: this.fatherModule,
399
515
  store: store,
400
- cacheKey: ['scheduleList', 'availabilityDateList', 'otherProductsIds']
516
+ cacheKey: this.otherParams.scheduleCatalogCache === 'memory' ? ['availabilityDateList', 'otherProductsIds'] : ['scheduleList', 'availabilityDateList', 'otherProductsIds']
401
517
  });
402
518
  }
403
519
  }
@@ -15,6 +15,8 @@ export type ScheduleAvailabilityDateItem = {
15
15
  * 加载日程可用日期参数接口
16
16
  */
17
17
  export interface LoadScheduleAvailableDateParams {
18
+ /** Caller lifecycle guard, checked before committing availability. */
19
+ assertCurrent?: () => void;
18
20
  /** 开始日期 */
19
21
  startDate: string;
20
22
  /** 结束日期 */
@@ -0,0 +1,6 @@
1
+ /** Validate only the catalog fields consumed by booking reads, not display metadata. */
2
+ export declare const isBookingScheduleList: (value: unknown) => boolean;
3
+ /** Empty resource/time/event arrays and zero capacity are valid successful results. */
4
+ export declare const isBookingResourceList: (value: unknown) => boolean;
5
+ /** The availability endpoint may return either or both lists. */
6
+ export declare const isBookingAvailabilityData: (value: unknown) => boolean;
@@ -0,0 +1,72 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ 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); }
8
+ import dayjs from 'dayjs';
9
+ var isRecord = function isRecord(value) {
10
+ return value !== null && _typeof(value) === 'object' && !Array.isArray(value);
11
+ };
12
+ var isNumericValue = function isNumericValue(value) {
13
+ return (typeof value === 'number' || typeof value === 'string' && value.trim() !== '') && Number.isFinite(Number(value));
14
+ };
15
+ var isDateValue = function isDateValue(value) {
16
+ if (typeof value !== 'string' || !value.trim() || !dayjs(value).isValid()) return false;
17
+ // dayjs accepts overflowing calendar components; do not turn them into another date.
18
+ var dateParts = /^(\d{4})-(\d{2})-(\d{2})(?:$|[ T])/.exec(value);
19
+ if (!dateParts) return true;
20
+ var _dateParts$map = dateParts.map(Number),
21
+ _dateParts$map2 = _slicedToArray(_dateParts$map, 4),
22
+ year = _dateParts$map2[1],
23
+ month = _dateParts$map2[2],
24
+ date = _dateParts$map2[3];
25
+ var calendarDate = new Date(0);
26
+ calendarDate.setUTCFullYear(year, month - 1, date);
27
+ return calendarDate.getUTCFullYear() === year && calendarDate.getUTCMonth() === month - 1 && calendarDate.getUTCDate() === date;
28
+ };
29
+ var isRecordArray = function isRecordArray(value) {
30
+ return Array.isArray(value) && value.every(isRecord);
31
+ };
32
+
33
+ /** Validate only the catalog fields consumed by booking reads, not display metadata. */
34
+ export var isBookingScheduleList = function isBookingScheduleList(value) {
35
+ return Array.isArray(value) && value.every(function (schedule) {
36
+ if (!isRecord(schedule) || !isNumericValue(schedule.id)) return false;
37
+ if (schedule.type === 'time-slots' && !isRecordArray(schedule.time_slot)) return false;
38
+ if (schedule.type === 'designation' && !isRecord(schedule.designation) && !isRecordArray(schedule.designation)) return false;
39
+ if ((schedule.repeat_type === 'daily' || schedule.repeat_type === 'weekly') && !isRecord(schedule.repeat_rule)) return false;
40
+ if (schedule.repeat_rule !== undefined && schedule.repeat_rule !== null) {
41
+ if (!isRecord(schedule.repeat_rule)) return false;
42
+ var rule = schedule.repeat_rule;
43
+ if (rule.end !== undefined && rule.end !== null && !isRecord(rule.end)) return false;
44
+ for (var _i = 0, _arr = ['excluded_date', 'included_date', 'frequency_date']; _i < _arr.length; _i++) {
45
+ var key = _arr[_i];
46
+ if (rule[key] !== undefined && rule[key] !== null && !Array.isArray(rule[key])) return false;
47
+ }
48
+ }
49
+ return true;
50
+ });
51
+ };
52
+
53
+ /** Empty resource/time/event arrays and zero capacity are valid successful results. */
54
+ export var isBookingResourceList = function isBookingResourceList(value) {
55
+ return Array.isArray(value) && value.every(function (resource) {
56
+ if (!isRecord(resource) || !isNumericValue(resource.id) || !isNumericValue(resource.form_id) || !Array.isArray(resource.times)) return false;
57
+ if (resource.capacity !== undefined && !isNumericValue(resource.capacity)) return false;
58
+ return resource.times.every(function (time) {
59
+ return isRecord(time) && isDateValue(time.start_at) && isDateValue(time.end_at) && (time.event_list === undefined || isRecordArray(time.event_list));
60
+ });
61
+ });
62
+ };
63
+
64
+ /** The availability endpoint may return either or both lists. */
65
+ export var isBookingAvailabilityData = function isBookingAvailabilityData(value) {
66
+ if (!isRecord(value) || value.date_list === undefined && value.other_product_ids === undefined) return false;
67
+ if (value.date_list !== undefined && (!Array.isArray(value.date_list) || !value.date_list.every(function (date) {
68
+ return isRecord(date) && isDateValue(date.date);
69
+ }))) return false;
70
+ if (value.other_product_ids !== undefined && (!Array.isArray(value.other_product_ids) || !value.other_product_ids.every(isNumericValue))) return false;
71
+ return true;
72
+ };
@@ -56,6 +56,8 @@ export interface CacheProps {
56
56
  * 请求配置
57
57
  */
58
58
  export interface RequestOptions {
59
+ /** Opt in to the host's bounded retry policy for booking availability GETs. */
60
+ bookingRead?: boolean;
59
61
  /** Customer-only, credential-free GET /open/document/{id} on picoding. */
60
62
  publicInvoiceDocument?: boolean;
61
63
  /** Route through the host's configured picoding environment. */
@@ -17,6 +17,7 @@ export interface SmallTicketShopInfo {
17
17
  timezone?: string;
18
18
  /** Customer-facing shop domain, supplied by the host shop context. */
19
19
  default_domain?: string;
20
+ private_domain?: string;
20
21
  private_domain_protocol?: string;
21
22
  [key: string]: any;
22
23
  }
@@ -437,7 +437,10 @@ function buildBaseData(params) {
437
437
  } : {});
438
438
  }
439
439
  function buildRewardClaimUrl(shopInfo, shopOrderNumber) {
440
- var domain = typeof shopInfo.default_domain === 'string' ? shopInfo.default_domain.trim() : '';
440
+ var default_domain = typeof shopInfo.default_domain === 'string' ? shopInfo.default_domain.trim() : '';
441
+ var private_domain = typeof shopInfo.private_domain === 'string' ? shopInfo.private_domain.trim() : '';
442
+ // 私有域名优先于默认域名
443
+ var domain = default_domain;
441
444
  var orderNumber = typeof shopOrderNumber === 'string' ? shopOrderNumber.trim() : typeof shopOrderNumber === 'number' && Number.isFinite(shopOrderNumber) ? String(shopOrderNumber) : '';
442
445
  if (!domain || !orderNumber) return undefined;
443
446
  try {