@pisell/pisellos 2.3.195 → 2.3.196

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 (37) hide show
  1. package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  2. package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
  3. package/dist/modules/BookingContext/utils/index.d.ts +1 -0
  4. package/dist/modules/BookingContext/utils/index.js +1 -0
  5. package/dist/modules/BookingContext/utils/productExtend.d.ts +6 -0
  6. package/dist/modules/BookingContext/utils/productExtend.js +21 -0
  7. package/dist/modules/ResourcePlanner/planner.js +24 -0
  8. package/dist/modules/ResourcePlanner/types.d.ts +7 -0
  9. package/dist/server/index.js +27 -17
  10. package/dist/solution/BookingByStep/index.d.ts +2 -2
  11. package/dist/solution/BookingTicket/index.d.ts +1 -1
  12. package/dist/solution/BookingTicket/index.js +8 -4
  13. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +2 -0
  14. package/dist/solution/BookingTicket/utils/addProductDecision.js +35 -8
  15. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  16. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
  17. package/dist/solution/UnifiedBookingSales/index.d.ts +14 -2
  18. package/dist/solution/UnifiedBookingSales/index.js +1619 -1335
  19. package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  20. package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
  21. package/lib/modules/BookingContext/utils/index.d.ts +1 -0
  22. package/lib/modules/BookingContext/utils/index.js +11 -0
  23. package/lib/modules/BookingContext/utils/productExtend.d.ts +6 -0
  24. package/lib/modules/BookingContext/utils/productExtend.js +23 -0
  25. package/lib/modules/ResourcePlanner/planner.js +23 -0
  26. package/lib/modules/ResourcePlanner/types.d.ts +7 -0
  27. package/lib/server/index.js +5 -1
  28. package/lib/solution/BookingByStep/index.d.ts +2 -2
  29. package/lib/solution/BookingTicket/index.d.ts +1 -1
  30. package/lib/solution/BookingTicket/index.js +4 -2
  31. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +2 -0
  32. package/lib/solution/BookingTicket/utils/addProductDecision.js +33 -3
  33. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  34. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
  35. package/lib/solution/UnifiedBookingSales/index.d.ts +14 -2
  36. package/lib/solution/UnifiedBookingSales/index.js +139 -3
  37. package/package.json +1 -1
