@pisell/pisellos 2.2.178 → 2.2.179

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 (182) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/Customer/index.d.ts +0 -6
  3. package/dist/modules/Customer/index.js +83 -129
  4. package/dist/modules/Customer/types.d.ts +0 -2
  5. package/dist/modules/Discount/index.d.ts +4 -2
  6. package/dist/modules/Discount/index.js +93 -8
  7. package/dist/modules/Discount/types.d.ts +7 -1
  8. package/dist/modules/Order/index.d.ts +18 -88
  9. package/dist/modules/Order/index.js +501 -1357
  10. package/dist/modules/Order/types.d.ts +19 -198
  11. package/dist/modules/Order/types.js +0 -31
  12. package/dist/modules/Order/utils.d.ts +1 -50
  13. package/dist/modules/Order/utils.js +32 -261
  14. package/dist/modules/Quotation/index.d.ts +1 -0
  15. package/dist/modules/Quotation/index.js +21 -23
  16. package/dist/modules/Rules/index.d.ts +0 -4
  17. package/dist/modules/Rules/index.js +10 -26
  18. package/dist/modules/SalesSummary/index.js +2 -4
  19. package/dist/modules/SalesSummary/utils.js +7 -21
  20. package/dist/modules/Schedule/index.js +2 -6
  21. package/dist/modules/index.d.ts +0 -1
  22. package/dist/modules/index.js +1 -2
  23. package/dist/server/index.js +29 -87
  24. package/dist/server/modules/order/index.d.ts +0 -23
  25. package/dist/server/modules/order/index.js +46 -123
  26. package/dist/server/modules/order/types.d.ts +2 -0
  27. package/dist/server/modules/order/utils/filterOrders.js +6 -20
  28. package/dist/server/modules/products/index.d.ts +1 -1
  29. package/dist/server/modules/products/index.js +113 -130
  30. package/dist/server/modules/schedule/index.js +6 -13
  31. package/dist/solution/BaseSales/index.d.ts +7 -89
  32. package/dist/solution/BaseSales/index.js +375 -1494
  33. package/dist/solution/BaseSales/types.d.ts +1 -67
  34. package/dist/solution/BaseSales/types.js +1 -3
  35. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -0
  36. package/dist/solution/BaseSales/utils/parseSalesResponse.js +1 -1
  37. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +16 -68
  38. package/dist/solution/BaseSales/utils.js +8 -46
  39. package/dist/solution/BookingByStep/index.d.ts +1 -1
  40. package/dist/solution/BookingTicket/index.d.ts +1 -133
  41. package/dist/solution/BookingTicket/index.js +175 -780
  42. package/dist/solution/BookingTicket/types.d.ts +0 -2
  43. package/dist/solution/BookingTicket/types.js +0 -3
  44. package/dist/solution/BookingTicket/utils/cartView.js +2 -4
  45. package/dist/solution/ScanOrder/index.d.ts +3 -9
  46. package/dist/solution/ScanOrder/index.js +128 -231
  47. package/dist/solution/ScanOrder/utils.js +8 -46
  48. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  49. package/dist/solution/ShopDiscount/index.js +23 -18
  50. package/dist/solution/VenueBooking/index.d.ts +9 -5
  51. package/dist/solution/VenueBooking/index.js +55 -103
  52. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  53. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
  54. package/lib/modules/Customer/index.d.ts +0 -6
  55. package/lib/modules/Customer/index.js +11 -26
  56. package/lib/modules/Customer/types.d.ts +0 -2
  57. package/lib/modules/Discount/index.d.ts +4 -2
  58. package/lib/modules/Discount/index.js +63 -8
  59. package/lib/modules/Discount/types.d.ts +7 -1
  60. package/lib/modules/Order/index.d.ts +18 -88
  61. package/lib/modules/Order/index.js +149 -677
  62. package/lib/modules/Order/types.d.ts +19 -198
  63. package/lib/modules/Order/types.js +0 -1
  64. package/lib/modules/Order/utils.d.ts +1 -50
  65. package/lib/modules/Order/utils.js +22 -229
  66. package/lib/modules/Quotation/index.d.ts +1 -0
  67. package/lib/modules/Quotation/index.js +15 -18
  68. package/lib/modules/Rules/index.d.ts +0 -4
  69. package/lib/modules/Rules/index.js +14 -22
  70. package/lib/modules/SalesSummary/index.js +2 -4
  71. package/lib/modules/SalesSummary/utils.js +7 -21
  72. package/lib/modules/Schedule/index.js +1 -3
  73. package/lib/modules/index.d.ts +0 -1
  74. package/lib/modules/index.js +1 -3
  75. package/lib/server/index.js +4 -41
  76. package/lib/server/modules/order/index.d.ts +0 -23
  77. package/lib/server/modules/order/index.js +14 -46
  78. package/lib/server/modules/order/types.d.ts +2 -0
  79. package/lib/server/modules/order/utils/filterOrders.js +4 -12
  80. package/lib/server/modules/products/index.d.ts +1 -1
  81. package/lib/server/modules/products/index.js +20 -30
  82. package/lib/server/modules/schedule/index.js +1 -2
  83. package/lib/solution/BaseSales/index.d.ts +7 -89
  84. package/lib/solution/BaseSales/index.js +22 -736
  85. package/lib/solution/BaseSales/types.d.ts +1 -67
  86. package/lib/solution/BaseSales/types.js +1 -3
  87. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -0
  88. package/lib/solution/BaseSales/utils/parseSalesResponse.js +1 -0
  89. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +12 -71
  90. package/lib/solution/BaseSales/utils.js +6 -46
  91. package/lib/solution/BookingByStep/index.d.ts +1 -1
  92. package/lib/solution/BookingTicket/index.d.ts +1 -133
  93. package/lib/solution/BookingTicket/index.js +8 -352
  94. package/lib/solution/BookingTicket/types.d.ts +0 -2
  95. package/lib/solution/BookingTicket/types.js +0 -6
  96. package/lib/solution/BookingTicket/utils/cartView.js +2 -4
  97. package/lib/solution/ScanOrder/index.d.ts +3 -9
  98. package/lib/solution/ScanOrder/index.js +66 -147
  99. package/lib/solution/ScanOrder/utils.js +6 -46
  100. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  101. package/lib/solution/ShopDiscount/index.js +4 -2
  102. package/lib/solution/VenueBooking/index.d.ts +9 -5
  103. package/lib/solution/VenueBooking/index.js +14 -50
  104. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  105. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
  106. package/package.json +2 -2
  107. package/dist/modules/BookingContext/index.d.ts +0 -37
  108. package/dist/modules/BookingContext/index.js +0 -436
  109. package/dist/modules/BookingContext/types.d.ts +0 -102
  110. package/dist/modules/BookingContext/types.js +0 -51
  111. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  112. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -193
  113. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  114. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -137
  115. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  116. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -215
  117. package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
  118. package/dist/modules/BookingContext/utils/flexible.js +0 -56
  119. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  120. package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
  121. package/dist/modules/BookingContext/utils/index.d.ts +0 -11
  122. package/dist/modules/BookingContext/utils/index.js +0 -11
  123. package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
  124. package/dist/modules/BookingContext/utils/noResource.js +0 -77
  125. package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
  126. package/dist/modules/BookingContext/utils/productExtend.js +0 -339
  127. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  128. package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
  129. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  130. package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
  131. package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
  132. package/dist/modules/BookingContext/utils/resources.js +0 -486
  133. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  134. package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
  135. package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  136. package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
  137. package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  138. package/dist/modules/Order/utils/manualProductDiscount.js +0 -212
  139. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +0 -275
  140. package/dist/solution/BaseSales/utils/cartPromotion.js +0 -1258
  141. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  142. package/dist/solution/BaseSales/utils/quotationPrice.js +0 -237
  143. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  144. package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
  145. package/lib/modules/BookingContext/index.d.ts +0 -37
  146. package/lib/modules/BookingContext/index.js +0 -297
  147. package/lib/modules/BookingContext/types.d.ts +0 -102
  148. package/lib/modules/BookingContext/types.js +0 -34
  149. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  150. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -207
  151. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  152. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -141
  153. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  154. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -198
  155. package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
  156. package/lib/modules/BookingContext/utils/flexible.js +0 -80
  157. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  158. package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
  159. package/lib/modules/BookingContext/utils/index.d.ts +0 -11
  160. package/lib/modules/BookingContext/utils/index.js +0 -43
  161. package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
  162. package/lib/modules/BookingContext/utils/noResource.js +0 -90
  163. package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
  164. package/lib/modules/BookingContext/utils/productExtend.js +0 -283
  165. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  166. package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
  167. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  168. package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
  169. package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
  170. package/lib/modules/BookingContext/utils/resources.js +0 -377
  171. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  172. package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
  173. package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  174. package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
  175. package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  176. package/lib/modules/Order/utils/manualProductDiscount.js +0 -207
  177. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +0 -275
  178. package/lib/solution/BaseSales/utils/cartPromotion.js +0 -836
  179. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  180. package/lib/solution/BaseSales/utils/quotationPrice.js +0 -277
  181. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  182. package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -318
