@pisell/pisellos 0.10.77 → 0.10.78
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/modules/Product/index.d.ts +1 -1
- package/dist/modules/ProductList/index.d.ts +2 -0
- package/dist/modules/ProductList/index.js +125 -39
- package/dist/modules/ResourcePlanner/planner.js +5 -0
- package/dist/solution/BaseSales/index.d.ts +12 -1
- package/dist/solution/BaseSales/index.js +275 -185
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingTicket/index.d.ts +1 -13
- package/dist/solution/UnifiedBookingSales/index.d.ts +23 -1
- package/dist/solution/UnifiedBookingSales/index.js +1307 -635
- package/dist/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
- package/dist/solution/UnifiedBookingSales/sessionResourceCache.js +271 -0
- package/dist/solution/UnifiedBookingSales/types.d.ts +25 -2
- package/dist/solution/UnifiedBookingSales/types.js +2 -0
- package/dist/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
- package/dist/solution/UnifiedBookingSales/venueCatalogSession.js +277 -0
- package/lib/model/strategy/adapter/promotion/index.js +46 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/ProductList/index.d.ts +2 -0
- package/lib/modules/ProductList/index.js +56 -0
- package/lib/modules/ResourcePlanner/planner.js +4 -0
- package/lib/solution/BaseSales/index.d.ts +12 -1
- package/lib/solution/BaseSales/index.js +65 -0
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingTicket/index.d.ts +1 -13
- package/lib/solution/UnifiedBookingSales/index.d.ts +23 -1
- package/lib/solution/UnifiedBookingSales/index.js +359 -5
- package/lib/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
- package/lib/solution/UnifiedBookingSales/sessionResourceCache.js +199 -0
- package/lib/solution/UnifiedBookingSales/types.d.ts +25 -2
- package/lib/solution/UnifiedBookingSales/types.js +1 -0
- package/lib/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
- package/lib/solution/UnifiedBookingSales/venueCatalogSession.js +151 -0
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ import { type InvoiceLayoutConfig, type InvoiceTemplateSettings, type OpenDataCo
|
|
|
6
6
|
import type { LoadScheduleAvailableDateParams, ScheduleItem } from '../../modules/Schedule/types';
|
|
7
7
|
import type { ProductListLoadProductsParams, ProductListStoreQueryParams } from '../../modules/ProductList';
|
|
8
8
|
import type { AvailabilityDateRange, AvailabilityOccupancy, AvailabilityProduct, AvailabilityResource, GetProductTimeRangesRequest } from '../../modules/ResourcePlanner';
|
|
9
|
-
import type { AvailabilityContextRef, ContextualAvailabilityQuery, ContextualAvailabilityQueryResult, ContextualCommitAvailabilitySelectionParams, ContextualProductTimeRangeGroup, UnifiedBookingSalesAddRetailProductParams, UnifiedBookingSalesCatalogQueryBatch, UnifiedBookingSalesApplyPlannerDiscountsParams, UnifiedBookingSalesCommitAvailabilitySelectionResult, UnifiedBookingSalesDiscountResult, UnifiedBookingSalesLoadProductsByScheduleDateParams, UnifiedBookingSalesLoadOpenDataParams, UnifiedBookingSalesPrepareAvailabilityProjectionParams, UnifiedBookingSalesPolicyResponse, UnifiedBookingSalesQueryBookingResourceDetailsParams, UnifiedBookingSalesResourceDetail, UnifiedBookingSalesResolveProductAllergyRequirementParams, UnifiedBookingSalesStageRetailProductsParams, UnifiedBookingSalesState } from './types';
|
|
9
|
+
import type { AvailabilityContextRef, ContextualAvailabilityQuery, ContextualAvailabilityQueryResult, ContextualCommitAvailabilitySelectionParams, ContextualProductTimeRangeGroup, UnifiedBookingSalesAddRetailProductParams, UnifiedBookingSalesCatalogQueryBatch, UnifiedBookingSalesVenueCatalogSession, UnifiedBookingSalesVenueCatalogSessionParams, UnifiedBookingSalesApplyPlannerDiscountsParams, UnifiedBookingSalesCommitAvailabilitySelectionResult, UnifiedBookingSalesDiscountResult, UnifiedBookingSalesLoadProductsByScheduleDateParams, UnifiedBookingSalesLoadOpenDataParams, UnifiedBookingSalesPrepareAvailabilityProjectionParams, UnifiedBookingSalesPolicyResponse, UnifiedBookingSalesQueryBookingResourceDetailsParams, UnifiedBookingSalesResourceDetail, UnifiedBookingSalesResolveProductAllergyRequirementParams, UnifiedBookingSalesStageRetailProductsParams, UnifiedBookingSalesState } from './types';
|
|
10
10
|
import type { BusinessAvailability } from '../../modules/BusinessAvailability';
|
|
11
11
|
import { BookingTicket } from '../BookingTicket';
|
|
12
12
|
import type { AllergyRequirement } from '../../model/strategy/adapter/itemRule';
|
|
@@ -74,6 +74,10 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
|
|
|
74
74
|
private runtimeInitializationGeneration;
|
|
75
75
|
private runtimeOpenDataDestroyed;
|
|
76
76
|
private unifiedProductCatalog;
|
|
77
|
+
private venueCatalogSessions;
|
|
78
|
+
private venueCatalogSessionKey?;
|
|
79
|
+
private venueCatalogMenus?;
|
|
80
|
+
private venueVariantDetails;
|
|
77
81
|
private availabilityRuntimeOffsetMinutes;
|
|
78
82
|
private availabilityScheduleCatalog;
|
|
79
83
|
private availabilityProjectionSequence;
|
|
@@ -84,6 +88,7 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
|
|
|
84
88
|
private availabilityPrepareInFlight;
|
|
85
89
|
private availabilityProjectionRefreshInFlight;
|
|
86
90
|
private availabilityRemoteOccupancyCache;
|
|
91
|
+
private availabilitySessionResourceCache;
|
|
87
92
|
private availabilityRemoteResourceQueryInFlight;
|
|
88
93
|
private availabilityRemoteResourceQuerySequence;
|
|
89
94
|
private availabilityRemoteResourceEpoch;
|
|
@@ -225,6 +230,23 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
|
|
|
225
230
|
queryCatalogProductDetail(params: ProductListLoadProductsParams & {
|
|
226
231
|
product_id: number;
|
|
227
232
|
}): Promise<ProductData | undefined>;
|
|
233
|
+
protected isVenueCatalogLocalPricingActive(): boolean;
|
|
234
|
+
protected getVenueCatalogLocalPriceSource(productId: number, selectedProduct?: Record<string, any>): {
|
|
235
|
+
product: Record<string, any>;
|
|
236
|
+
menuList: Record<string, any>[];
|
|
237
|
+
} | undefined;
|
|
238
|
+
getProductByIds(ids: number[], options?: {
|
|
239
|
+
loadMissing?: boolean;
|
|
240
|
+
}): Promise<ProductData[]>;
|
|
241
|
+
private getVenueCatalogHydratedProduct;
|
|
242
|
+
/** Explicit user opening for legacy promotion/gift SKU hosts. Pure readers never call this. */
|
|
243
|
+
prepareVenueCatalogProductDetail(params: {
|
|
244
|
+
product_id: number;
|
|
245
|
+
retry?: boolean;
|
|
246
|
+
}): Promise<ProductData | undefined>;
|
|
247
|
+
private hydrateVenueVariantDetail;
|
|
248
|
+
/** One complete raw product query per explicitly configured pool for this page lifetime. */
|
|
249
|
+
createVenueCatalogSession(params: UnifiedBookingSalesVenueCatalogSessionParams): UnifiedBookingSalesVenueCatalogSession;
|
|
228
250
|
/**
|
|
229
251
|
* Opt-in calendar/card preview batching. Results expire after sixty seconds or a
|
|
230
252
|
* runtime change; the next read starts a fresh clock/cache. Selection and submit
|
|
@@ -63,8 +63,10 @@ Object.keys(_types).forEach(function (key) {
|
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
var _remoteOccupancyCache = require("./remoteOccupancyCache");
|
|
66
|
+
var _sessionResourceCache = require("./sessionResourceCache");
|
|
66
67
|
var _businessAvailability = require("./businessAvailability");
|
|
67
68
|
var _catalogQueryBatch = require("./catalogQueryBatch");
|
|
69
|
+
var _venueCatalogSession = require("./venueCatalogSession");
|
|
68
70
|
var _BookingTicket = require("../BookingTicket");
|
|
69
71
|
var _localClock = require("../../modules/ResourcePlanner/localClock");
|
|
70
72
|
var _platform = require("../../utils/platform");
|
|
@@ -1229,6 +1231,10 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1229
1231
|
runtimeInitializationGeneration = 0;
|
|
1230
1232
|
runtimeOpenDataDestroyed = false;
|
|
1231
1233
|
unifiedProductCatalog = [];
|
|
1234
|
+
venueCatalogSessions = new Set();
|
|
1235
|
+
venueCatalogSessionKey;
|
|
1236
|
+
venueCatalogMenus;
|
|
1237
|
+
venueVariantDetails = new Map();
|
|
1232
1238
|
availabilityRuntimeOffsetMinutes = null;
|
|
1233
1239
|
availabilityScheduleCatalog = null;
|
|
1234
1240
|
availabilityProjectionSequence = 0;
|
|
@@ -1239,6 +1245,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1239
1245
|
availabilityPrepareInFlight = new Map();
|
|
1240
1246
|
availabilityProjectionRefreshInFlight = new Map();
|
|
1241
1247
|
availabilityRemoteOccupancyCache = new _remoteOccupancyCache.AvailabilityRemoteOccupancyCache(MAX_REMOTE_OCCUPANCY_RESOURCE_DATE_CELLS);
|
|
1248
|
+
availabilitySessionResourceCache = new _sessionResourceCache.AvailabilitySessionResourceCache();
|
|
1242
1249
|
availabilityRemoteResourceQueryInFlight = new Map();
|
|
1243
1250
|
availabilityRemoteResourceQuerySequence = 0;
|
|
1244
1251
|
availabilityRemoteResourceEpoch = 0;
|
|
@@ -1435,6 +1442,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1435
1442
|
clearAvailabilityRemoteResourceState() {
|
|
1436
1443
|
this.availabilityRemoteResourceEpoch += 1;
|
|
1437
1444
|
this.availabilityRemoteOccupancyCache.clear();
|
|
1445
|
+
this.availabilitySessionResourceCache.clear();
|
|
1438
1446
|
this.availabilityRemoteResourceQueryInFlight.clear();
|
|
1439
1447
|
this.availabilityRemoteResourceQuerySequence = 0;
|
|
1440
1448
|
}
|
|
@@ -2215,6 +2223,319 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2215
2223
|
async queryCatalogProductDetail(params) {
|
|
2216
2224
|
return this.loadCatalogProductDetail(params, query => this.queryCatalogSnapshot(query));
|
|
2217
2225
|
}
|
|
2226
|
+
isVenueCatalogLocalPricingActive() {
|
|
2227
|
+
return this.venueCatalogSessions.size > 0;
|
|
2228
|
+
}
|
|
2229
|
+
getVenueCatalogLocalPriceSource(productId, selectedProduct) {
|
|
2230
|
+
const scope = this.getRuntimeOpenDataScope();
|
|
2231
|
+
const role = selectedProduct?.metadata?.venue_booking_role;
|
|
2232
|
+
const poolRole = role === 'party_extra' || role === 'tickets_extra' ? 'extras' : role === 'party_main' || role === 'tickets' ? 'main' : undefined;
|
|
2233
|
+
const matches = Array.from(this.venueCatalogSessions).filter(entry => entry.scope === scope && entry.generation === this.runtimeInitializationGeneration && (!poolRole || entry.role === poolRole) && entry.pool?.products.some(row => Number(row.id) === productId));
|
|
2234
|
+
if (!matches.length) return undefined;
|
|
2235
|
+
const pool = matches[0].pool;
|
|
2236
|
+
const product = this.getVenueCatalogHydratedProduct(pool.products.find(row => Number(row.id) === productId));
|
|
2237
|
+
// Legacy promotion/gift inputs may have no venue role. Equivalent complete
|
|
2238
|
+
// sources are unambiguous; different pool snapshots must never use Set order.
|
|
2239
|
+
if (matches.slice(1).some(entry => !(0, _lodashEs.isEqual)(product, this.getVenueCatalogHydratedProduct(entry.pool.products.find(row => Number(row.id) === productId))) || !(0, _lodashEs.isEqual)(pool.pricingMenus, entry.pool.pricingMenus))) return undefined;
|
|
2240
|
+
return {
|
|
2241
|
+
product: (0, _lodashEs.cloneDeep)(product),
|
|
2242
|
+
menuList: (0, _lodashEs.cloneDeep)(pool.pricingMenus)
|
|
2243
|
+
};
|
|
2244
|
+
}
|
|
2245
|
+
async getProductByIds(ids, options) {
|
|
2246
|
+
const active = this.isVenueCatalogLocalPricingActive();
|
|
2247
|
+
const products = await super.getProductByIds(ids, active ? {
|
|
2248
|
+
loadMissing: false
|
|
2249
|
+
} : options);
|
|
2250
|
+
return active ? products.map(product => this.getVenueCatalogHydratedProduct(product)) : products;
|
|
2251
|
+
}
|
|
2252
|
+
getVenueCatalogHydratedProduct(product) {
|
|
2253
|
+
const variants = this.venueVariantDetails.get(Number(product.id ?? product.product_id))?.data;
|
|
2254
|
+
return variants ? {
|
|
2255
|
+
...(0, _lodashEs.cloneDeep)(product),
|
|
2256
|
+
variant: (0, _lodashEs.cloneDeep)(variants)
|
|
2257
|
+
} : (0, _lodashEs.cloneDeep)(product);
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
/** Explicit user opening for legacy promotion/gift SKU hosts. Pure readers never call this. */
|
|
2261
|
+
async prepareVenueCatalogProductDetail(params) {
|
|
2262
|
+
if (!this.isVenueCatalogLocalPricingActive()) throw (0, _venueCatalogSession.venueCatalogError)('VENUE_CATALOG_REQUIRED', 'Open a venue catalog before configuring this product.');
|
|
2263
|
+
const owner = this.venueCatalogSessionKey;
|
|
2264
|
+
const scope = this.getRuntimeOpenDataScope();
|
|
2265
|
+
const generation = this.runtimeInitializationGeneration;
|
|
2266
|
+
const source = this.getVenueCatalogLocalPriceSource(params.product_id);
|
|
2267
|
+
if (!source) return undefined;
|
|
2268
|
+
await this.hydrateVenueVariantDetail(source.product, params);
|
|
2269
|
+
if (this.runtimeOpenDataDestroyed || !this.isVenueCatalogLocalPricingActive() || owner !== this.venueCatalogSessionKey || scope !== this.getRuntimeOpenDataScope() || generation !== this.runtimeInitializationGeneration) {
|
|
2270
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_CATALOG_STALE', 'The venue catalog changed while loading product options.');
|
|
2271
|
+
}
|
|
2272
|
+
return this.getVenueCatalogHydratedProduct(source.product);
|
|
2273
|
+
}
|
|
2274
|
+
async hydrateVenueVariantDetail(raw, params) {
|
|
2275
|
+
// is_variant is the backend's explicit gate. Ordinary retail never requests detail.
|
|
2276
|
+
if (Number(raw.is_variant) !== 1) return;
|
|
2277
|
+
const count = Number(raw.variant_count) || 0;
|
|
2278
|
+
if (Array.isArray(raw.variant) && raw.variant.length > 0 && raw.variant.length >= count) return;
|
|
2279
|
+
const productId = Number(raw.id ?? raw.product_id);
|
|
2280
|
+
let entry = this.venueVariantDetails.get(productId);
|
|
2281
|
+
if (entry?.failed && params.retry === true) {
|
|
2282
|
+
this.venueVariantDetails.delete(productId);
|
|
2283
|
+
entry = undefined;
|
|
2284
|
+
}
|
|
2285
|
+
if (!entry) {
|
|
2286
|
+
const owner = this.venueCatalogSessionKey;
|
|
2287
|
+
const scope = this.getRuntimeOpenDataScope();
|
|
2288
|
+
const generation = this.runtimeInitializationGeneration;
|
|
2289
|
+
const core = this.core;
|
|
2290
|
+
const request = this.request;
|
|
2291
|
+
const next = {
|
|
2292
|
+
promise: Promise.resolve([])
|
|
2293
|
+
};
|
|
2294
|
+
const assertCurrent = () => {
|
|
2295
|
+
if (this.runtimeOpenDataDestroyed || !this.isVenueCatalogLocalPricingActive() || owner !== this.venueCatalogSessionKey || scope !== this.getRuntimeOpenDataScope() || generation !== this.runtimeInitializationGeneration || core !== this.core || request !== this.request || this.venueVariantDetails.get(productId) !== next) {
|
|
2296
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_CATALOG_STALE', 'The venue catalog changed while loading product options.');
|
|
2297
|
+
}
|
|
2298
|
+
};
|
|
2299
|
+
this.venueVariantDetails.set(productId, next);
|
|
2300
|
+
next.promise = Promise.resolve().then(async () => {
|
|
2301
|
+
assertCurrent();
|
|
2302
|
+
const response = await request.get(`/product/show/${productId}`, {
|
|
2303
|
+
open_bundle: 1,
|
|
2304
|
+
with_schedule: 1,
|
|
2305
|
+
is_eject: 1,
|
|
2306
|
+
with: [..._clientDataVariants.PRODUCT_QUERY_DATA_VARIANT_RELATIONS]
|
|
2307
|
+
}, {
|
|
2308
|
+
useCache: false,
|
|
2309
|
+
customToast: () => {}
|
|
2310
|
+
});
|
|
2311
|
+
assertCurrent();
|
|
2312
|
+
if (response?.status === false || response?.code != null && Number(response.code) !== 200) {
|
|
2313
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_VARIANT_DETAIL_FAILED', response?.message || 'Product options could not be loaded.');
|
|
2314
|
+
}
|
|
2315
|
+
const detail = response?.data?.item ?? response?.data;
|
|
2316
|
+
if (Number(detail?.id ?? detail?.product_id) !== productId || !Array.isArray(detail?.variant) || !detail.variant.length || detail.variant.length < count) {
|
|
2317
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_VARIANT_DETAIL_INCOMPLETE', 'Complete product variants are unavailable. Please retry.');
|
|
2318
|
+
}
|
|
2319
|
+
const variants = detail.variant.map(value => {
|
|
2320
|
+
const variant = (0, _lodashEs.cloneDeep)(value);
|
|
2321
|
+
const original = variant._dataVariant?.original;
|
|
2322
|
+
const evaluated = variant._dataVariant || Array.isArray(variant.metadata?.data_variant_ids);
|
|
2323
|
+
const basePrice = original?.price ?? original?.base_price ?? variant.base_price ?? (evaluated ? undefined : variant.price);
|
|
2324
|
+
if (!Number.isSafeInteger(Number(variant.id)) || Number(variant.id) <= 0 || basePrice === undefined || basePrice === null || basePrice === '' || !Number.isFinite(Number(basePrice))) {
|
|
2325
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_VARIANT_DETAIL_INCOMPLETE', 'The base price for a product variant is unavailable.');
|
|
2326
|
+
}
|
|
2327
|
+
// Copy only combination SKU data. The pool's price/data_variants and
|
|
2328
|
+
// pricing metadata remain its original baseline for every later context.
|
|
2329
|
+
variant.price = basePrice;
|
|
2330
|
+
variant.base_price = basePrice;
|
|
2331
|
+
if (variant.selling_price !== undefined) variant.selling_price = basePrice;
|
|
2332
|
+
delete variant._dataVariant;
|
|
2333
|
+
if (variant.metadata) delete variant.metadata.data_variant_ids;
|
|
2334
|
+
return variant;
|
|
2335
|
+
});
|
|
2336
|
+
next.data = variants;
|
|
2337
|
+
for (const pool of this.venueCatalogSessions) {
|
|
2338
|
+
if (pool.scope !== scope || !pool.pool) continue;
|
|
2339
|
+
const product = pool.pool.products.find(row => Number(row.id) === productId);
|
|
2340
|
+
if (!product) continue;
|
|
2341
|
+
const hydrated = this.getVenueCatalogHydratedProduct(product);
|
|
2342
|
+
this.store.products?.rememberRawProductQueryResult?.([(0, _lodashEs.cloneDeep)(hydrated)]);
|
|
2343
|
+
this.store.products?.addProduct?.([(0, _lodashEs.cloneDeep)(hydrated)]);
|
|
2344
|
+
}
|
|
2345
|
+
return variants;
|
|
2346
|
+
}).catch(error => {
|
|
2347
|
+
next.failed = true;
|
|
2348
|
+
throw error;
|
|
2349
|
+
});
|
|
2350
|
+
entry = next;
|
|
2351
|
+
}
|
|
2352
|
+
await entry.promise;
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
/** One complete raw product query per explicitly configured pool for this page lifetime. */
|
|
2356
|
+
createVenueCatalogSession(params) {
|
|
2357
|
+
if (!(0, _platform.isCustomerUserPlatform)(this.otherParams?.platform)) {
|
|
2358
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_CATALOG_PLATFORM_UNSUPPORTED', 'Venue catalog sessions require a customer platform.');
|
|
2359
|
+
}
|
|
2360
|
+
const ids = params.menu_list_ids;
|
|
2361
|
+
if (!Array.isArray(ids) || !ids.length || ids.some(id => !Number.isSafeInteger(id) || id <= 0)) {
|
|
2362
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_MENU_REQUIRED', 'Choose an explicit menu for this venue product pool.');
|
|
2363
|
+
}
|
|
2364
|
+
const menuIds = [...new Set(ids)].sort((a, b) => a - b);
|
|
2365
|
+
const scope = this.getRuntimeOpenDataScope();
|
|
2366
|
+
const generation = this.runtimeInitializationGeneration;
|
|
2367
|
+
const core = this.core;
|
|
2368
|
+
const request = this.request;
|
|
2369
|
+
const entry = {
|
|
2370
|
+
scope,
|
|
2371
|
+
generation,
|
|
2372
|
+
role: params.poolRole
|
|
2373
|
+
};
|
|
2374
|
+
const sessionKey = JSON.stringify([scope, generation, params.sessionKey ?? null]);
|
|
2375
|
+
if (!this.venueCatalogSessions.size || sessionKey !== this.venueCatalogSessionKey) {
|
|
2376
|
+
// React may create new page pools before disposing the old page's pools.
|
|
2377
|
+
// The explicit session identity prevents reusing old-order occupancy then.
|
|
2378
|
+
this.venueCatalogSessions.clear();
|
|
2379
|
+
this.venueCatalogSessionKey = sessionKey;
|
|
2380
|
+
this.venueCatalogMenus = undefined;
|
|
2381
|
+
this.venueVariantDetails.clear();
|
|
2382
|
+
this.availabilitySessionResourceCache.clear();
|
|
2383
|
+
}
|
|
2384
|
+
this.venueCatalogSessions.add(entry);
|
|
2385
|
+
const assertCurrent = () => {
|
|
2386
|
+
if (!this.venueCatalogSessions.has(entry)) {
|
|
2387
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_CATALOG_DISPOSED', 'The venue catalog session is closed.');
|
|
2388
|
+
}
|
|
2389
|
+
if (this.runtimeOpenDataDestroyed || this.core !== core || this.request !== request || generation !== this.runtimeInitializationGeneration || scope !== this.getRuntimeOpenDataScope()) {
|
|
2390
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_CATALOG_STALE', 'The venue store context changed. Reopen the booking page.');
|
|
2391
|
+
}
|
|
2392
|
+
};
|
|
2393
|
+
const now = () => {
|
|
2394
|
+
const timezone = String(this.otherParams?.businessTimezone || this.getPickupTimingContextData('timezone') || '').trim();
|
|
2395
|
+
if (!timezone) throw (0, _venueCatalogSession.venueCatalogError)('VENUE_TIMEZONE_REQUIRED', 'The venue timezone is not ready.');
|
|
2396
|
+
const parts = new Intl.DateTimeFormat('en-GB', {
|
|
2397
|
+
timeZone: timezone,
|
|
2398
|
+
year: 'numeric',
|
|
2399
|
+
month: '2-digit',
|
|
2400
|
+
day: '2-digit',
|
|
2401
|
+
hour: '2-digit',
|
|
2402
|
+
minute: '2-digit',
|
|
2403
|
+
second: '2-digit',
|
|
2404
|
+
hourCycle: 'h23'
|
|
2405
|
+
}).formatToParts(new Date());
|
|
2406
|
+
const part = type => parts.find(item => item.type === type)?.value;
|
|
2407
|
+
return `${part('year')}-${part('month')}-${part('day')} ${part('hour')}:${part('minute')}:${part('second')}`;
|
|
2408
|
+
};
|
|
2409
|
+
const snapshot = (pool, input) => {
|
|
2410
|
+
assertCurrent();
|
|
2411
|
+
if (input.menu_list_ids && JSON.stringify([...new Set(input.menu_list_ids)].sort((a, b) => a - b)) !== JSON.stringify(menuIds)) {
|
|
2412
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_MENU_SCOPE_CHANGED', 'This catalog session belongs to another menu.');
|
|
2413
|
+
}
|
|
2414
|
+
const current = now();
|
|
2415
|
+
const datetime = input.schedule_datetime || (input.schedule_date ? `${input.schedule_date} ${current.slice(11)}` : current);
|
|
2416
|
+
if (!(0, _localClock.parseLocalDateTime)(datetime.replace('T', ' ')) || input.schedule_date && datetime.slice(0, 10) !== input.schedule_date) {
|
|
2417
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_CATALOG_DATETIME_INVALID', 'Choose a valid venue catalog date and time.');
|
|
2418
|
+
}
|
|
2419
|
+
const menus = (0, _venueCatalogSession.activeVenueMenus)(pool.menus, this.getAvailabilityScheduleCatalog(), datetime, Boolean(input.schedule_date && !input.schedule_datetime));
|
|
2420
|
+
let products = pool.products.filter(product => menus.some(menu => (0, _venueCatalogSession.productMatchesVenueMenu)(product, menu))).map(product => this.getVenueCatalogHydratedProduct(product));
|
|
2421
|
+
if (input.product_ids?.length) products = products.filter(product => input.product_ids.some(id => Number(id) === Number(product.id)));
|
|
2422
|
+
const user = this.core.getPlugin?.('user');
|
|
2423
|
+
const queryPayload = {
|
|
2424
|
+
schedule_date: datetime.slice(0, 10),
|
|
2425
|
+
schedule_datetime: datetime,
|
|
2426
|
+
customer_id: input.customer_id ?? this.getTempOrder()?.customer_id ?? user?.get?.()?.id,
|
|
2427
|
+
strategy_context: {
|
|
2428
|
+
...this.getPriceQueryStrategyContext(),
|
|
2429
|
+
...(input.strategy_context || {})
|
|
2430
|
+
}
|
|
2431
|
+
};
|
|
2432
|
+
const result = (0, _clientDataVariants.tryResolveClientDataVariants)({
|
|
2433
|
+
core: this.core,
|
|
2434
|
+
otherParams: this.otherParams,
|
|
2435
|
+
products: (0, _lodashEs.cloneDeep)(products),
|
|
2436
|
+
queryPayload,
|
|
2437
|
+
handledByOsServer: false,
|
|
2438
|
+
scheduleList: this.getAvailabilityScheduleCatalog(),
|
|
2439
|
+
menuList: pool.pricingMenus
|
|
2440
|
+
});
|
|
2441
|
+
if (result.status !== 'resolved' && result.status !== 'empty') {
|
|
2442
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_LOCAL_PRICE_UNAVAILABLE', 'Complete product pricing rules are not ready. Please retry.');
|
|
2443
|
+
}
|
|
2444
|
+
return result.products.slice().sort((a, b) => Number(b.sort || 0) - Number(a.sort || 0));
|
|
2445
|
+
};
|
|
2446
|
+
return (0, _venueCatalogSession.createVenueCatalogSessionAdapter)({
|
|
2447
|
+
assertCurrent,
|
|
2448
|
+
load: async () => {
|
|
2449
|
+
if (!this.venueCatalogMenus || this.venueCatalogMenus.scope !== scope) {
|
|
2450
|
+
const promise = request.get('/form/data/v1', {
|
|
2451
|
+
skip: 1,
|
|
2452
|
+
num: 999,
|
|
2453
|
+
code: 'menu_list'
|
|
2454
|
+
}, {
|
|
2455
|
+
useCache: false,
|
|
2456
|
+
customToast: () => {}
|
|
2457
|
+
}).then(response => (0, _venueCatalogSession.readVenueCatalogList)(response, 'Venue menus'));
|
|
2458
|
+
this.venueCatalogMenus = {
|
|
2459
|
+
scope,
|
|
2460
|
+
promise
|
|
2461
|
+
};
|
|
2462
|
+
void promise.catch(() => {
|
|
2463
|
+
if (this.venueCatalogMenus?.promise === promise) this.venueCatalogMenus = undefined;
|
|
2464
|
+
});
|
|
2465
|
+
}
|
|
2466
|
+
const pricingMenus = await this.venueCatalogMenus.promise;
|
|
2467
|
+
const menus = (0, _venueCatalogSession.validateVenueMenus)(pricingMenus, menuIds);
|
|
2468
|
+
assertCurrent();
|
|
2469
|
+
// A menu query with a date may exclude future members. Read the raw ID union
|
|
2470
|
+
// without menu/time/customer pricing filters, then filter collection/all menus locally.
|
|
2471
|
+
const onlyIds = menus.every(menu => menu.partyroom_package.type === 'products');
|
|
2472
|
+
const onlyCollections = menus.every(menu => menu.partyroom_package.type === 'product_collection');
|
|
2473
|
+
const productIds = onlyIds ? [...new Set(menus.flatMap(menu => menu.partyroom_package.products.map(product => Number(product.product_id))))] : undefined;
|
|
2474
|
+
const collections = onlyCollections ? [...new Set(menus.flatMap(menu => menu.partyroom_package.products.map(product => String(product.product_collection_id))))] : undefined;
|
|
2475
|
+
const products = onlyIds && !productIds?.length ? [] : await this.store.products.loadVenueCatalogPool({
|
|
2476
|
+
product_ids: productIds,
|
|
2477
|
+
collection: collections,
|
|
2478
|
+
category_ids: params.category_ids,
|
|
2479
|
+
extension_type: params.extension_type,
|
|
2480
|
+
cacheId: this.cacheId
|
|
2481
|
+
});
|
|
2482
|
+
assertCurrent();
|
|
2483
|
+
const pool = {
|
|
2484
|
+
menus,
|
|
2485
|
+
pricingMenus: (0, _lodashEs.cloneDeep)(pricingMenus),
|
|
2486
|
+
products: products.filter(product => menus.some(menu => (0, _venueCatalogSession.productMatchesVenueMenu)(product, menu)))
|
|
2487
|
+
};
|
|
2488
|
+
entry.pool = (0, _lodashEs.cloneDeep)(pool);
|
|
2489
|
+
// Legacy marketing lookups can reuse complete records without changing
|
|
2490
|
+
// either pool's membership or publishing a replacement sales catalog.
|
|
2491
|
+
this.store.products.rememberRawProductQueryResult((0, _lodashEs.cloneDeep)(pool.products));
|
|
2492
|
+
this.store.products.addProduct((0, _lodashEs.cloneDeep)(pool.products));
|
|
2493
|
+
return pool;
|
|
2494
|
+
},
|
|
2495
|
+
snapshot,
|
|
2496
|
+
prepareDetail: async (pool, query) => {
|
|
2497
|
+
const raw = pool.products.find(product => Number(product.id) === Number(query.product_id));
|
|
2498
|
+
if (raw) await this.hydrateVenueVariantDetail(raw, query);
|
|
2499
|
+
assertCurrent();
|
|
2500
|
+
},
|
|
2501
|
+
quote: async (pool, query) => {
|
|
2502
|
+
const product = query.product;
|
|
2503
|
+
const productId = Number(product?.product_id ?? product?.id);
|
|
2504
|
+
const booking = query.booking;
|
|
2505
|
+
const datetime = booking?.start_date ? `${booking.start_date} ${booking.start_time || '00:00:00'}` : query.datetime || now();
|
|
2506
|
+
if (!snapshot(pool, {
|
|
2507
|
+
product_ids: [productId],
|
|
2508
|
+
schedule_datetime: datetime,
|
|
2509
|
+
customer_id: query.customer_id == null ? undefined : Number(query.customer_id)
|
|
2510
|
+
}).length) {
|
|
2511
|
+
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_PRODUCT_UNAVAILABLE', 'This product is unavailable in the selected menu at this time.');
|
|
2512
|
+
}
|
|
2513
|
+
const raw = pool.products.find(row => Number(row.id) === productId);
|
|
2514
|
+
if (!raw) throw (0, _venueCatalogSession.venueCatalogError)('VENUE_PRODUCT_UNAVAILABLE', 'This product is not in the venue catalog.');
|
|
2515
|
+
const result = await this.calculateVenueCatalogProductBookingPrice({
|
|
2516
|
+
...query,
|
|
2517
|
+
datetime
|
|
2518
|
+
}, {
|
|
2519
|
+
product: this.getVenueCatalogHydratedProduct(raw),
|
|
2520
|
+
menuList: pool.pricingMenus
|
|
2521
|
+
});
|
|
2522
|
+
assertCurrent();
|
|
2523
|
+
return result;
|
|
2524
|
+
},
|
|
2525
|
+
onRetry: () => {
|
|
2526
|
+
for (const [id, detail] of this.venueVariantDetails) if (detail.failed) this.venueVariantDetails.delete(id);
|
|
2527
|
+
},
|
|
2528
|
+
onDispose: () => {
|
|
2529
|
+
this.venueCatalogSessions.delete(entry);
|
|
2530
|
+
if (!this.venueCatalogSessions.size) {
|
|
2531
|
+
this.venueCatalogSessionKey = undefined;
|
|
2532
|
+
this.venueCatalogMenus = undefined;
|
|
2533
|
+
this.venueVariantDetails.clear();
|
|
2534
|
+
this.availabilitySessionResourceCache.clear();
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
});
|
|
2538
|
+
}
|
|
2218
2539
|
|
|
2219
2540
|
/**
|
|
2220
2541
|
* Opt-in calendar/card preview batching. Results expire after sixty seconds or a
|
|
@@ -2812,7 +3133,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2812
3133
|
};
|
|
2813
3134
|
}
|
|
2814
3135
|
assertAvailabilityPrepareParams(params) {
|
|
2815
|
-
if (params.occupancyCachePolicy !== undefined && params.occupancyCachePolicy !== 'cache_first') {
|
|
3136
|
+
if (params.occupancyCachePolicy !== undefined && params.occupancyCachePolicy !== 'cache_first' && params.occupancyCachePolicy !== 'session') {
|
|
2816
3137
|
throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', 'Unknown occupancyCachePolicy');
|
|
2817
3138
|
}
|
|
2818
3139
|
assertAvailabilityCatalogProductIds(params.productIds, 'prepare.productIds');
|
|
@@ -3025,12 +3346,26 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
3025
3346
|
}
|
|
3026
3347
|
};
|
|
3027
3348
|
assertCurrent();
|
|
3028
|
-
const
|
|
3349
|
+
const resourceQuery = {
|
|
3029
3350
|
dateRange: {
|
|
3030
3351
|
startDate: date,
|
|
3031
3352
|
endDate: date
|
|
3032
3353
|
},
|
|
3033
|
-
resourceIds
|
|
3354
|
+
resourceIds
|
|
3355
|
+
};
|
|
3356
|
+
// Match normalizeAvailabilityPrepareDescriptor so confirmation reuses exactly
|
|
3357
|
+
// the same resource/date coverage as the selection projection.
|
|
3358
|
+
const timezone = String(this.otherParams?.businessTimezone || Intl.DateTimeFormat().resolvedOptions().timeZone || 'Asia/Shanghai').trim();
|
|
3359
|
+
const resources = this.isVenueCatalogLocalPricingActive() ? await this.availabilitySessionResourceCache.load({
|
|
3360
|
+
scopeKey: `${scope}:${this.buildAvailabilityRemoteResourceScopeKey(timezone)}`,
|
|
3361
|
+
timezoneName: timezone,
|
|
3362
|
+
...resourceQuery,
|
|
3363
|
+
fetch: query => this.fetchAvailabilityResourcesV2({
|
|
3364
|
+
...query,
|
|
3365
|
+
strictResponse: true
|
|
3366
|
+
})
|
|
3367
|
+
}) : await this.fetchAvailabilityResourcesV2({
|
|
3368
|
+
...resourceQuery,
|
|
3034
3369
|
strictResponse: true
|
|
3035
3370
|
});
|
|
3036
3371
|
assertCurrent();
|
|
@@ -3143,6 +3478,24 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
3143
3478
|
resourceOccupancies: []
|
|
3144
3479
|
};
|
|
3145
3480
|
}
|
|
3481
|
+
if (params.fetchPolicy === 'session') {
|
|
3482
|
+
const rawResources = await this.availabilitySessionResourceCache.load({
|
|
3483
|
+
scopeKey: `${this.getRuntimeOpenDataScope()}:${this.buildAvailabilityRemoteResourceScopeKey(params.timezone)}`,
|
|
3484
|
+
timezoneName: params.timezone,
|
|
3485
|
+
resourceIds,
|
|
3486
|
+
dateRange: params.dateRange,
|
|
3487
|
+
fetch: query => this.fetchAvailabilityResourcesV2({
|
|
3488
|
+
...query,
|
|
3489
|
+
strictResponse: true
|
|
3490
|
+
})
|
|
3491
|
+
});
|
|
3492
|
+
return buildAvailabilityResourcesFromV2({
|
|
3493
|
+
rawResources,
|
|
3494
|
+
scheduleList: params.scheduleList,
|
|
3495
|
+
dateRange: params.dateRange,
|
|
3496
|
+
fixedOffsetMinutes: this.getAvailabilityRuntimeOffsetMinutes()
|
|
3497
|
+
});
|
|
3498
|
+
}
|
|
3146
3499
|
if (Array.isArray(params.rawResources) && params.fetchPolicy !== 'refresh') {
|
|
3147
3500
|
return buildAvailabilityResourcesFromV2({
|
|
3148
3501
|
rawResources: params.rawResources,
|
|
@@ -3404,8 +3757,9 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
3404
3757
|
products,
|
|
3405
3758
|
rawResources: normalizedPrepareParams.rawResources,
|
|
3406
3759
|
scheduleList,
|
|
3407
|
-
//
|
|
3408
|
-
|
|
3760
|
+
// Explicit Venue sessions retain physical occupancy coverage across preview,
|
|
3761
|
+
// selection and commit. Cart-derived occupancy is still rebuilt below.
|
|
3762
|
+
fetchPolicy: normalizedPrepareParams.occupancyCachePolicy === 'session' ? 'session' : options.resourceFetchPolicy || (normalizedPrepareParams.refreshOccupancies ? 'refresh' : normalizedPrepareParams.occupancyCachePolicy === 'cache_first' ? 'cache_first' : 'default'),
|
|
3409
3763
|
fallbackResources: options.fallbackResources
|
|
3410
3764
|
});
|
|
3411
3765
|
const tempOrder = this.getTempOrder();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AvailabilityDateRange } from '../../modules/ResourcePlanner';
|
|
2
|
+
type ResourceId = number | string;
|
|
3
|
+
type RawResource = Record<string, any>;
|
|
4
|
+
export interface AvailabilitySessionResourceQuery {
|
|
5
|
+
resourceIds: ResourceId[];
|
|
6
|
+
dateRange: AvailabilityDateRange;
|
|
7
|
+
}
|
|
8
|
+
export interface AvailabilitySessionResourceLoadParams extends AvailabilitySessionResourceQuery {
|
|
9
|
+
/** The owner supplies shop/tenant, order cache, business and channel identity. */
|
|
10
|
+
scopeKey: string;
|
|
11
|
+
timezoneName: string;
|
|
12
|
+
/** Must reject transport/business errors; only a successful empty array is negative coverage. */
|
|
13
|
+
fetch: (query: AvailabilitySessionResourceQuery) => Promise<RawResource[]>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Opt-in venue-session snapshots. Unlike the legacy SWR cache, a covered resource/day is never
|
|
17
|
+
* refreshed or evicted during this session. Only missing cells are fetched, including when a new
|
|
18
|
+
* resource set partly overlaps an earlier one. The final backend submission remains authoritative.
|
|
19
|
+
*/
|
|
20
|
+
export declare class AvailabilitySessionResourceCache {
|
|
21
|
+
private readonly cells;
|
|
22
|
+
private readonly pending;
|
|
23
|
+
private generation;
|
|
24
|
+
clear(): void;
|
|
25
|
+
load(params: AvailabilitySessionResourceLoadParams): Promise<RawResource[]>;
|
|
26
|
+
}
|
|
27
|
+
export {};
|