@pisell/pisellos 2.3.171 → 2.3.173
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.
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/BookingContext/utils/productExtend.d.ts +5 -0
- package/dist/modules/BookingContext/utils/productExtend.js +61 -23
- package/dist/modules/OpenData/index.d.ts +1 -0
- package/dist/modules/OpenData/index.js +1 -0
- package/dist/modules/OpenData/salesSettings.d.ts +32 -0
- package/dist/modules/OpenData/salesSettings.js +80 -0
- package/dist/modules/OpenData/types.d.ts +13 -0
- package/dist/modules/Payment/walletpass.js +32 -6
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingTicket/index.d.ts +2 -2
- package/dist/solution/UnifiedBookingSales/index.d.ts +22 -1
- package/dist/solution/UnifiedBookingSales/index.js +910 -650
- package/dist/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
- package/dist/solution/UnifiedBookingSales/salesSettings.js +81 -0
- package/lib/model/strategy/adapter/promotion/index.js +46 -1
- package/lib/modules/BookingContext/utils/productExtend.d.ts +5 -0
- package/lib/modules/BookingContext/utils/productExtend.js +36 -3
- package/lib/modules/OpenData/index.d.ts +1 -0
- package/lib/modules/OpenData/index.js +12 -0
- package/lib/modules/OpenData/salesSettings.d.ts +32 -0
- package/lib/modules/OpenData/salesSettings.js +70 -0
- package/lib/modules/OpenData/types.d.ts +13 -0
- package/lib/modules/Payment/walletpass.js +23 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingTicket/index.d.ts +2 -2
- package/lib/solution/UnifiedBookingSales/index.d.ts +22 -1
- package/lib/solution/UnifiedBookingSales/index.js +128 -1
- package/lib/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
- package/lib/solution/UnifiedBookingSales/salesSettings.js +72 -0
- package/package.json +1 -1
|
@@ -36,6 +36,18 @@ var _pickupTiming = require("../../modules/Order/pickupTiming");
|
|
|
36
36
|
var _cacheItemToBookingInput = require("../../modules/BookingContext/utils/cacheItemToBookingInput");
|
|
37
37
|
var _utils = require("../../modules/BookingContext/utils");
|
|
38
38
|
var _OpenData = require("../../modules/OpenData");
|
|
39
|
+
var _salesSettings = require("./salesSettings");
|
|
40
|
+
Object.keys(_salesSettings).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
43
|
+
if (key in exports && exports[key] === _salesSettings[key]) return;
|
|
44
|
+
Object.defineProperty(exports, key, {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () {
|
|
47
|
+
return _salesSettings[key];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
39
51
|
var _getDateIsInSchedule = require("../../modules/Schedule/getDateIsInSchedule");
|
|
40
52
|
var _ResourcePlanner = require("../../modules/ResourcePlanner");
|
|
41
53
|
var _types = require("./types");
|
|
@@ -57,7 +69,7 @@ var _localClock = require("../../modules/ResourcePlanner/localClock");
|
|
|
57
69
|
var _platform = require("../../utils/platform");
|
|
58
70
|
var _itemRule = require("../../model/strategy/adapter/itemRule");
|
|
59
71
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
60
|
-
const OPEN_DATA_SECTION_CODES = ['sale', 'reservation', 'fulfillment', 'menu', 'workflow', 'documents', 'basic', 'checkout', 'availability'];
|
|
72
|
+
const OPEN_DATA_SECTION_CODES = ['sale', 'reservation', 'fulfillment', 'menu', 'workflow', 'documents', 'basic', 'checkout', 'availability', 'interface'];
|
|
61
73
|
function normalizePositiveInteger(value) {
|
|
62
74
|
const normalized = Number(value);
|
|
63
75
|
if (!Number.isInteger(normalized) || normalized <= 0) return undefined;
|
|
@@ -2038,6 +2050,121 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2038
2050
|
async getOpenData() {
|
|
2039
2051
|
return this.loadOpenDataConfig();
|
|
2040
2052
|
}
|
|
2053
|
+
|
|
2054
|
+
/** One policy snapshot for all Sales 2.0 consumers. Network errors must reach the caller. */
|
|
2055
|
+
async getSalesSettings() {
|
|
2056
|
+
const config = await this.getOpenData();
|
|
2057
|
+
if (!config) throw new Error('Sales settings are unavailable without a business context.');
|
|
2058
|
+
return (0, _OpenData.normalizeSalesSettings)(config, this.otherParams?.platform);
|
|
2059
|
+
}
|
|
2060
|
+
getLoadedSalesSettings() {
|
|
2061
|
+
if (!this.runtimeOpenDataSnapshot) {
|
|
2062
|
+
throw new Error('Sales settings are not loaded. Call getSalesSettings before preparing a booking.');
|
|
2063
|
+
}
|
|
2064
|
+
return (0, _OpenData.normalizeSalesSettings)(this.runtimeOpenDataSnapshot, this.otherParams?.platform);
|
|
2065
|
+
}
|
|
2066
|
+
getProductBookingsForScheduling() {
|
|
2067
|
+
const seen = new Set();
|
|
2068
|
+
return (this.getTempOrder()?.products || []).flatMap(product => {
|
|
2069
|
+
if (product.metadata?.product_add_schedule_time != null || product.deleted_at) return [];
|
|
2070
|
+
const booking = this.findLinkedBooking(product);
|
|
2071
|
+
if (!booking || (0, _pickupTiming.isFulfillmentTimingBooking)(booking) || seen.has(booking)) return [];
|
|
2072
|
+
seen.add(booking);
|
|
2073
|
+
return [booking];
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
shouldApplyMultipleBookingScheduling() {
|
|
2077
|
+
const platform = (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform);
|
|
2078
|
+
return platform === 'pos' || platform === 'webpos';
|
|
2079
|
+
}
|
|
2080
|
+
resolveLoadedDefaultBookingStart(holderIds, fallback) {
|
|
2081
|
+
// Customer channels keep their entry default instead of following cart bookings.
|
|
2082
|
+
// Keep this callback installed so BookingContext cannot fall back to Board.
|
|
2083
|
+
if (!this.shouldApplyMultipleBookingScheduling()) return (0, _salesSettings.normalizeBookingDateTime)(fallback);
|
|
2084
|
+
const settings = this.getLoadedSalesSettings();
|
|
2085
|
+
return (0, _salesSettings.resolveDefaultBookingStart)({
|
|
2086
|
+
bookings: this.getProductBookingsForScheduling(),
|
|
2087
|
+
holderIds,
|
|
2088
|
+
mode: settings.reservation.multipleBookingScheduling,
|
|
2089
|
+
fallback
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
/** Used by the SKU flow after Holder changes, without changing an explicit user-selected time. */
|
|
2094
|
+
async resolveDefaultBookingStart(params) {
|
|
2095
|
+
if (!this.shouldApplyMultipleBookingScheduling()) return (0, _salesSettings.normalizeBookingDateTime)(params.fallback);
|
|
2096
|
+
await this.getSalesSettings();
|
|
2097
|
+
return this.resolveLoadedDefaultBookingStart(params.holderIds, params.fallback);
|
|
2098
|
+
}
|
|
2099
|
+
buildBookingCalcContext(extra) {
|
|
2100
|
+
return {
|
|
2101
|
+
...super.buildBookingCalcContext(extra),
|
|
2102
|
+
resolveDefaultBookingStart: (cacheItem, fallback) => this.resolveLoadedDefaultBookingStart(extra?.holderIds ?? (0, _salesSettings.getBookingHolderIds)(cacheItem), fallback)
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
2105
|
+
buildAddProductCtx(extra) {
|
|
2106
|
+
return {
|
|
2107
|
+
...super.buildAddProductCtx(extra),
|
|
2108
|
+
resolveDefaultBookingStart: (cacheItem, fallback) => this.resolveLoadedDefaultBookingStart(extra?.holderIds ?? (0, _salesSettings.getBookingHolderIds)(cacheItem), fallback)
|
|
2109
|
+
};
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
/** Re-evaluate an automatic default after Holder enrichment, or restore a known explicit TimeBar start. */
|
|
2113
|
+
async applyDefaultBookingStart(cacheItem, options = {}) {
|
|
2114
|
+
if (!this.shouldApplyMultipleBookingScheduling()) return cacheItem;
|
|
2115
|
+
if (!cacheItem?.new || !(0, _utils.isBookingProduct)(cacheItem) || (0, _utils.isSessionProduct)(cacheItem) || cacheItem?._extend?.other?.session) return cacheItem;
|
|
2116
|
+
const extend = cacheItem._extend || {};
|
|
2117
|
+
const currentStart = (0, _salesSettings.getBookingBoundary)(extend, 'start');
|
|
2118
|
+
const automaticStart = (0, _salesSettings.normalizeBookingDateTime)(cacheItem._data?.salesDefaultBookingStart);
|
|
2119
|
+
if (extend.start_time && (!automaticStart || !currentStart || (0, _dayjs.default)(currentStart).valueOf() !== (0, _dayjs.default)(automaticStart).valueOf())) return cacheItem;
|
|
2120
|
+
const explicitStart = (0, _salesSettings.normalizeBookingDateTime)(options.explicitStart);
|
|
2121
|
+
if (options.explicitStart !== undefined && !explicitStart) {
|
|
2122
|
+
throw new Error('The explicit booking start must be a valid date and time.');
|
|
2123
|
+
}
|
|
2124
|
+
const holderIds = options.holderIds ?? (0, _salesSettings.getBookingHolderIds)(cacheItem);
|
|
2125
|
+
const fallback = (0, _salesSettings.normalizeBookingDateTime)(cacheItem._data?.salesDefaultBookingFallback) ?? currentStart ?? (0, _salesSettings.normalizeBookingDateTime)(String(this.getBookingDate() || ''));
|
|
2126
|
+
const nextStart = explicitStart ?? (await this.resolveDefaultBookingStart({
|
|
2127
|
+
holderIds,
|
|
2128
|
+
fallback
|
|
2129
|
+
}));
|
|
2130
|
+
if (!nextStart) return cacheItem;
|
|
2131
|
+
if (currentStart && (0, _dayjs.default)(nextStart).valueOf() === (0, _dayjs.default)(currentStart).valueOf()) {
|
|
2132
|
+
if (!explicitStart) return cacheItem;
|
|
2133
|
+
const data = {
|
|
2134
|
+
...cacheItem._data
|
|
2135
|
+
};
|
|
2136
|
+
delete data.salesDefaultBookingStart;
|
|
2137
|
+
delete data.salesDefaultBookingFallback;
|
|
2138
|
+
return {
|
|
2139
|
+
...cacheItem,
|
|
2140
|
+
_data: data
|
|
2141
|
+
};
|
|
2142
|
+
}
|
|
2143
|
+
const nextExtend = {
|
|
2144
|
+
...extend,
|
|
2145
|
+
start_date: nextStart.slice(0, 10),
|
|
2146
|
+
start_time: nextStart.slice(11)
|
|
2147
|
+
};
|
|
2148
|
+
for (const key of ['startDate', 'endDate', 'end_time', 'resource', 'resources', 'availabilitySelection']) {
|
|
2149
|
+
delete nextExtend[key];
|
|
2150
|
+
}
|
|
2151
|
+
if ((0, _utils.isMultiDayProduct)(cacheItem) && currentStart && extend.end_date) {
|
|
2152
|
+
const shiftDays = (0, _dayjs.default)(nextStart.slice(0, 10)).diff((0, _dayjs.default)(currentStart.slice(0, 10)), 'day');
|
|
2153
|
+
nextExtend.end_date = (0, _dayjs.default)(extend.end_date).add(shiftDays, 'day').format('YYYY-MM-DD');
|
|
2154
|
+
} else {
|
|
2155
|
+
delete nextExtend.end_date;
|
|
2156
|
+
}
|
|
2157
|
+
return this.getProductExtend({
|
|
2158
|
+
...cacheItem,
|
|
2159
|
+
_extend: nextExtend,
|
|
2160
|
+
_data: explicitStart ? {} : {
|
|
2161
|
+
salesDefaultBookingStart: nextStart,
|
|
2162
|
+
salesDefaultBookingFallback: fallback
|
|
2163
|
+
}
|
|
2164
|
+
}, {
|
|
2165
|
+
holderIds
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2041
2168
|
async loadPickupTimingOpenData(_force) {
|
|
2042
2169
|
const scope = this.getPickupTimingScope();
|
|
2043
2170
|
const businessCode = String(this.otherParams?.businessCode ?? this.otherParams?.business_code ?? '').trim();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MultipleBookingScheduling } from '../../modules/OpenData';
|
|
2
|
+
export interface ResolveDefaultBookingStartParams {
|
|
3
|
+
/** Product bookings in cart insertion order; unrelated order-level bookings are excluded by the facade. */
|
|
4
|
+
bookings: readonly Record<string, any>[];
|
|
5
|
+
holderIds?: unknown;
|
|
6
|
+
mode?: MultipleBookingScheduling;
|
|
7
|
+
fallback?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Normalize scalar/array holder identities without merging the no-holder group with real holders. */
|
|
10
|
+
export declare function normalizeBookingHolderIds(value: unknown): string[];
|
|
11
|
+
export declare function getBookingHolderIds(booking: Record<string, any>): string[];
|
|
12
|
+
/** Validate input and convert absolute ISO values to the runtime-local date/time used by booking fields. */
|
|
13
|
+
export declare function normalizeBookingDateTime(value: unknown): string | undefined;
|
|
14
|
+
export declare function getBookingBoundary(booking: Record<string, any>, edge: 'start' | 'end'): string | undefined;
|
|
15
|
+
/** Select a default only; availability and resource occupancy remain the commit path's authority. */
|
|
16
|
+
export declare function resolveDefaultBookingStart({ bookings, holderIds, mode, fallback, }: ResolveDefaultBookingStartParams): string | undefined;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getBookingBoundary = getBookingBoundary;
|
|
7
|
+
exports.getBookingHolderIds = getBookingHolderIds;
|
|
8
|
+
exports.normalizeBookingDateTime = normalizeBookingDateTime;
|
|
9
|
+
exports.normalizeBookingHolderIds = normalizeBookingHolderIds;
|
|
10
|
+
exports.resolveDefaultBookingStart = resolveDefaultBookingStart;
|
|
11
|
+
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
12
|
+
var _pickupTiming = require("../../modules/Order/pickupTiming");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
/** Normalize scalar/array holder identities without merging the no-holder group with real holders. */
|
|
15
|
+
function normalizeBookingHolderIds(value) {
|
|
16
|
+
const values = Array.isArray(value) ? value : value == null ? [] : [value];
|
|
17
|
+
return Array.from(new Set(values.flatMap(id => {
|
|
18
|
+
if (typeof id !== 'string' && typeof id !== 'number') return [];
|
|
19
|
+
const text = String(id).trim();
|
|
20
|
+
return text && text !== '0' ? [text] : [];
|
|
21
|
+
})));
|
|
22
|
+
}
|
|
23
|
+
function getBookingHolderIds(booking) {
|
|
24
|
+
return normalizeBookingHolderIds(booking.holder_id ?? booking.metadata?.holder_id ?? booking.holder?.form_record ?? booking.metadata?.holder?.form_record ?? booking._extend?.holder_id ?? booking._extend?.holder?.form_record);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Validate input and convert absolute ISO values to the runtime-local date/time used by booking fields. */
|
|
28
|
+
function normalizeBookingDateTime(value) {
|
|
29
|
+
if (typeof value !== 'string') return undefined;
|
|
30
|
+
const text = value.trim().replace(' ', 'T');
|
|
31
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,3})?)?(Z|[+-]\d{2}:\d{2})?$/.exec(text);
|
|
32
|
+
if (!match) return undefined;
|
|
33
|
+
const [, y, m, d, h, minute, second = '0', zone] = match;
|
|
34
|
+
const calendar = new Date(`${y}-${m}-${d}T00:00:00.000Z`);
|
|
35
|
+
if (!Number.isFinite(calendar.getTime()) || calendar.toISOString().slice(0, 10) !== `${y}-${m}-${d}` || Number(h) > 23 || Number(minute) > 59 || Number(second) > 59 || !(0, _dayjs.default)(text).isValid()) return undefined;
|
|
36
|
+
return zone ? (0, _dayjs.default)(text).format('YYYY-MM-DDTHH:mm:ss') : text;
|
|
37
|
+
}
|
|
38
|
+
function getBookingBoundary(booking, edge) {
|
|
39
|
+
const direct = booking[`${edge}At`] ?? booking[`${edge}_at`];
|
|
40
|
+
const directTime = normalizeBookingDateTime(direct);
|
|
41
|
+
if (directTime) return directTime;
|
|
42
|
+
const date = booking[`${edge}_date`];
|
|
43
|
+
const time = booking[`${edge}_time`];
|
|
44
|
+
if (typeof date !== 'string') return undefined;
|
|
45
|
+
return typeof time === 'string' ? normalizeBookingDateTime(`${date.slice(0, 10)}T${time}`) : normalizeBookingDateTime(date);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Select a default only; availability and resource occupancy remain the commit path's authority. */
|
|
49
|
+
function resolveDefaultBookingStart({
|
|
50
|
+
bookings,
|
|
51
|
+
holderIds,
|
|
52
|
+
mode = 'one_after_another',
|
|
53
|
+
fallback
|
|
54
|
+
}) {
|
|
55
|
+
const holders = new Set(normalizeBookingHolderIds(holderIds));
|
|
56
|
+
const related = bookings.flatMap(booking => {
|
|
57
|
+
if (!booking || (0, _pickupTiming.isFulfillmentTimingBooking)(booking) || booking.deleted_at) return [];
|
|
58
|
+
const previousHolders = getBookingHolderIds(booking);
|
|
59
|
+
const matches = holders.size === 0 ? previousHolders.length === 0 : previousHolders.some(holder => holders.has(holder));
|
|
60
|
+
if (!matches) return [];
|
|
61
|
+
const start = getBookingBoundary(booking, 'start');
|
|
62
|
+
const end = getBookingBoundary(booking, 'end');
|
|
63
|
+
if (!start || !end || !(0, _dayjs.default)(end).isAfter((0, _dayjs.default)(start))) return [];
|
|
64
|
+
return [{
|
|
65
|
+
start,
|
|
66
|
+
end
|
|
67
|
+
}];
|
|
68
|
+
});
|
|
69
|
+
if (!related.length) return normalizeBookingDateTime(fallback);
|
|
70
|
+
if (mode === 'same_start_time') return related[related.length - 1].start;
|
|
71
|
+
return related.reduce((latest, booking) => (0, _dayjs.default)(booking.end).isAfter((0, _dayjs.default)(latest)) ? booking.end : latest, related[0].end);
|
|
72
|
+
}
|