@@ -0,0 +1,15 @@
1
+ import dayjs from 'dayjs';
2
+ import type { BookingCalcContext } from './productExtend';
3
+ export declare function isManualBookingProduct(product: any): boolean;
4
+ export declare function getCalendarBookingRange(product: any, ctx?: BookingCalcContext): {
5
+ startAt: string;
6
+ endAt: string;
7
+ duration: number;
8
+ startDate: dayjs.Dayjs;
9
+ endDate: dayjs.Dayjs;
10
+ } | undefined;
11
+ /** A prepared calendar cache is reused after SKU input; no availability-driven replacement is allowed. */
12
+ export declare function prepareCalendarBookingCacheItem(cacheItem: any, ctx: BookingCalcContext): any;
13
+ export declare function calendarBookingEntryKey(ctx: BookingCalcContext): string;
14
+ export declare function calendarBookingNeedsInput(cacheItem: any): boolean;
15
+ export declare function calendarBookingPreparationKey(cacheItem: any, ctx: BookingCalcContext): string;
@@ -0,0 +1,207 @@
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ 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."); }
4
+ 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; } }
5
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
7
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
11
+ 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); }
12
+ 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; }
13
+ 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; }
14
+ 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; }
15
+ 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; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
+ 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); }
18
+ import dayjs from 'dayjs';
19
+ import { captureRuntimeOffsetMinutes, extractFixedOffsetMinutes, formatLocalDateTime, localDateTimeToScalar, parseLocalDateTime } from "../../ResourcePlanner/localClock";
20
+ import { isBookingProduct, isMultiDayProduct } from "./serviceTimes";
21
+ export function isManualBookingProduct(product) {
22
+ var _product$product_reso, _product$capacity;
23
+ return !isBookingProduct(product) && Boolean((product === null || product === void 0 ? void 0 : product.extension_type) === 'product_appointment' || (product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 || (_product$product_reso = _product$product_reso.resources) === null || _product$product_reso === void 0 ? void 0 : _product$product_reso.some(function (group) {
24
+ return Number(group.status) === 1;
25
+ })) || ['custom', 'package'].includes(product === null || product === void 0 || (_product$capacity = product.capacity) === null || _product$capacity === void 0 ? void 0 : _product$capacity.type));
26
+ }
27
+ export function getCalendarBookingRange(product, ctx) {
28
+ var _product$flexible, _product$_extend;
29
+ var range = ctx === null || ctx === void 0 ? void 0 : ctx.bookingTimeRangeFromCalendar;
30
+ if (!range || (ctx === null || ctx === void 0 ? void 0 : ctx.platform) !== 'pos' || isMultiDayProduct(product) || (product === null || product === void 0 ? void 0 : product.duration_type) === 'days' || (product === null || product === void 0 || (_product$flexible = product.flexible) === null || _product$flexible === void 0 || (_product$flexible = _product$flexible.duration) === null || _product$flexible === void 0 ? void 0 : _product$flexible.type) === 'days' || (product === null || product === void 0 || (_product$_extend = product._extend) === null || _product$_extend === void 0 ? void 0 : _product$_extend.sub_type) === 'days' || !isBookingProduct(product) && !isManualBookingProduct(product)) return undefined;
31
+ try {
32
+ var offset = captureRuntimeOffsetMinutes();
33
+ var normalize = function normalize(text) {
34
+ var _extractFixedOffsetMi;
35
+ var scalar = localDateTimeToScalar(parseLocalDateTime(text));
36
+ var inputOffset = (_extractFixedOffsetMi = extractFixedOffsetMinutes(text)) !== null && _extractFixedOffsetMi !== void 0 ? _extractFixedOffsetMi : offset;
37
+ return formatLocalDateTime(scalar + (offset - inputOffset) * 60000, offset);
38
+ };
39
+ var startAt = normalize(range.startAt);
40
+ var endAt = normalize(range.endAt);
41
+ var start = localDateTimeToScalar(parseLocalDateTime(startAt));
42
+ var end = localDateTimeToScalar(parseLocalDateTime(endAt));
43
+ var duration = (end - start) / 60000;
44
+ if (!Number.isInteger(duration) || duration <= 0 || start % 60000 || end % 60000) throw new Error();
45
+ return {
46
+ startAt: startAt,
47
+ endAt: endAt,
48
+ duration: duration,
49
+ startDate: dayjs(startAt.slice(0, 19)),
50
+ endDate: dayjs(endAt.slice(0, 19))
51
+ };
52
+ } catch (_unused) {
53
+ throw Object.assign(new Error('Calendar booking requires valid complete start/end times.'), {
54
+ code: 'INVALID_TARGET_FILTER'
55
+ });
56
+ }
57
+ }
58
+
59
+ /** A prepared calendar cache is reused after SKU input; no availability-driven replacement is allowed. */
60
+ export function prepareCalendarBookingCacheItem(cacheItem, ctx) {
61
+ var _cacheItem$product_re, _cacheItem$_data;
62
+ var range = getCalendarBookingRange(cacheItem, ctx);
63
+ if (!range) return cacheItem;
64
+ var resource = {};
65
+ var forms = (((_cacheItem$product_re = cacheItem.product_resource) === null || _cacheItem$product_re === void 0 ? void 0 : _cacheItem$product_re.resources) || []).filter(function (group) {
66
+ return Number(group.status) === 1;
67
+ });
68
+ var entry = Number(ctx.resourceIdFromCalendar);
69
+ var preserveInput = ((_cacheItem$_data = cacheItem._data) === null || _cacheItem$_data === void 0 ? void 0 : _cacheItem$_data.calendarBookingEntryKey) === calendarBookingEntryKey(ctx);
70
+ var inputInvalid = false;
71
+ if (preserveInput) {
72
+ var ext = cacheItem._extend || {};
73
+ try {
74
+ var _ext$start_date, _ext$end_date, _ext$start_date2, _ext$end_date2;
75
+ if (!((_ext$start_date = ext.start_date) !== null && _ext$start_date !== void 0 ? _ext$start_date : ext.startDate) || !((_ext$end_date = ext.end_date) !== null && _ext$end_date !== void 0 ? _ext$end_date : ext.endDate) || !ext.start_time || !ext.end_time) throw new Error('Incomplete calendar input.');
76
+ range = getCalendarBookingRange(cacheItem, _objectSpread(_objectSpread({}, ctx), {}, {
77
+ bookingTimeRangeFromCalendar: {
78
+ startAt: "".concat(dayjs((_ext$start_date2 = ext.start_date) !== null && _ext$start_date2 !== void 0 ? _ext$start_date2 : ext.startDate).format('YYYY-MM-DD'), "T").concat(ext.start_time, ":00"),
79
+ endAt: "".concat(dayjs((_ext$end_date2 = ext.end_date) !== null && _ext$end_date2 !== void 0 ? _ext$end_date2 : ext.endDate).format('YYYY-MM-DD'), "T").concat(ext.end_time, ":00")
80
+ }
81
+ }));
82
+ } catch (_unused2) {
83
+ range = undefined;
84
+ inputInvalid = true;
85
+ }
86
+ }
87
+ var _iterator = _createForOfIteratorHelper(forms),
88
+ _step;
89
+ try {
90
+ var _loop = function _loop() {
91
+ var _ctx$resourcesOriginM, _cacheItem$_extend;
92
+ var form = _step.value;
93
+ var ids = [].concat(_toConsumableArray(form.optional_resource || []), _toConsumableArray(form.default_resource || []));
94
+ var linked = ids.some(function (id) {
95
+ return String(id) === String(entry);
96
+ });
97
+ var origin = (_ctx$resourcesOriginM = ctx.resourcesOriginMap) === null || _ctx$resourcesOriginM === void 0 ? void 0 : _ctx$resourcesOriginM[entry];
98
+ var chosen = (_cacheItem$_extend = cacheItem._extend) === null || _cacheItem$_extend === void 0 || (_cacheItem$_extend = _cacheItem$_extend.resource) === null || _cacheItem$_extend === void 0 ? void 0 : _cacheItem$_extend[String(form.id)];
99
+ var hasChosen = preserveInput && chosen !== undefined;
100
+ var validChosen = hasChosen && Array.isArray(chosen) && new Set(chosen.map(function (row) {
101
+ return String(row.relation_id);
102
+ })).size === chosen.length && chosen.every(function (row) {
103
+ var _ctx$resourcesOriginM2;
104
+ return (row.form_id == null || String(row.form_id) === String(form.id)) && (Number(row.relation_id) === 0 || ids.some(function (id) {
105
+ return String(id) === String(row.relation_id);
106
+ }) && ((_ctx$resourcesOriginM2 = ctx.resourcesOriginMap) === null || _ctx$resourcesOriginM2 === void 0 ? void 0 : _ctx$resourcesOriginM2[row.relation_id]) && (ctx.resourcesOriginMap[row.relation_id].form_id == null || String(ctx.resourcesOriginMap[row.relation_id].form_id) === String(form.id)));
107
+ });
108
+ if (hasChosen && !validChosen) inputInvalid = true;
109
+ if (hasChosen) {
110
+ resource[String(form.id)] = validChosen ? chosen : [];
111
+ } else if (linked && origin && (origin.form_id == null || String(origin.form_id) === String(form.id))) {
112
+ resource[String(form.id)] = [{
113
+ relation_type: origin.relation_type || 'form',
114
+ form_id: form.id,
115
+ relation_id: entry,
116
+ like_status: 'common',
117
+ metadata: {
118
+ form_name: form.title,
119
+ resource_name: origin.main_field
120
+ }
121
+ }];
122
+ } else {
123
+ resource[String(form.id)] = [];
124
+ }
125
+ };
126
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
127
+ _loop();
128
+ }
129
+ } catch (err) {
130
+ _iterator.e(err);
131
+ } finally {
132
+ _iterator.f();
133
+ }
134
+ return _objectSpread(_objectSpread(_objectSpread({}, cacheItem), isManualBookingProduct(cacheItem) && range ? {
135
+ duration: {
136
+ type: 'minutes',
137
+ value: range.duration
138
+ }
139
+ } : {}), {}, {
140
+ _data: _objectSpread(_objectSpread({}, cacheItem._data), {}, {
141
+ calendarBookingInputInvalid: inputInvalid
142
+ }),
143
+ _extend: _objectSpread(_objectSpread(_objectSpread({}, cacheItem._extend), range ? {
144
+ startDate: range.startDate,
145
+ start_date: range.startDate,
146
+ start_time: range.startAt.slice(11, 16),
147
+ endDate: range.endDate,
148
+ end_date: range.endDate,
149
+ end_time: range.endAt.slice(11, 16),
150
+ duration: range.duration
151
+ } : {}), {}, {
152
+ resource: resource
153
+ })
154
+ });
155
+ }
156
+ export function calendarBookingEntryKey(ctx) {
157
+ return JSON.stringify([ctx.bookingTimeRangeFromCalendar, ctx.resourceIdFromCalendar]);
158
+ }
159
+ export function calendarBookingNeedsInput(cacheItem) {
160
+ var _cacheItem$_data2, _cacheItem$product_re2;
161
+ if ((_cacheItem$_data2 = cacheItem._data) !== null && _cacheItem$_data2 !== void 0 && _cacheItem$_data2.calendarBookingInputInvalid) return true;
162
+ var capacity = cacheItem.capacity;
163
+ if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'custom' && (!Array.isArray(capacity.custom) || !capacity.custom.length || capacity.custom.some(function (item) {
164
+ return !Number.isFinite(Number(item.min)) || item.max == null || Number(item.min) !== Number(item.max);
165
+ }))) return true;
166
+ var groups = (_cacheItem$product_re2 = cacheItem.product_resource) === null || _cacheItem$product_re2 === void 0 ? void 0 : _cacheItem$product_re2.resources;
167
+ if (groups != null && !Array.isArray(groups)) return true;
168
+ var seen = new Set();
169
+ return (groups || []).some(function (group) {
170
+ var _rule$min, _rule$max, _cacheItem$_extend2, _group$required;
171
+ if (Number(group.status) === 0) return false;
172
+ if (group.id == null || seen.has(String(group.id))) return true;
173
+ seen.add(String(group.id));
174
+ var rule = group.select_type;
175
+ if (Number(group.status) !== 1 || !rule || !['single', 'multiple'].includes(rule.type)) return true;
176
+ var min = Number((_rule$min = rule.min) !== null && _rule$min !== void 0 ? _rule$min : rule.type === 'single' ? 1 : NaN);
177
+ var max = Number((_rule$max = rule.max) !== null && _rule$max !== void 0 ? _rule$max : rule.type === 'single' ? 1 : NaN);
178
+ var rows = (_cacheItem$_extend2 = cacheItem._extend) === null || _cacheItem$_extend2 === void 0 || (_cacheItem$_extend2 = _cacheItem$_extend2.resource) === null || _cacheItem$_extend2 === void 0 ? void 0 : _cacheItem$_extend2[String(group.id)];
179
+ var required = (_group$required = group.required) !== null && _group$required !== void 0 ? _group$required : true;
180
+ var minimum = Math.max(required ? 1 : 0, min);
181
+ return !Number.isInteger(min) || !Number.isInteger(max) || min < 0 || max < minimum || !Array.isArray(rows) || rows.length < minimum || rows.length > max;
182
+ });
183
+ }
184
+ export function calendarBookingPreparationKey(cacheItem, ctx) {
185
+ var _cacheItem$_extend3, _sku$product_variant_, _ext$start_date3, _ext$end_date3;
186
+ var identities = function identities(rows) {
187
+ return (rows || []).map(function (row) {
188
+ var _ref, _row$group_id, _ref2, _row$product_option_i, _row$_bundle_product_, _row$product_variant_, _ref3, _row$quantity;
189
+ return [(_ref = (_row$group_id = row.group_id) !== null && _row$group_id !== void 0 ? _row$group_id : row.option_group_id) !== null && _ref !== void 0 ? _ref : row.bundle_group_id, (_ref2 = (_row$product_option_i = row.product_option_item_id) !== null && _row$product_option_i !== void 0 ? _row$product_option_i : row.option_group_item_id) !== null && _ref2 !== void 0 ? _ref2 : row.id, (_row$_bundle_product_ = row._bundle_product_id) !== null && _row$_bundle_product_ !== void 0 ? _row$_bundle_product_ : row.bundle_product_id, (_row$product_variant_ = row.product_variant_id) !== null && _row$product_variant_ !== void 0 ? _row$product_variant_ : row.bundle_variant_id, (_ref3 = (_row$quantity = row.quantity) !== null && _row$quantity !== void 0 ? _row$quantity : row.num) !== null && _ref3 !== void 0 ? _ref3 : 1, identities(row.option)];
190
+ }).sort(function (left, right) {
191
+ return JSON.stringify(left).localeCompare(JSON.stringify(right));
192
+ });
193
+ };
194
+ var sku = ((_cacheItem$_extend3 = cacheItem._extend) === null || _cacheItem$_extend3 === void 0 ? void 0 : _cacheItem$_extend3.other) || {};
195
+ var ext = cacheItem._extend || {};
196
+ var dateKey = function dateKey(value) {
197
+ return value == null || value === '' ? null : dayjs(value).format('YYYY-MM-DD');
198
+ };
199
+ return JSON.stringify([ctx.bookingTimeRangeFromCalendar, ctx.resourceIdFromCalendar, cacheItem.capacity, cacheItem.product_resource, (_sku$product_variant_ = sku.product_variant_id) !== null && _sku$product_variant_ !== void 0 ? _sku$product_variant_ : sku.variant_id, identities(sku.option), identities(sku.bundle), dateKey((_ext$start_date3 = ext.start_date) !== null && _ext$start_date3 !== void 0 ? _ext$start_date3 : ext.startDate), ext.start_time, dateKey((_ext$end_date3 = ext.end_date) !== null && _ext$end_date3 !== void 0 ? _ext$end_date3 : ext.endDate), ext.end_time, Object.entries(ext.resource || {}).map(function (_ref4) {
200
+ var _ref5 = _slicedToArray(_ref4, 2),
201
+ formId = _ref5[0],
202
+ rows = _ref5[1];
203
+ return [formId, Array.isArray(rows) ? rows.map(function (row) {
204
+ return [row.form_id, row.relation_id];
205
+ }) : null];
206
+ })]);
207
+ }
@@ -6,6 +6,7 @@ export * from './resources';
6
6
  export * from './resourceSelection';