@@ -1,346 +0,0 @@
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 dayjs from 'dayjs';
8
- import { cacheItemToBookingInput, derivePresetStartTimeFromDate, getProductExtend, getIsAutoClose, isSessionProduct, isBookingProduct, applySessionTimesToExtend, hasActualResourceSelection, productNeedsResourceExtend } from "../../../modules/BookingContext";
9
- import { transformBaseProductToOrderProduct } from "../../BaseSales/utils/transformBaseProductToOrderProduct";
10
-
11
- /**
12
- * cart.addProduct 两阶段决策(与 ticketBooking `handleSelectProduct` 对齐):
13
- *
14
- * 1. `requiresDetail`:规格 / SKU / 套餐 / Session / 称重弹窗(门禁:`isOpenDetailModal` / `cartDetailValue` / `open_sold_weight`)
15
- * 2. `requiresBookingEdit`:资源 / 时间编辑抽屉(门禁:`getIsAutoClose` on prepared cacheItem)
16
- * 3. `add`:两关均通过,直接 transform + 加车
17
- */
18
-
19
- /** 资源 / 时间编辑抽屉所需的最小 payload。 */
20
-
21
- /**
22
- * 第一段:是否需要打开规格 / SKU 详情弹窗(与 addService `handleSelectProduct` 一致,不用 `getIsEject` 做门禁)。
23
- */
24
- function needsSpecDetailModal(item) {
25
- if (item !== null && item !== void 0 && item.open_sold_weight) return true;
26
- if (item !== null && item !== void 0 && item.isOpenDetailModal) return true;
27
- if (!(item !== null && item !== void 0 && item.cartDetailValue)) return true;
28
- return false;
29
- }
30
-
31
- /**
32
- * 第二段:预约商品是否仍需打开资源 / 时间编辑(与 info2 `cacheItem.autoClose` 等价)。
33
- */
34
- function needsBookingEdit(cacheItem, ctx) {
35
- if (isNormalBookingProduct(cacheItem)) return false;
36
- var isAutoAllocationOn = (ctx === null || ctx === void 0 ? void 0 : ctx.isAutoAllocationOn) || function () {
37
- return true;
38
- };
39
- return !getIsAutoClose(cacheItem, isAutoAllocationOn);
40
- }
41
- function buildRequiresBookingEditPayload(cacheItem, ctx) {
42
- return {
43
- cacheItem: cacheItem,
44
- customerId: ctx === null || ctx === void 0 ? void 0 : ctx.customerId,
45
- date: typeof (ctx === null || ctx === void 0 ? void 0 : ctx.date) === 'string' ? ctx.date : null
46
- };
47
- }
48
-
49
- /**
50
- * 加车主决策:对齐 `handleSelectProduct` 两段分支。
51
- */
52
- export function decideAddProduct(item, ctx) {
53
- var derivedCtx = withDerivedBookingCtx(ctx);
54
- if (needsSpecDetailModal(item)) {
55
- return {
56
- action: 'requiresDetail',
57
- payload: buildRequiresDetailPayload(item, derivedCtx)
58
- };
59
- }
60
- var cacheItem = prepareBookingCacheItem(buildCacheItemFromCartDetail(item, derivedCtx), derivedCtx);
61
- if (needsBookingEdit(cacheItem, derivedCtx)) {
62
- return {
63
- action: 'requiresBookingEdit',
64
- cacheItem: cacheItem,
65
- payload: buildRequiresBookingEditPayload(cacheItem, derivedCtx)
66
- };
67
- }
68
- return {
69
- action: 'add',
70
- cacheItem: cacheItem
71
- };
72
- }
73
-
74
- /**
75
- * 规格弹窗 callback 后的第二段决策(对齐 `handleBooking4Service` 内 `cacheItem.autoClose` 分支)。
76
- */
77
- export function decideAfterDetail(cacheItem, ctx) {
78
- var derivedCtx = withDerivedBookingCtx(ctx);
79
- var extended = prepareBookingCacheItem(cacheItem, derivedCtx);
80
- if (needsBookingEdit(extended, derivedCtx)) {
81
- return {
82
- action: 'requiresBookingEdit',
83
- cacheItem: extended,
84
- payload: buildRequiresBookingEditPayload(extended, derivedCtx)
85
- };
86
- }
87
- return {
88
- action: 'add',
89
- cacheItem: extended
90
- };
91
- }
92
-
93
- /**
94
- * @deprecated 请用 `decideAddProduct`;保留兼容:autoClose=true 仅表示可直接加车(action=add)。
95
- */
96
-
97
- function isNormalBookingProduct(item) {
98
- return !isBookingProduct(item);
99
- }
100
- function hasPreparedBookingExtend(cacheItem) {
101
- var _ext$other;
102
- // 场次/时间已写入但资源仍未选中时,须继续走 getProductExtend(对齐 info2 必定调用 getProductExtend)。
103
- if (productNeedsResourceExtend(cacheItem) && !hasActualResourceSelection(cacheItem)) {
104
- return false;
105
- }
106
- var ext = (cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem._extend) || {};
107
- var hasResourceState = Boolean(hasActualResourceSelection(cacheItem) && ext.capacity && (ext.endDate || ext.end_date));
108
- var hasSessionState = Boolean(isSessionProduct(cacheItem) && ((_ext$other = ext.other) === null || _ext$other === void 0 ? void 0 : _ext$other.session) && ext.start_time && (ext.end_time || ext.endDate));
109
- var hasMultiDayState = Boolean(isNormalBookingProduct(cacheItem) === false && isMultiDayLike(cacheItem));
110
- var hasExplicitTimeState = Boolean(ext.duration && (ext.start_date || ext.startDate) && ext.start_time && (ext.end_date && ext.end_time || ext.endDate));
111
- return hasResourceState || hasSessionState || hasMultiDayState || hasExplicitTimeState;
112
- }
113
-
114
- /** 弹窗 / Host 使用的日历日,与 ticketBooking `state.date.format('YYYY-MM-DD')` 对齐。 */
115
- function formatBookingDateForUI(date) {
116
- if (date == null || date === '') return null;
117
- var parsed = dayjs(date);
118
- return parsed.isValid() ? parsed.format('YYYY-MM-DD') : null;
119
- }
120
-
121
- /** 补齐 presetStartTime(decideAutoClose / transform 与 BookingTicket.buildAddProductCtx 共用)。 */
122
- function withDerivedBookingCtx(ctx) {
123
- var _ctx$presetStartTime;
124
- if (!ctx) return {};
125
- return _objectSpread(_objectSpread({}, ctx), {}, {
126
- presetStartTime: (_ctx$presetStartTime = ctx.presetStartTime) !== null && _ctx$presetStartTime !== void 0 ? _ctx$presetStartTime : derivePresetStartTimeFromDate(ctx.date)
127
- });
128
- }
129
- function isMultiDayLike(cacheItem) {
130
- var _cacheItem$duration;
131
- var ext = (cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem._extend) || {};
132
- return Boolean((cacheItem === null || cacheItem === void 0 || (_cacheItem$duration = cacheItem.duration) === null || _cacheItem$duration === void 0 ? void 0 : _cacheItem$duration.type) === 'days' && ext.duration && ext.start_date && ext.end_date);
133
- }
134
-
135
- /**
136
- * 统一补齐预约商品的运行态字段。
137
- *
138
- * 新链路不再让决策和提交各自重建 cacheItem;这里作为唯一入口补齐
139
- * `_extend.resource / capacity / startDate / endDate` 等后续 booking mapper 需要的字段。
140
- */
141
- export function prepareBookingCacheItem(cacheItem, ctx) {
142
- if (isNormalBookingProduct(cacheItem) || hasPreparedBookingExtend(cacheItem)) {
143
- return cacheItem;
144
- }
145
- return getProductExtend({
146
- cacheItem: cacheItem,
147
- ctx: withDerivedBookingCtx(ctx),
148
- isDisabledTime: true
149
- });
150
- }
151
- export function decideAutoClose(item, ctx) {
152
- var decision = decideAddProduct(item, ctx);
153
- if (decision.action === 'add') {
154
- return {
155
- autoClose: true,
156
- cacheItem: decision.cacheItem
157
- };
158
- }
159
- if (decision.action === 'requiresBookingEdit') {
160
- return {
161
- autoClose: false,
162
- cacheItem: decision.cacheItem
163
- };
164
- }
165
- return {
166
- autoClose: false
167
- };
168
- }
169
-
170
- /**
171
- * 替代 info2 `getIsEject`:商品是否需要弹窗(含 type='detail' / option_group / bundle_group / variant / session / sold_by_weight)。
172
- */
173
- export function getIsEject(item) {
174
- var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'select';
175
- var isSession = isSessionProduct(item);
176
- var isSoldByWeight = Boolean(item === null || item === void 0 ? void 0 : item.open_sold_weight);
177
- var need = type === 'detail' || ((item === null || item === void 0 ? void 0 : item.bundle_group_count) || 0) > 0 || ((item === null || item === void 0 ? void 0 : item.option_group_count) || 0) > 0 || ((item === null || item === void 0 ? void 0 : item.is_variant) || 0) > 0 || isSession || isSoldByWeight;
178
- return need ? 1 : 0;
179
- }
180
-
181
- /** 仅 session 商品(且没有 variant/option/package)。 */
182
- export function getIsOnlySession(item) {
183
- var isSession = isSessionProduct(item);
184
- return !(((item === null || item === void 0 ? void 0 : item.bundle_group_count) || 0) > 0 || ((item === null || item === void 0 ? void 0 : item.option_group_count) || 0) > 0 || ((item === null || item === void 0 ? void 0 : item.is_variant) || 0) > 0) && isSession;
185
- }
186
-
187
- /**
188
- * 拼装 requiresDetail payload;showConfig 与 info2 弹窗内部判断一致。
189
- */
190
- export function buildRequiresDetailPayload(item, ctx) {
191
- var isOnlySession = getIsOnlySession(item);
192
- var isEject = getIsEject(item, (ctx === null || ctx === void 0 ? void 0 : ctx.type) || 'select');
193
- return {
194
- item: item,
195
- showConfig: {
196
- option: ((item === null || item === void 0 ? void 0 : item.option_group_count) || 0) > 0,
197
- session: isSessionProduct(item),
198
- variant: ((item === null || item === void 0 ? void 0 : item.is_variant) || 0) > 0,
199
- package: ((item === null || item === void 0 ? void 0 : item.bundle_group_count) || 0) > 0,
200
- number: Boolean(item === null || item === void 0 ? void 0 : item.open_sold_weight)
201
- },
202
- isOnlySession: isOnlySession,
203
- isEject: isEject ? 1 : 0,
204
- customerId: ctx === null || ctx === void 0 ? void 0 : ctx.customerId,
205
- date: formatBookingDateForUI(ctx === null || ctx === void 0 ? void 0 : ctx.date),
206
- productData: item
207
- };
208
- }
209
-
210
- /**
211
- * 用 item.cartDetailValue 拼装一个 cacheItem 雏形(与 info2 `handleDirectAddService` 等价路径)。
212
- * 这里只补 `_extend.start_date / quantity / other` 等运行态字段;后续走 getProductExtend 才会补齐资源 / 时间。
213
- */
214
- export function buildCacheItemFromCartDetail(item, ctx) {
215
- var _item$id, _ref, _ctx$quantity, _item$_extend$price, _item$_extend;
216
- var cartDetailValue = item.cartDetailValue || {};
217
- var other = JSON.parse(JSON.stringify(cartDetailValue || {}));
218
- other.session = cartDetailValue.session;
219
- /** 列表/接口可能只带 product_id 不带 id,勿用 item.id 覆盖掉已有 product_id */
220
- var resolvedId = (_item$id = item.id) !== null && _item$id !== void 0 ? _item$id : item.product_id;
221
- var extend = applySessionTimesToExtend(item, {
222
- start_date: (ctx === null || ctx === void 0 ? void 0 : ctx.date) || undefined,
223
- /** 列表连点 / 防抖合并时以 ctx.quantity 为准,避免 cartDetailValue 默认 1 盖掉合并数量 */
224
- quantity: (_ref = (_ctx$quantity = ctx === null || ctx === void 0 ? void 0 : ctx.quantity) !== null && _ctx$quantity !== void 0 ? _ctx$quantity : cartDetailValue === null || cartDetailValue === void 0 ? void 0 : cartDetailValue.quantity) !== null && _ref !== void 0 ? _ref : 1,
225
- product_name: item.title,
226
- other: other,
227
- isNormalProduct: !isBookingProduct(item),
228
- price: (_item$_extend$price = item === null || item === void 0 || (_item$_extend = item._extend) === null || _item$_extend === void 0 ? void 0 : _item$_extend.price) !== null && _item$_extend$price !== void 0 ? _item$_extend$price : item === null || item === void 0 ? void 0 : item.price
229
- }, {
230
- date: ctx === null || ctx === void 0 ? void 0 : ctx.date
231
- });
232
- return _objectSpread(_objectSpread({}, item), {}, {
233
- id: resolvedId,
234
- product_id: resolvedId,
235
- _key: cartDetailValue.key,
236
- _extend: extend,
237
- new: 1
238
- });
239
- }
240
-
241
- /**
242
- * 用 Info2 callback 的 (e, extension_type, detail) 拼装 cacheItem。
243
- *
244
- * 保留 detail._extend 中的 pricing / note(规格弹窗改价、备注等),
245
- * 再叠加 session 时间、ctx.quantity 等运行态字段;other 以 callback `e` 为准。
246
- */
247
- export function buildCacheItemFromDetail(item, detailResult, ctx) {
248
- var _detailResult$e, _currentItem$id, _detail$extension_typ, _ref2, _ref3, _ctx$quantity2, _detailResult$e2, _ref4, _detailExtend$price, _currentItem$title, _detailExtend$note, _detailResult$e3;
249
- var _currentItem = detailResult.detail || item;
250
- var _detail = _currentItem;
251
- var detailExtend = (_detail === null || _detail === void 0 ? void 0 : _detail._extend) || {};
252
- var other = JSON.parse(JSON.stringify(detailResult.e || {}));
253
- other.session = (_detailResult$e = detailResult.e) === null || _detailResult$e === void 0 ? void 0 : _detailResult$e.session;
254
- var resolvedId = (_currentItem$id = _currentItem.id) !== null && _currentItem$id !== void 0 ? _currentItem$id : _currentItem.product_id;
255
- var mergedItem = _objectSpread(_objectSpread(_objectSpread({}, item), _detail), {}, {
256
- extension_type: (_detail$extension_typ = _detail.extension_type) !== null && _detail$extension_typ !== void 0 ? _detail$extension_typ : item.extension_type
257
- });
258
- var runtimeExtend = applySessionTimesToExtend(mergedItem, {
259
- start_date: (ctx === null || ctx === void 0 ? void 0 : ctx.date) || detailExtend.start_date || undefined,
260
- quantity: (_ref2 = (_ref3 = (_ctx$quantity2 = ctx === null || ctx === void 0 ? void 0 : ctx.quantity) !== null && _ctx$quantity2 !== void 0 ? _ctx$quantity2 : (_detailResult$e2 = detailResult.e) === null || _detailResult$e2 === void 0 ? void 0 : _detailResult$e2.quantity) !== null && _ref3 !== void 0 ? _ref3 : detailExtend.quantity) !== null && _ref2 !== void 0 ? _ref2 : 1,
261
- price: (_ref4 = (_detailExtend$price = detailExtend.price) !== null && _detailExtend$price !== void 0 ? _detailExtend$price : _detail === null || _detail === void 0 ? void 0 : _detail.price) !== null && _ref4 !== void 0 ? _ref4 : item === null || item === void 0 ? void 0 : item.price,
262
- product_name: (_currentItem$title = _currentItem.title) !== null && _currentItem$title !== void 0 ? _currentItem$title : detailExtend.product_name,
263
- other: other,
264
- isNormalProduct: !isBookingProduct(mergedItem)
265
- }, {
266
- date: ctx === null || ctx === void 0 ? void 0 : ctx.date
267
- });
268
- var extend = _objectSpread(_objectSpread(_objectSpread({}, detailExtend), runtimeExtend), {}, {
269
- other: other
270
- });
271
- var note = (_detailExtend$note = detailExtend.note) !== null && _detailExtend$note !== void 0 ? _detailExtend$note : _detail === null || _detail === void 0 ? void 0 : _detail.note;
272
- return _objectSpread(_objectSpread(_objectSpread({}, _detail), {}, {
273
- id: resolvedId,
274
- product_id: resolvedId,
275
- extension_type: mergedItem.extension_type,
276
- _key: (_detailResult$e3 = detailResult.e) === null || _detailResult$e3 === void 0 ? void 0 : _detailResult$e3.key
277
- }, note != null && note !== '' ? {
278
- note: String(note)
279
- } : {}), {}, {
280
- _extend: extend,
281
- new: 1
282
- });
283
- }
284
-
285
- /**
286
- * `transformDetailToProductAndBooking`:把 cacheItem 拆成 OS `addProductToOrder` 所需的 `(product, booking)`。
287
- *
288
- * - `product` 走 `transformBaseProductToOrderProduct`(沿用 BaseSales 现有 mapper)。
289
- * - `booking` 走 `cacheItemToBookingInput`(严格按 TEMP_ORDER_FIELDS_SUMMARY.md 协议)。
290
- * - 普通商品(无 duration / 无 schedules)不产 booking,与 info2 一致。
291
- */
292
- export function transformDetailToProductAndBooking(cacheItem, ctx) {
293
- var preparedCacheItem = prepareBookingCacheItem(cacheItem, withDerivedBookingCtx(ctx));
294
- var payload = buildBasePayloadFromCacheItem(preparedCacheItem, ctx);
295
- var productInput = transformBaseProductToOrderProduct({
296
- payload: payload,
297
- sourceProduct: preparedCacheItem
298
- });
299
- if (!productInput) {
300
- throw new Error('[BookingTicket] transformDetailToProductAndBooking: product transform failed (missing numeric item.id / item.product_id)');
301
- }
302
- var isNormalProduct = isNormalBookingProduct(preparedCacheItem);
303
- var booking;
304
- if (!isNormalProduct) {
305
- booking = cacheItemToBookingInput(preparedCacheItem, {
306
- bookingConfig: ctx === null || ctx === void 0 ? void 0 : ctx.bookingConfig
307
- });
308
- }
309
- return {
310
- product: productInput,
311
- booking: booking,
312
- cacheItem: preparedCacheItem
313
- };
314
- }
315
-
316
- /**
317
- * 把 cacheItem._extend.other 中的字段 + 顶层运行态拼成 `BaseProductDetailPayload`。
318
- */
319
- function buildBasePayloadFromCacheItem(cacheItem, ctx) {
320
- var _cacheItem$_extend, _cacheItem$_extend$qu, _cacheItem$_extend2, _cacheItem$product_id, _cacheItem$id, _ref5, _other$product_varian, _extend$skuValue, _extend$_skuValue, _extend$price, _extend$price2;
321
- var other = (cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend = cacheItem._extend) === null || _cacheItem$_extend === void 0 ? void 0 : _cacheItem$_extend.other) || {};
322
- var quantity = (ctx === null || ctx === void 0 ? void 0 : ctx.quantity) != null && ctx.quantity > 0 ? ctx.quantity : (_cacheItem$_extend$qu = cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend2 = cacheItem._extend) === null || _cacheItem$_extend2 === void 0 ? void 0 : _cacheItem$_extend2.quantity) !== null && _cacheItem$_extend$qu !== void 0 ? _cacheItem$_extend$qu : 1;
323
- var resolvedPid = (_cacheItem$product_id = cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem.product_id) !== null && _cacheItem$product_id !== void 0 ? _cacheItem$product_id : cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem.id;
324
- var extend = (cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem._extend) || {};
325
- return {
326
- id: (_cacheItem$id = cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem.id) !== null && _cacheItem$id !== void 0 ? _cacheItem$id : cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem.product_id,
327
- product_id: resolvedPid,
328
- variant_id: (_ref5 = (_other$product_varian = other === null || other === void 0 ? void 0 : other.product_variant_id) !== null && _other$product_varian !== void 0 ? _other$product_varian : other === null || other === void 0 ? void 0 : other.variant_id) !== null && _ref5 !== void 0 ? _ref5 : 0,
329
- quantity: quantity,
330
- option: (other === null || other === void 0 ? void 0 : other.option) || [],
331
- bundle: (other === null || other === void 0 ? void 0 : other.bundle) || (extend === null || extend === void 0 || (_extend$skuValue = extend.skuValue) === null || _extend$skuValue === void 0 ? void 0 : _extend$skuValue.bundle) || (extend === null || extend === void 0 || (_extend$_skuValue = extend._skuValue) === null || _extend$_skuValue === void 0 ? void 0 : _extend$_skuValue.bundle) || [],
332
- unique: other === null || other === void 0 ? void 0 : other.unique,
333
- session: other === null || other === void 0 ? void 0 : other.session,
334
- note: extend === null || extend === void 0 ? void 0 : extend.note,
335
- price: (_extend$price = extend === null || extend === void 0 ? void 0 : extend.price) !== null && _extend$price !== void 0 ? _extend$price : cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem.price,
336
- selling_price: (_extend$price2 = extend === null || extend === void 0 ? void 0 : extend.price) !== null && _extend$price2 !== void 0 ? _extend$price2 : cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem.price,
337
- line_total: extend === null || extend === void 0 ? void 0 : extend.total,
338
- total: extend === null || extend === void 0 ? void 0 : extend.total,
339
- origin_total: extend === null || extend === void 0 ? void 0 : extend.origin_total,
340
- price_override: extend === null || extend === void 0 ? void 0 : extend.priceOverride,
341
- bundle_edit: extend === null || extend === void 0 ? void 0 : extend.bundle_edit,
342
- discount_reason: extend === null || extend === void 0 ? void 0 : extend.discount_reason,
343
- discount_list: cacheItem === null || cacheItem === void 0 ? void 0 : cacheItem.discount_list,
344
- _extend: extend
345
- };
346
- }
@@ -1,37 +0,0 @@
1
- import { Module, ModuleOptions, PisellCore } from '../../types';
2
- import { BaseModule } from '../BaseModule';
3
- import { BookingContextConfig, BookingContextDateInput, BookingContextModuleAPI, BookingContextResource, BookingContextResourceMap, BookingContextState, InitBookingContextParams, LoadBookingConfigParams, LoadBookingResourcesParams } from './types';
4
- export * from './types';
5
- export * from './utils';
6
- /** 稳定序列化 config 查询参数,用于判断是否与上次 loadBookingConfig 一致。 */
7
- export declare function buildBookingConfigQueryKey(params?: LoadBookingConfigParams): string;
8
- /** 稳定序列化资源列表查询(date + bookingIds),用于跳过重复 loadResources。 */
9
- export declare function buildBookingResourcesQueryKey(params?: LoadBookingResourcesParams): string;
10
- export declare class BookingContextModule extends BaseModule implements Module, BookingContextModuleAPI {
11
- protected defaultName: string;
12
- protected defaultVersion: string;
13
- private request;
14
- private store;
15
- /** 上次成功 loadBookingConfig 的 query key;命中则不再请求。 */
16
- private lastConfigQueryKey;
17
- /** 上次成功 loadResources 的 query key(date|bookingIds);命中则不再请求。 */
18
- private lastResourcesQueryKey;
19
- constructor(name?: string, version?: string);
20
- initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
21
- loadBookingConfig(params?: LoadBookingConfigParams): Promise<BookingContextConfig | null>;
22
- loadResources(params?: LoadBookingResourcesParams): Promise<BookingContextResource[]>;
23
- /**
24
- * store 内是否已具备与本次 init 入参等价的 config / resources(不再打接口)。
25
- */
26
- isBookingContextReady(params?: InitBookingContextParams): boolean;
27
- initBookingContext(params?: InitBookingContextParams): Promise<BookingContextState>;
28
- setBookingConfig(config: BookingContextConfig | null): void;
29
- getBookingConfig(): BookingContextConfig | null;
30
- setResources(resources: BookingContextResource[] | null | undefined): void;
31
- getResourcesOrigin(): BookingContextResource[];
32
- getResourcesOriginMap(): BookingContextResourceMap;
33
- setDate(date: BookingContextDateInput): void;
34
- getDate(): string | null;
35
- getState(): BookingContextState;
36
- clear(): void;
37
- }
@@ -1,297 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/modules/BookingContext/index.ts
31
- var BookingContext_exports = {};
32
- __export(BookingContext_exports, {
33
- BookingContextModule: () => BookingContextModule,
34
- buildBookingConfigQueryKey: () => buildBookingConfigQueryKey,
35
- buildBookingResourcesQueryKey: () => buildBookingResourcesQueryKey
36
- });
37
- module.exports = __toCommonJS(BookingContext_exports);
38
- var import_dayjs = __toESM(require("dayjs"));
39
- var import_BaseModule = require("../BaseModule");
40
- var import_request = require("../../plugins/request");
41
- var import_types = require("./types");
42
- var import_formatResourceList = require("./utils/formatResourceList");
43
- __reExport(BookingContext_exports, require("./types"), module.exports);
44
- __reExport(BookingContext_exports, require("./utils"), module.exports);
45
- var EMPTY_STATE = {
46
- bookingConfig: null,
47
- resourcesOrigin: [],
48
- resourcesOriginMap: {},
49
- date: null
50
- };
51
- var DEFAULT_BOOKING_CONFIG_PARAMS = {
52
- item_type: "appointment_booking",
53
- sub_type: "ticket"
54
- };
55
- var BOARD_CONFIG_CACHE = {
56
- useCache: true,
57
- cache: {
58
- mode: import_request.RequestModeENUM.REMOTE_LOCAL,
59
- type: "indexDB",
60
- updateCache: true
61
- }
62
- };
63
- var RESOURCE_LIST_CACHE = {
64
- useCache: true,
65
- cache: {
66
- mode: import_request.RequestModeENUM.REMOTE_LOCAL,
67
- type: "memory"
68
- }
69
- };
70
- function normalizeDate(input) {
71
- if (input === null || input === void 0)
72
- return null;
73
- if (typeof input === "string")
74
- return input || null;
75
- if (input instanceof Date)
76
- return input.toISOString();
77
- if (typeof input.format === "function") {
78
- try {
79
- return input.format() || null;
80
- } catch {
81
- return null;
82
- }
83
- }
84
- return null;
85
- }
86
- function toScheduleQueryDate(input) {
87
- const normalized = normalizeDate(input);
88
- if (!normalized)
89
- return (0, import_dayjs.default)().format("YYYY-MM-DD");
90
- const parsed = (0, import_dayjs.default)(normalized);
91
- return parsed.isValid() ? parsed.format("YYYY-MM-DD") : (0, import_dayjs.default)().format("YYYY-MM-DD");
92
- }
93
- function buildResourcesMap(resources) {
94
- const map = {};
95
- resources.forEach((resource) => {
96
- if (resource && resource.id !== void 0 && resource.id !== null) {
97
- map[String(resource.id)] = resource;
98
- }
99
- });
100
- return map;
101
- }
102
- function buildBookingConfigQueryKey(params = {}) {
103
- const merged = { ...DEFAULT_BOOKING_CONFIG_PARAMS, ...params };
104
- const keys = Object.keys(merged).sort();
105
- const sorted = {};
106
- keys.forEach((k) => {
107
- sorted[k] = merged[k];
108
- });
109
- return JSON.stringify(sorted);
110
- }
111
- function buildBookingResourcesQueryKey(params = {}) {
112
- const date = toScheduleQueryDate(params.date);
113
- const ids = (params.bookingIds || []).filter((id) => typeof id === "number" && Number.isFinite(id)).sort((a, b) => a - b);
114
- return `${date}|${ids.join(",")}`;
115
- }
116
- var BookingContextModule = class extends import_BaseModule.BaseModule {
117
- constructor(name, version) {
118
- super(name, version);
119
- this.defaultName = "bookingContext";
120
- this.defaultVersion = "1.0.0";
121
- this.store = { ...EMPTY_STATE };
122
- /** 上次成功 loadBookingConfig 的 query key;命中则不再请求。 */
123
- this.lastConfigQueryKey = null;
124
- /** 上次成功 loadResources 的 query key(date|bookingIds);命中则不再请求。 */
125
- this.lastResourcesQueryKey = null;
126
- }
127
- async initialize(core, options = {}) {
128
- this.core = core;
129
- this.request = core.getPlugin("request");
130
- if (!this.request) {
131
- throw new Error("BookingContextModule 需要 request 插件支持");
132
- }
133
- this.store = {
134
- bookingConfig: null,
135
- resourcesOrigin: [],
136
- resourcesOriginMap: {},
137
- date: null
138
- };
139
- const initialState = options.initialState || {};
140
- if (initialState.bookingConfig) {
141
- this.store.bookingConfig = initialState.bookingConfig;
142
- }
143
- if (Array.isArray(initialState.resourcesOrigin)) {
144
- this.store.resourcesOrigin = initialState.resourcesOrigin;
145
- this.store.resourcesOriginMap = buildResourcesMap(initialState.resourcesOrigin);
146
- }
147
- if (initialState.date) {
148
- this.store.date = initialState.date;
149
- }
150
- }
151
- async loadBookingConfig(params = {}) {
152
- const configKey = buildBookingConfigQueryKey(params);
153
- if (this.store.bookingConfig != null && this.lastConfigQueryKey === configKey) {
154
- return this.store.bookingConfig;
155
- }
156
- const query = {
157
- ...DEFAULT_BOOKING_CONFIG_PARAMS,
158
- ...params
159
- };
160
- const res = await this.request.get(
161
- "/core/board/management/config",
162
- query,
163
- BOARD_CONFIG_CACHE
164
- );
165
- const config = (res == null ? void 0 : res.data) ?? null;
166
- console.log("config123", config);
167
- this.setBookingConfig(config);
168
- this.lastConfigQueryKey = buildBookingConfigQueryKey(params);
169
- return config;
170
- }
171
- async loadResources(params = {}) {
172
- const date = toScheduleQueryDate(params.date ?? this.store.date);
173
- const resourcesKey = buildBookingResourcesQueryKey({
174
- date,
175
- bookingIds: params.bookingIds
176
- });
177
- if (this.lastResourcesQueryKey === resourcesKey) {
178
- return this.getResourcesOrigin();
179
- }
180
- const res = await this.request.get(
181
- "/schedule/resource/list",
182
- { date },
183
- RESOURCE_LIST_CACHE
184
- );
185
- const { list } = (0, import_formatResourceList.formatResourceListAndMap)(res == null ? void 0 : res.data, params.bookingIds || []);
186
- this.setResources(list);
187
- this.lastResourcesQueryKey = buildBookingResourcesQueryKey({
188
- date,
189
- bookingIds: params.bookingIds
190
- });
191
- return list;
192
- }
193
- /**
194
- * store 内是否已具备与本次 init 入参等价的 config / resources(不再打接口)。
195
- */
196
- isBookingContextReady(params = {}) {
197
- const configKey = buildBookingConfigQueryKey(params.bookingConfigParams);
198
- const dateInput = params.date ?? this.store.date ?? (0, import_dayjs.default)();
199
- const queryDate = toScheduleQueryDate(dateInput);
200
- const resourcesKey = buildBookingResourcesQueryKey({
201
- date: queryDate,
202
- bookingIds: params.bookingIds
203
- });
204
- const configReady = this.store.bookingConfig != null && this.lastConfigQueryKey === configKey;
205
- const resourcesReady = params.loadResources === false || this.lastResourcesQueryKey === resourcesKey;
206
- return configReady && resourcesReady;
207
- }
208
- async initBookingContext(params = {}) {
209
- const dateInput = params.date ?? this.store.date ?? (0, import_dayjs.default)();
210
- const queryDate = toScheduleQueryDate(dateInput);
211
- this.setDate(dateInput);
212
- if (!params.forceRefresh && this.isBookingContextReady(params)) {
213
- return this.getState();
214
- }
215
- const configKey = buildBookingConfigQueryKey(params.bookingConfigParams);
216
- const resourcesKey = buildBookingResourcesQueryKey({
217
- date: queryDate,
218
- bookingIds: params.bookingIds
219
- });
220
- const needConfig = params.forceRefresh || this.store.bookingConfig == null || this.lastConfigQueryKey !== configKey;
221
- const needResources = params.loadResources !== false && (params.forceRefresh || this.lastResourcesQueryKey !== resourcesKey);
222
- if (needConfig) {
223
- await this.loadBookingConfig(params.bookingConfigParams);
224
- }
225
- if (needResources) {
226
- await this.loadResources({
227
- date: queryDate,
228
- bookingIds: params.bookingIds
229
- });
230
- }
231
- return this.getState();
232
- }
233
- setBookingConfig(config) {
234
- this.store.bookingConfig = config || null;
235
- this.core.effects.emit(
236
- `${this.name}:${import_types.BookingContextEvent.OnBookingConfigChange}`,
237
- this.store.bookingConfig
238
- );
239
- }
240
- getBookingConfig() {
241
- return this.store.bookingConfig;
242
- }
243
- setResources(resources) {
244
- const list = Array.isArray(resources) ? resources : [];
245
- this.store.resourcesOrigin = list;
246
- this.store.resourcesOriginMap = buildResourcesMap(list);
247
- this.core.effects.emit(`${this.name}:${import_types.BookingContextEvent.OnResourcesChange}`, {
248
- resourcesOrigin: this.store.resourcesOrigin,
249
- resourcesOriginMap: this.store.resourcesOriginMap
250
- });
251
- }
252
- getResourcesOrigin() {
253
- return [...this.store.resourcesOrigin];
254
- }
255
- getResourcesOriginMap() {
256
- return this.store.resourcesOriginMap;
257
- }
258
- setDate(date) {
259
- this.store.date = normalizeDate(date);
260
- this.core.effects.emit(`${this.name}:${import_types.BookingContextEvent.OnDateChange}`, this.store.date);
261
- }
262
- getDate() {
263
- return this.store.date;
264
- }
265
- getState() {
266
- return {
267
- bookingConfig: this.store.bookingConfig,
268
- resourcesOrigin: [...this.store.resourcesOrigin],
269
- resourcesOriginMap: this.store.resourcesOriginMap,
270
- date: this.store.date
271
- };
272
- }
273
- clear() {
274
- this.lastConfigQueryKey = null;
275
- this.lastResourcesQueryKey = null;
276
- this.store = {
277
- bookingConfig: null,
278
- resourcesOrigin: [],
279
- resourcesOriginMap: {},
280
- date: null
281
- };
282
- this.core.effects.emit(`${this.name}:${import_types.BookingContextEvent.OnBookingConfigChange}`, null);
283
- this.core.effects.emit(`${this.name}:${import_types.BookingContextEvent.OnResourcesChange}`, {
284
- resourcesOrigin: [],
285
- resourcesOriginMap: {}
286
- });
287
- this.core.effects.emit(`${this.name}:${import_types.BookingContextEvent.OnDateChange}`, null);
288
- }
289
- };
290
- // Annotate the CommonJS export names for ESM import in node:
291
- 0 && (module.exports = {
292
- BookingContextModule,
293
- buildBookingConfigQueryKey,
294
- buildBookingResourcesQueryKey,
295
- ...require("./types"),
296
- ...require("./utils")
297
- });