7
7
  export * from './resourceErrors';
8
8
  export * from './productExtend';
9
+ export * from './calendarBooking';
9
10
  export * from './cacheItemToBookingInput';
10
11
  export * from './buildCacheItemFromOrderLine';
11
12
  export * from './buildNormalProductCacheItemFromOrderLine';
@@ -6,6 +6,7 @@ export * from "./resources";
6
6
  export * from "./resourceSelection";
7
7
  export * from "./resourceErrors";
8
8
  export * from "./productExtend";
9
+ export * from "./calendarBooking";
9
10
  export * from "./cacheItemToBookingInput";
10
11
  export * from "./buildCacheItemFromOrderLine";
11
12
  export * from "./buildNormalProductCacheItemFromOrderLine";
@@ -7,6 +7,12 @@ import { TimeSlicesResult, TimeSlice, DurationSlice } from './timeSlices';
7
7
  * 让 OS 这层完全可在 Node 单测下运行(dayjs 在 Node 也是纯函数)。
8
8
  */
9
9
  export interface BookingCalcContext {
10
+ /** Real runtime platform, injected by BookingTicket rather than inferred from sales channel. */
11
+ platform?: string;
12
+ bookingTimeRangeFromCalendar?: {
13
+ startAt: string;
14
+ endAt: string;
15
+ };
10
16
  /** Sales channel; remembered duration starts are accepted only by POS. */
11
17
  channel?: string;
12
18
  /** Current in-memory order session, supplied by the owning Order module. */
@@ -16,6 +16,7 @@ import { hasActualResourceSelection, productNeedsResourceExtend } from "./resour
16
16
  import { isMultiDayProduct, isSessionProduct, getDays, getServiceTimes } from "./serviceTimes";
17
17
  import { sliceDayIntoFiveMinutes, findNextDuration, getEndDate } from "./timeSlices";
18
18
  import { flexibleObj, getDurationValue, isProductFlexibleDuration } from "./flexible";
19
+ import { getCalendarBookingRange, prepareCalendarBookingCacheItem, calendarBookingNeedsInput, calendarBookingPreparationKey, calendarBookingEntryKey, isManualBookingProduct } from "./calendarBooking";
19
20
 
20
21
  /**
21
22
  * 上下文(与 info2 state.bookingConfig / state.service / state.date 一一对应)。
@@ -291,6 +292,26 @@ export function getServiceStartTimeAndEndTime(params) {
291
292
  export function getProductExtend(params) {
292
293
  var _cacheItem$_extend9;
293
294
  var isDisabledTime = params.isDisabledTime;
295
+ if (getCalendarBookingRange(params.cacheItem, params.ctx)) {
296
+ var _params$cacheItem$_da;
297
+ var prepared = prepareCalendarBookingCacheItem(params.cacheItem, params.ctx);
298
+ var capacity = setDefaultCapacitys({
299
+ capacitys: prepared.capacity,
300
+ cacheItem: prepared
301
+ });
302
+ return _objectSpread(_objectSpread({}, prepared), {}, {
303
+ _extend: _objectSpread(_objectSpread({}, prepared._extend), {}, {
304
+ capacity: capacity
305
+ }),
306
+ _data: _objectSpread(_objectSpread({}, prepared._data), {}, {
307
+ capacitys: prepared.capacity,
308
+ calendarManualBooking: ((_params$cacheItem$_da = params.cacheItem._data) === null || _params$cacheItem$_da === void 0 ? void 0 : _params$cacheItem$_da.calendarManualBooking) === true || isManualBookingProduct(params.cacheItem),
309
+ calendarBookingEntryKey: calendarBookingEntryKey(params.ctx),
310
+ calendarBookingPreparationKey: calendarBookingPreparationKey(prepared, params.ctx)
311
+ }),
312
+ autoClose: !calendarBookingNeedsInput(prepared)
313
+ });
314
+ }
294
315
  var hasRememberedTime = params.ctx.rememberedTime !== undefined;
295
316
  var cacheItem = hasRememberedTime ? seedRememberedBookingStart(params.cacheItem, params.ctx) : params.cacheItem;
296
317
  var ctx = hasRememberedTime ? _objectSpread(_objectSpread({}, params.ctx), {}, {
@@ -1191,6 +1191,20 @@ export function getDurationBusinessDate(projection, startAt) {
1191
1191
  });
1192
1192
  return (period === null || period === void 0 ? void 0 : period.businessDate) || startAt.slice(0, 10);
1193
1193
  }
1194
+ function getRequestedProductRange(projection, product, request, runtimeOptions, fixedOffsetMinutes) {
1195
+ var _request$requestedRan;
1196
+ var range = (_request$requestedRan = request.requestedRangesByProductId) === null || _request$requestedRan === void 0 ? void 0 : _request$requestedRan[String(product.id)];
1197
+ if (!runtimeOptions.allowRequestedRanges || !range || product.kind !== 'duration' && product.kind !== 'session') return [];
1198
+ var start = toDateTime(range.startAt);
1199
+ var end = toDateTime(range.endAt);
1200
+ if (!Number.isFinite(start) || !Number.isFinite(end) || !Number.isInteger((end - start) / 60000) || end <= start) {
1201
+ throw availabilityError('INVALID_TARGET_FILTER', '手工预约范围必须包含有效起止时间和正整数分钟时长');
1202
+ }
1203
+ var candidate = createDurationTimeRangeWithEnd(product, start, end, projection, fixedOffsetMinutes);
1204
+ candidate.businessDate = getDurationBusinessDate(projection, candidate.startAt);
1205
+ assertRangesWithinProjection(projection, [candidate]);
1206
+ return [candidate];
1207
+ }
1194
1208
  function getAlignedDurationRanges(params) {
1195
1209
  var _request$rememberedSt, _request$rememberedTi, _request$editingStart;
1196
1210
  var projection = params.projection,
@@ -1407,6 +1421,16 @@ export function getProductTimeRanges(projection) {
1407
1421
  return projection.products.filter(function (product) {
1408
1422
  return !filteredProductIdSet || filteredProductIdSet.has(String(product.id));
1409
1423
  }).map(function (product) {
1424
+ var requestedRanges = getRequestedProductRange(projection, product, request, runtimeOptions, fixedOffsetMinutes);
1425
+ if (requestedRanges.length > 0) {
1426
+ return {
1427
+ productId: product.id,
1428
+ title: product.title,
1429
+ kind: product.kind,
1430
+ slotStepMinutes: slotStepMinutes,
1431
+ ranges: dedupeProductRanges(requestedRanges)
1432
+ };
1433
+ }
1410
1434
  if (product.kind === 'normal') {
1411
1435
  return {
1412
1436
  productId: product.id,
@@ -263,6 +263,11 @@ export interface GetProductTimeRangesRequest {
263
263
  partySize?: number;
264
264
  durationMinutesByProductId?: Record<string, number>;
265
265
  durationStartTimesByProductId?: Record<string, string[]>;
266
+ /** Explicit POS manual interval. Endpoints are absolute datetimes, not business-day HH:mm. */
267
+ requestedRangesByProductId?: Record<string, {
268
+ startAt: string;
269
+ endAt: string;
270
+ }>;
266
271
  /** Restore only the exact remembered start; recompute the end from current product/windows. */
267
272
  rememberedStartAtByProductId?: Record<string, string>;
268
273
  /** Order-scoped v2 memory preserves the complete actual booking interval. */
@@ -300,6 +305,8 @@ export interface GetProductTimeRangesRuntimeOptions {
300
305
  * disabled.
301
306
  */
302
307
  allowSessionCustomRanges?: boolean;
308
+ /** Internal POS manual capability; automatic/remembered selections must leave this disabled. */
309
+ allowRequestedRanges?: boolean;
303
310
  /**
304
311
  * Internal POS capability: materialize candidates whose schedule date was
305
312
  * explicitly excluded, while availability evaluation keeps them unavailable.
@@ -6460,8 +6460,8 @@ var Server = /*#__PURE__*/function () {
6460
6460
  key: "syncMachinecodeRedeemStatusToLocalOrder",
6461
6461
  value: function () {
6462
6462
  var _syncMachinecodeRedeemStatusToLocalOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee65(data, ids, status) {
6463
- var _this$order5;
6464
- var title, lookup, localOrder, voucherIdSet, vouchers, hasUpdatedVoucher, nextVouchers;
6463
+ var _this$order5, _data$order_id2;
6464
+ var title, lookup, localOrder, orderId, voucherIdSet, vouchers, hasUpdatedVoucher, nextVouchers;
6465
6465
  return _regeneratorRuntime().wrap(function _callee65$(_context65) {
6466
6466
  while (1) switch (_context65.prev = _context65.next) {
6467
6467
  case 0:
@@ -6491,8 +6491,18 @@ var Server = /*#__PURE__*/function () {
6491
6491
  return this.order.getLocalOrderByLookup(lookup);
6492
6492
  case 10:
6493
6493
  localOrder = _context65.sent;
6494
+ orderId = (_data$order_id2 = data === null || data === void 0 ? void 0 : data.order_id) !== null && _data$order_id2 !== void 0 ? _data$order_id2 : data === null || data === void 0 ? void 0 : data.orderId;
6495
+ if (!(!localOrder && orderId !== undefined && orderId !== null && orderId !== '' && String(orderId) !== String(lookup))) {
6496
+ _context65.next = 16;
6497
+ break;
6498
+ }
6499
+ _context65.next = 15;
6500
+ return this.order.getLocalOrderByLookup(orderId);
6501
+ case 15:
6502
+ localOrder = _context65.sent;
6503
+ case 16:
6494
6504
  if (localOrder) {
6495
- _context65.next = 14;
6505
+ _context65.next = 19;
6496
6506
  break;
6497
6507
  }
6498
6508
  this.logWarning("".concat(title, ": \u672C\u5730\u8BA2\u5355\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u6838\u9500\u72B6\u6001\u66F4\u65B0"), {
@@ -6500,14 +6510,14 @@ var Server = /*#__PURE__*/function () {
6500
6510
  status: status
6501
6511
  });
6502
6512
  return _context65.abrupt("return");
6503
- case 14:
6513
+ case 19:
6504
6514
  voucherIdSet = new Set(ids.filter(function (id) {
6505
6515
  return id !== undefined && id !== null && id !== '';
6506
6516
  }).map(function (id) {
6507
6517
  return String(id);
6508
6518
  }));
6509
6519
  if (!(voucherIdSet.size === 0)) {
6510
- _context65.next = 18;
6520
+ _context65.next = 23;
6511
6521
  break;
6512
6522
  }
6513
6523
  this.logWarning("".concat(title, ": voucher ids \u7F3A\u5931\uFF0C\u8DF3\u8FC7\u672C\u5730\u8BA2\u5355\u6838\u9500\u72B6\u6001\u66F4\u65B0"), {
@@ -6515,7 +6525,7 @@ var Server = /*#__PURE__*/function () {
6515
6525
  status: status
6516
6526
  });
6517
6527
  return _context65.abrupt("return");
6518
- case 18:
6528
+ case 23:
6519
6529
  vouchers = Array.isArray(localOrder.vouchers) ? localOrder.vouchers : [];
6520
6530
  hasUpdatedVoucher = false;
6521
6531
  nextVouchers = vouchers.map(function (voucher) {
@@ -6528,7 +6538,7 @@ var Server = /*#__PURE__*/function () {
6528
6538
  });
6529
6539
  });
6530
6540
  if (hasUpdatedVoucher) {
6531
- _context65.next = 24;
6541
+ _context65.next = 29;
6532
6542
  break;
6533
6543
  }
6534
6544
  this.logWarning("".concat(title, ": \u672C\u5730\u8BA2\u5355\u672A\u547D\u4E2D\u4EFB\u4F55 voucher\uFF0C\u8DF3\u8FC7\u6838\u9500\u72B6\u6001\u66F4\u65B0"), {
@@ -6537,47 +6547,47 @@ var Server = /*#__PURE__*/function () {
6537
6547
  status: status
6538
6548
  });
6539
6549
  return _context65.abrupt("return");
6540
- case 24:
6550
+ case 29:
6541
6551
  if (!(typeof this.order.overwriteExistingOrder === 'function')) {
6542
- _context65.next = 29;
6552
+ _context65.next = 34;
6543
6553
  break;
6544
6554
  }
6545
- _context65.next = 27;
6555
+ _context65.next = 32;
6546
6556
  return this.order.overwriteExistingOrder(_objectSpread(_objectSpread({}, localOrder), {}, {
6547
6557
  vouchers: nextVouchers
6548
6558
  }));
6549
- case 27:
6559
+ case 32:
6550
6560
  this.logInfo("".concat(title, ": \u672C\u5730\u8BA2\u5355 vouchers \u6838\u9500\u72B6\u6001\u5DF2\u66F4\u65B0"), {
6551
6561
  lookup: lookup,
6552
6562
  updatedCount: voucherIdSet.size,
6553
6563
  status: status
6554
6564
  });
6555
6565
  return _context65.abrupt("return");
6556
- case 29:
6566
+ case 34:
6557
6567
  if (!(data !== null && data !== void 0 && data.external_sale_number && typeof this.order.markOrderSyncedByExternalSaleNumber === 'function')) {
6558
- _context65.next = 34;
6568
+ _context65.next = 39;
6559
6569
  break;
6560
6570
  }
6561
- _context65.next = 32;
6571
+ _context65.next = 37;
6562
6572
  return this.order.markOrderSyncedByExternalSaleNumber({
6563
6573
  externalSaleNumber: data.external_sale_number,
6564
6574
  patch: {
6565
6575
  vouchers: nextVouchers
6566
6576
  }
6567
6577
  });
6568
- case 32:
6578
+ case 37:
6569
6579
  this.logInfo("".concat(title, ": \u672C\u5730\u8BA2\u5355 vouchers \u6838\u9500\u72B6\u6001\u5DF2\u66F4\u65B0"), {
6570
6580
  lookup: lookup,
6571
6581
  updatedCount: voucherIdSet.size,
6572
6582
  status: status
6573
6583
  });
6574
6584
  return _context65.abrupt("return");
6575
- case 34:
6585
+ case 39:
6576
6586
  this.logWarning("".concat(title, ": Order \u6A21\u5757\u4E0D\u652F\u6301\u672C\u5730\u8BA2\u5355\u8986\u76D6\uFF0C\u8DF3\u8FC7\u6838\u9500\u72B6\u6001\u66F4\u65B0"), {
6577
6587
  lookup: lookup,
6578
6588
  status: status
6579
6589
  });
6580
- case 35:
6590
+ case 40:
6581
6591
  case "end":
6582
6592
  return _context65.stop();
6583
6593
  }
@@ -328,7 +328,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
328
328
  date: string;
329
329
  status: string;
330
330
  week: string;
331
- weekNum: 0 | 1 | 2 | 5 | 4 | 3 | 6;
331
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
332
332
  }[]>;
333
333
  submitTimeSlot(timeSlots: TimeSliceItem): void;
334
334
  private getScheduleDataByIds;
@@ -375,7 +375,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
375
375
  };
376
376
  setOtherData(key: string, value: any): void;
377
377
  getOtherData(key: string): any;
378
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
378
+ getProductTypeById(id: number): Promise<"duration" | "normal" | "session">;
379
379
  /**
380
380
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
381
381
  *
@@ -366,7 +366,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
366
366
  * 获取当前的客户搜索条件
367
367
  * @returns 当前搜索条件
368
368
  */
369
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
369
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
370
370
  /**
371
371
  * 获取客户列表状态(包含滚动加载相关状态)
372
372
  * @returns 客户状态
@@ -2740,7 +2740,8 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
2740
2740
  var _extra$date,
2741
2741
  _extra$presetStartTim,
2742
2742
  _this$getOrderSession,
2743
- _this8 = this;
2743
+ _this8 = this,
2744
+ _this$otherParams9;
2744
2745
  var state = this.store.bookingContext.getState();
2745
2746
  var date = (_extra$date = extra === null || extra === void 0 ? void 0 : extra.date) !== null && _extra$date !== void 0 ? _extra$date : state.date;
2746
2747
  return _objectSpread(_objectSpread({
@@ -2753,7 +2754,8 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
2753
2754
  orderSessionId: (_this$getOrderSession = this.getOrderSessionId()) !== null && _this$getOrderSession !== void 0 ? _this$getOrderSession : undefined,
2754
2755
  isOrderSessionCurrent: function isOrderSessionCurrent(sessionId) {
2755
2756
  return _this8.isOrderSessionCurrent(sessionId);
2756
- }
2757
+ },
2758
+ platform: String(((_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 ? void 0 : _this$otherParams9.platform) || '').trim().toLowerCase()
2757
2759
  });
2758
2760
  }
2759
2761
 
@@ -2855,7 +2857,8 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
2855
2857
  _this$store$order$get5,
2856
2858
  _extra$presetStartTim2,
2857
2859
  _this$getOrderSession2,
2858
- _this9 = this;
2860
+ _this9 = this,
2861
+ _this$otherParams10;
2859
2862
  var bookingContextState = this.store.bookingContext.getState();
2860
2863
  var date = (_extra$date2 = extra === null || extra === void 0 ? void 0 : extra.date) !== null && _extra$date2 !== void 0 ? _extra$date2 : bookingContextState.date;
2861
2864
  var orderCustomerId = (_ref14 = (_this$getOrderCustome4 = (_this$getOrderCustome5 = this.getOrderCustomerSnapshot()) === null || _this$getOrderCustome5 === void 0 ? void 0 : _this$getOrderCustome5.id) !== null && _this$getOrderCustome4 !== void 0 ? _this$getOrderCustome4 : (_this$store$order$get5 = this.store.order.getTempOrder()) === null || _this$store$order$get5 === void 0 ? void 0 : _this$store$order$get5.customer_id) !== null && _ref14 !== void 0 ? _ref14 : undefined;
@@ -2871,7 +2874,8 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
2871
2874
  orderSessionId: (_this$getOrderSession2 = this.getOrderSessionId()) !== null && _this$getOrderSession2 !== void 0 ? _this$getOrderSession2 : undefined,
2872
2875
  isOrderSessionCurrent: function isOrderSessionCurrent(sessionId) {
2873
2876
  return _this9.isOrderSessionCurrent(sessionId);
2874
- }
2877
+ },
2878
+ platform: String(((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform) || '').trim().toLowerCase()
2875
2879
  });
2876
2880
  }
2877
2881
 
@@ -41,6 +41,8 @@ export declare function decideAfterDetail(cacheItem: any, ctx?: AddProductDecide
41
41
  * @deprecated 请用 `decideAddProduct`;保留兼容:autoClose=true 仅表示可直接加车(action=add)。
42
42
  */
43
43
  export interface AddProductRequiresDetailPayload {
44
+ /** Same prepared decision cache supplied to the Host; never a separate Flow preflight. */
45
+ preparedCacheItem?: any;
44
46
  item: ProductData | Record<string, any>;
45
47
  /** UI 需展示的子弹窗开关。 */
46
48
  showConfig: {