@pisell/pisellos 2.3.191 → 2.3.193

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 (62) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/BookingContext/index.d.ts +2 -2
  3. package/dist/modules/BookingContext/index.js +55 -25
  4. package/dist/modules/BookingContext/types.d.ts +2 -0
  5. package/dist/modules/Order/index.d.ts +13 -5
  6. package/dist/modules/Order/index.js +1053 -554
  7. package/dist/modules/Order/types.d.ts +20 -1
  8. package/dist/modules/Order/types.js +4 -0
  9. package/dist/modules/Order/utils.d.ts +3 -1
  10. package/dist/modules/Order/utils.js +5 -2
  11. package/dist/modules/ProductList/clientDataVariants.js +6 -2
  12. package/dist/modules/ProductList/index.d.ts +2 -0
  13. package/dist/modules/ProductList/index.js +125 -39
  14. package/dist/modules/ResourcePlanner/planner.js +5 -0
  15. package/dist/modules/Rules/index.js +30 -19
  16. package/dist/server/index.js +5 -2
  17. package/dist/solution/BaseSales/index.d.ts +14 -3
  18. package/dist/solution/BaseSales/index.js +285 -195
  19. package/dist/solution/BookingByStep/index.d.ts +2 -2
  20. package/dist/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
  21. package/dist/solution/UnifiedBookingSales/catalogQueryBatch.js +202 -0
  22. package/dist/solution/UnifiedBookingSales/index.d.ts +49 -1
  23. package/dist/solution/UnifiedBookingSales/index.js +2276 -902
  24. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
  25. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.js +4 -0
  26. package/dist/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  27. package/dist/solution/UnifiedBookingSales/sessionResourceCache.js +271 -0
  28. package/dist/solution/UnifiedBookingSales/types.d.ts +64 -1
  29. package/dist/solution/UnifiedBookingSales/types.js +7 -1
  30. package/dist/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  31. package/dist/solution/UnifiedBookingSales/venueCatalogSession.js +277 -0
  32. package/lib/modules/BookingContext/index.d.ts +2 -2
  33. package/lib/modules/BookingContext/index.js +42 -10
  34. package/lib/modules/BookingContext/types.d.ts +2 -0
  35. package/lib/modules/Order/index.d.ts +13 -5
  36. package/lib/modules/Order/index.js +208 -7
  37. package/lib/modules/Order/types.d.ts +20 -1
  38. package/lib/modules/Order/types.js +2 -0
  39. package/lib/modules/Order/utils.d.ts +3 -1
  40. package/lib/modules/Order/utils.js +5 -2
  41. package/lib/modules/ProductList/clientDataVariants.js +6 -2
  42. package/lib/modules/ProductList/index.d.ts +2 -0
  43. package/lib/modules/ProductList/index.js +56 -0
  44. package/lib/modules/ResourcePlanner/planner.js +4 -0
  45. package/lib/modules/Rules/index.js +19 -9
  46. package/lib/server/index.js +5 -1
  47. package/lib/solution/BaseSales/index.d.ts +14 -3
  48. package/lib/solution/BaseSales/index.js +67 -2
  49. package/lib/solution/BookingByStep/index.d.ts +2 -2
  50. package/lib/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
  51. package/lib/solution/UnifiedBookingSales/catalogQueryBatch.js +109 -0
  52. package/lib/solution/UnifiedBookingSales/index.d.ts +49 -1
  53. package/lib/solution/UnifiedBookingSales/index.js +872 -55
  54. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
  55. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +2 -0
  56. package/lib/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  57. package/lib/solution/UnifiedBookingSales/sessionResourceCache.js +199 -0
  58. package/lib/solution/UnifiedBookingSales/types.d.ts +64 -1
  59. package/lib/solution/UnifiedBookingSales/types.js +4 -1
  60. package/lib/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  61. package/lib/solution/UnifiedBookingSales/venueCatalogSession.js +151 -0
  62. package/package.json +1 -1
@@ -11,6 +11,8 @@ export declare class AvailabilityRemoteOccupancyCache {
11
11
  scopeKey: string;
12
12
  resourceIds: AvailabilityId[];
13
13
  dateRange: AvailabilityDateRange;
14
+ /** Only opt-in preview reads expire cells; legacy reads retain their SWR semantics. */
15
+ maxAgeMs?: number;
14
16
  }): Record<string, any>[] | null;
15
17
  hasCompleteCoverage(params: {
16
18
  scopeKey: string;
@@ -117,6 +117,7 @@ class AvailabilityRemoteOccupancyCache {
117
117
  const requestedResourceIds = uniqueIds(params.resourceIds);
118
118
  const requestedDates = buildDateList(params.dateRange);
119
119
  if (requestedResourceIds.length === 0 || requestedDates.length === 0) return [];
120
+ const now = Date.now();
120
121
  const resources = [];
121
122
  for (const resourceId of requestedResourceIds) {
122
123
  const resourceKey = this.buildResourceKey(params.scopeKey, resourceId);
@@ -125,6 +126,7 @@ class AvailabilityRemoteOccupancyCache {
125
126
  const cellKey = this.buildCellKey(resourceKey, date);
126
127
  const cell = this.touchCell(cellKey);
127
128
  if (!cell) return null;
129
+ if (params.maxAgeMs !== undefined && (now < cell.fetchedAt || now - cell.fetchedAt >= params.maxAgeMs)) return null;
128
130
  cell.eventList.forEach(rawEvent => {
129
131
  eventList.set(buildEventIdentity(resourceId, rawEvent), (0, _lodashEs.cloneDeep)(rawEvent));
130
132
  });
@@ -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 {};
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AvailabilitySessionResourceCache = void 0;
7
+ var _lodashEs = require("lodash-es");
8
+ var _localClock = require("../../modules/ResourcePlanner/localClock");
9
+ function datesInRange(range) {
10
+ const count = (0, _localClock.dateOrdinalFromLocalDate)(range.endDate) - (0, _localClock.dateOrdinalFromLocalDate)(range.startDate) + 1;
11
+ // A legal 90-business-day projection may include its preceding opening and overnight tail.
12
+ if (count < 1 || count > 92) throw new Error('Resource coverage requires a valid range of at most 92 days.');
13
+ const dates = [];
14
+ let date = (0, _localClock.formatLocalDate)(range.startDate);
15
+ for (let index = 0; index < count; index += 1) {
16
+ dates.push(date);
17
+ date = (0, _localClock.nextDate)(date);
18
+ }
19
+ return dates;
20
+ }
21
+ function resourceIdOf(resource) {
22
+ return resource.resourceId ?? resource.resource_id ?? resource.id;
23
+ }
24
+ function eventTime(event, edge) {
25
+ return String(event[`${edge}_at`] ?? event[`${edge}At`] ?? event[`${edge}_time`] ?? event[`${edge}Time`] ?? '');
26
+ }
27
+ function stableValue(value) {
28
+ if (Array.isArray(value)) return value.map(stableValue);
29
+ if (value && typeof value === 'object') {
30
+ return Object.keys(value).sort().reduce((result, key) => {
31
+ result[key] = stableValue(value[key]);
32
+ return result;
33
+ }, {});
34
+ }
35
+ return value;
36
+ }
37
+ function eventIdentity(event) {
38
+ const id = event.schedule_event_id ?? event.scheduleEventId ?? event.server_event_id ?? event.id;
39
+ const isUniqueEvent = id !== undefined && id !== null && id !== '';
40
+ return {
41
+ // A booking/product UID can own several allocations. Only an actual event ID plus its
42
+ // interval identifies one event; otherwise retain the complete payload and its multiplicity.
43
+ key: isUniqueEvent ? `event:${JSON.stringify([String(id), eventTime(event, 'start'), eventTime(event, 'end')])}` : `raw:${JSON.stringify(stableValue(event))}`,
44
+ isUniqueEvent
45
+ };
46
+ }
47
+ function eventsOnDate(events, date) {
48
+ const start = (0, _localClock.localDateToScalarStart)(date);
49
+ const end = (0, _localClock.localDateToScalarStart)((0, _localClock.nextDate)(date));
50
+ return events.filter(event => {
51
+ try {
52
+ const eventStart = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(eventTime(event, 'start')));
53
+ const eventEnd = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(eventTime(event, 'end')));
54
+ return eventStart < eventEnd && eventStart < end && eventEnd > start;
55
+ } catch {
56
+ return false;
57
+ }
58
+ });
59
+ }
60
+
61
+ /**
62
+ * Opt-in venue-session snapshots. Unlike the legacy SWR cache, a covered resource/day is never
63
+ * refreshed or evicted during this session. Only missing cells are fetched, including when a new
64
+ * resource set partly overlaps an earlier one. The final backend submission remains authoritative.
65
+ */
66
+ class AvailabilitySessionResourceCache {
67
+ cells = new Map();
68
+ pending = new Map();
69
+ generation = 0;
70
+ clear() {
71
+ this.generation += 1;
72
+ this.cells.clear();
73
+ this.pending.clear();
74
+ }
75
+ async load(params) {
76
+ const generation = this.generation;
77
+ const assertCurrent = () => {
78
+ if (generation !== this.generation) {
79
+ throw Object.assign(new Error('Resource session changed while loading. Please prepare again.'), {
80
+ code: 'AVAILABILITY_CONTEXT_NOT_FOUND'
81
+ });
82
+ }
83
+ };
84
+ const resources = Array.from(new Map(params.resourceIds.filter(id => id !== undefined && id !== null && id !== '').map(id => [String(id), id])).values());
85
+ const dates = datesInRange(params.dateRange);
86
+ const key = (resourceId, date) => JSON.stringify([params.scopeKey, params.timezoneName, String(resourceId), date]);
87
+ const waits = new Set();
88
+ const gaps = [];
89
+ let previousIds = '';
90
+ dates.forEach(date => {
91
+ const missing = resources.filter(resourceId => {
92
+ const cellKey = key(resourceId, date);
93
+ if (this.cells.has(cellKey)) return false;
94
+ const pending = this.pending.get(cellKey);
95
+ if (pending) {
96
+ waits.add(pending);
97
+ return false;
98
+ }
99
+ return true;
100
+ }).sort((left, right) => String(left).localeCompare(String(right)));
101
+ const ids = JSON.stringify(missing.map(String));
102
+ const previous = gaps[gaps.length - 1];
103
+ if (missing.length && ids === previousIds && previous && (0, _localClock.nextDate)(previous.dateRange.endDate) === date) {
104
+ previous.dateRange.endDate = date;
105
+ } else if (missing.length) {
106
+ gaps.push({
107
+ resourceIds: missing,
108
+ dateRange: {
109
+ startDate: date,
110
+ endDate: date
111
+ }
112
+ });
113
+ }
114
+ previousIds = ids;
115
+ });
116
+
117
+ // Reserve every missing cell synchronously before dispatching any request. This also deduplicates
118
+ // partial overlapping in-flight queries, rather than only identical or fully covering requests.
119
+ gaps.forEach(query => {
120
+ const queryDates = datesInRange(query.dateRange);
121
+ const cellKeys = query.resourceIds.flatMap(id => queryDates.map(date => key(id, date)));
122
+ const promise = Promise.resolve().then(async () => {
123
+ assertCurrent();
124
+ const response = await params.fetch((0, _lodashEs.cloneDeep)(query));
125
+ assertCurrent();
126
+ if (!Array.isArray(response)) throw new Error('Booking resources returned an invalid response.');
127
+ const byId = new Map();
128
+ response.forEach(resource => {
129
+ if (!resource || typeof resource !== 'object' || Array.isArray(resource)) {
130
+ throw new Error('Booking resources returned an invalid resource.');
131
+ }
132
+ const id = resourceIdOf(resource);
133
+ if (typeof id !== 'string' && typeof id !== 'number' || id === '' || typeof id === 'number' && !Number.isFinite(id) || resource.event_list != null && !Array.isArray(resource.event_list)) {
134
+ throw new Error('Booking resources returned invalid identity or occupancy data.');
135
+ }
136
+ byId.set(String(id), (0, _lodashEs.cloneDeep)(resource));
137
+ });
138
+ // Assemble the response before publishing any cells, so malformed data cannot mark a
139
+ // partially successful range as covered. Missing resources in a valid response are cached too.
140
+ const updates = new Map();
141
+ query.resourceIds.forEach(id => {
142
+ const raw = byId.get(String(id));
143
+ const events = Array.isArray(raw?.event_list) ? raw.event_list : [];
144
+ const metadata = raw ? (({
145
+ event_list: _events,
146
+ ...rest
147
+ }) => rest)(raw) : null;
148
+ queryDates.forEach(date => updates.set(key(id, date), {
149
+ resource: metadata,
150
+ events: eventsOnDate(events, date)
151
+ }));
152
+ });
153
+ assertCurrent();
154
+ updates.forEach((cell, cellKey) => {
155
+ if (!this.cells.has(cellKey)) this.cells.set(cellKey, cell);
156
+ });
157
+ }).finally(() => {
158
+ cellKeys.forEach(cellKey => {
159
+ if (this.pending.get(cellKey) === promise) this.pending.delete(cellKey);
160
+ });
161
+ });
162
+ cellKeys.forEach(cellKey => this.pending.set(cellKey, promise));
163
+ waits.add(promise);
164
+ });
165
+ await Promise.all(Array.from(waits));
166
+ assertCurrent();
167
+ const result = [];
168
+ resources.forEach(id => {
169
+ let metadata = null;
170
+ const events = new Map();
171
+ dates.forEach(date => {
172
+ const cell = this.cells.get(key(id, date));
173
+ if (!cell) throw new Error('Resource session coverage was lost. Please prepare again.');
174
+ if (!metadata && cell.resource) metadata = cell.resource;
175
+ const occurrences = new Map();
176
+ cell.events.forEach(event => {
177
+ const identity = eventIdentity(event);
178
+ const occurrence = identity.isUniqueEvent ? 0 : occurrences.get(identity.key) || 0;
179
+ occurrences.set(identity.key, occurrence + 1);
180
+ const occupancyKey = JSON.stringify([identity.key, occurrence]);
181
+ // Merge the maximum count seen in a day, not a set of booking UIDs: anonymous duplicate
182
+ // allocations must still count twice, while one cross-midnight event counts only once.
183
+ if (!events.has(occupancyKey)) events.set(occupancyKey, {
184
+ ...event,
185
+ __availabilitySessionOccupancyKey: occupancyKey
186
+ });
187
+ });
188
+ });
189
+ if (metadata) {
190
+ result.push((0, _lodashEs.cloneDeep)({
191
+ ...metadata,
192
+ event_list: Array.from(events.values()).sort((left, right) => eventTime(left, 'start').localeCompare(eventTime(right, 'start')) || eventTime(left, 'end').localeCompare(eventTime(right, 'end')))
193
+ }));
194
+ }
195
+ });
196
+ return result;
197
+ }
198
+ }
199
+ exports.AvailabilitySessionResourceCache = AvailabilitySessionResourceCache;
@@ -6,10 +6,42 @@ import type { AvailabilityDateRange, AvailabilityErrorCode, AvailabilityId, Avai
6
6
  import type { BookingTicketState } from '../BookingTicket/types';
7
7
  import type { AllergyRequirement } from '../../model/strategy/adapter/itemRule';
8
8
  import type { SalesNoteDraftInput } from '../../modules/Order/types';
9
+ import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult } from '../BaseSales/types';
9
10
  export type { ProductListStoreQueryParams } from '../../modules/ProductList';
10
11
  export type { AvailabilityAbsoluteRange, AvailabilityAssignment, AvailabilityCell, AvailabilityDateRange, AvailabilityDisplayRange, AvailabilityErrorCode, AvailabilityId, AvailabilityMode, AvailabilityOccupancy, AvailabilityProduct, AvailabilityProductKind, AvailabilityProjection, AvailabilityProjectionInput, AvailabilityProjectionMeta, AvailabilityQuery, AvailabilityQueryResult, AvailabilityRequirementGroup, AvailabilityRequirementGroupResult, AvailabilityRequirementSelection, AvailabilityResource, AvailabilityResourceOption, AvailabilityResourceType, AvailabilityResourceWindow, AvailabilityScheduleMode, AvailabilityScheduleRef, AvailabilityScheduleRule, AvailabilitySelectionValidationParams, AvailabilitySelectionValidationResult, AvailabilitySessionRange, AvailabilityStatus, DateAvailabilityGroup, DateAvailabilityItem, DateAvailabilityQuery, DateAvailabilityQueryResult, GetProductTimeRangesRequest, ProductAvailabilityGroup, ProductAvailabilityItem, ProductAvailabilityQuery, ProductAvailabilityQueryResult, ProductTimeRange, ProductTimeRangeGroup, QueryAvailabilityBaseRequest, ResourceAvailabilityGroup, ResourceAvailabilityQuery, ResourceAvailabilityQueryResult, ResourceAvailabilityRangeGroup, TimeAvailabilityGroup, TimeAvailabilityItem, TimeAvailabilityQuery, TimeAvailabilityQueryResult, } from '../../modules/ResourcePlanner';
11
12
  export interface UnifiedBookingSalesState extends BookingTicketState {
12
13
  }
14
+ /** Read-only preview scope; existing solution queries remain fresh for selection and submission. */
15
+ export interface UnifiedBookingSalesCatalogQueryBatch {
16
+ queryCatalogSnapshot(params: ProductListLoadProductsParams): Promise<ProductData[]>;
17
+ queryCatalogProductDetail(params: ProductListLoadProductsParams & {
18
+ product_id: number;
19
+ }): Promise<ProductData | undefined>;
20
+ /** Releases retained results. A disposed batch cannot be reused. */
21
+ dispose(): void;
22
+ }
23
+ /** Venue page lifetime pool. Reads/quotes stay local; explicit opening may hydrate a variant once. */
24
+ export interface UnifiedBookingSalesVenueCatalogSession {
25
+ queryCatalogSnapshot(params?: ProductListLoadProductsParams): Promise<ProductData[]>;
26
+ queryCatalogProductDetail(params: ProductListLoadProductsParams & {
27
+ product_id: number;
28
+ }): Promise<ProductData | undefined>;
29
+ /** User-initiated opening only. Non-variant products never load a detail endpoint. */
30
+ prepareProductDetail(params: ProductListLoadProductsParams & {
31
+ product_id: number;
32
+ retry?: boolean;
33
+ }): Promise<ProductData | undefined>;
34
+ calculateProductBookingPrice(params: BaseSalesCalculateProductBookingPriceParams): Promise<BaseSalesProductBookingPriceResult>;
35
+ /** Retries failed pool/detail loads; successfully loaded records remain cached. */
36
+ retry(): void;
37
+ dispose(): void;
38
+ }
39
+ export type UnifiedBookingSalesVenueCatalogSessionParams = ProductListLoadProductsParams & {
40
+ /** Stable page/order session identity shared by main and extras pools. */
41
+ sessionKey?: string;
42
+ /** Lets implicit order repricing select the originating pool without guessing by product ID. */
43
+ poolRole?: 'main' | 'extras';
44
+ };
13
45
  export interface UnifiedBookingSalesPolicy {
14
46
  id?: AvailabilityId;
15
47
  title?: unknown;
@@ -39,6 +71,19 @@ export interface UnifiedBookingSalesLoadOpenDataParams {
39
71
  channel: string;
40
72
  force?: boolean;
41
73
  }
74
+ export interface UnifiedBookingSalesQueryBookingResourceDetailsParams {
75
+ /** Explicit booking date, YYYY-MM-DD. No implicit current-date fallback. */
76
+ date: string;
77
+ resourceIds: AvailabilityId[];
78
+ }
79
+ /** Original resource metadata. form_id is its resource type, not an associated customer form. */
80
+ export interface UnifiedBookingSalesResourceDetail extends Record<string, any> {
81
+ id: AvailabilityId;
82
+ resource_form_id?: number | string | null;
83
+ policy_id?: number | string | null;
84
+ form_id?: AvailabilityId;
85
+ main_field?: unknown;
86
+ }
42
87
  export interface UnifiedBookingSalesLoadProductsByScheduleDateParams extends Omit<ProductListLoadProductsParams, 'schedule_date' | 'product_ids'> {
43
88
  date: string;
44
89
  product_ids?: number[];
@@ -59,6 +104,14 @@ export interface UnifiedBookingSalesPrepareAvailabilityProjectionParams {
59
104
  dateRange?: Partial<AvailabilityDateRange>;
60
105
  catalogScope?: UnifiedBookingSalesCatalogScope;
61
106
  rawProducts?: Record<string, any>[];
107
+ /** Keep an independent catalog/projection without replacing the public sales catalog. Defaults to true. */
108
+ publishCatalog?: boolean;
109
+ /** Await remote occupancy refresh instead of stale-while-revalidate. Ignores rawResources; does not lock resources. */
110
+ refreshOccupancies?: boolean;
111
+ /** cache_first: 30-second preview. session: retain resource/date coverage for this venue page, including commit; overrides refreshOccupancies. Omit for legacy SWR. */
112
+ occupancyCachePolicy?: 'cache_first' | 'session';
113
+ /** Enforce configured sale cutoffs and disable manual POS availability overrides for this context. Defaults to false. */
114
+ strictAvailability?: boolean;
62
115
  rawResources?: Record<string, any>[];
63
116
  rawOccupancies?: AvailabilityOccupancy[];
64
117
  editingProductLineUids?: string[];
@@ -163,9 +216,11 @@ export interface UnifiedBookingSalesAddRetailProductParams {
163
216
  productId?: number | string;
164
217
  quantity?: number;
165
218
  productLoadParams?: ProductListLoadProductsParams;
219
+ salesNotes?: SalesNoteDraftInput[];
220
+ availabilityCommitGuard?: () => void;
166
221
  }
167
222
  export interface ContextualCommitAvailabilitySelectionParams {
168
- mode: 'add' | 'edit';
223
+ mode: 'add' | 'edit' | 'replace';
169
224
  /** Only POS duration add supports automatic remembered-time commits. */
170
225
  selectionIntent?: 'remembered' | 'manual';
171
226
  /** v2 remembered commits must still belong to the order that saved the interval. */
@@ -173,6 +228,14 @@ export interface ContextualCommitAvailabilitySelectionParams {
173
228
  /** Local UI intent guard, checked again immediately before the Order mutation. */
174
229
  availabilityCommitGuard?: () => void;
175
230
  productLineUid?: string;
231
+ /**
232
+ * Confirmed complete Party extras set (configured, purchase-time-repriced retail source products).
233
+ * Their legacy venue_booking_service_datetime metadata stores the venue-local quote time,
234
+ * independently of the main product's appointment time.
235
+ * Required for replace; edit opts into the same atomic path. Existing extras keep their own
236
+ * metadata.unique_identification_number; new extras omit it. [] explicitly removes all owned extras.
237
+ */
238
+ relatedRetailProducts?: Record<string, any>[];
176
239
  orderProduct: Record<string, any>;
177
240
  candidate: ContextualProductTimeRange;
178
241
  requirementSelections: AvailabilityRequirementSelection[];
@@ -4,9 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.UnifiedBookingSalesHooks = void 0;
7
+ /** Read-only preview scope; existing solution queries remain fresh for selection and submission. */
8
+ /** Venue page lifetime pool. Reads/quotes stay local; explicit opening may hydrate a variant once. */
7
9
  let UnifiedBookingSalesHooks = exports.UnifiedBookingSalesHooks = /*#__PURE__*/function (UnifiedBookingSalesHooks) {
8
10
  UnifiedBookingSalesHooks["onAvailabilityProjectionPrepared"] = "unifiedBookingSales:onAvailabilityProjectionPrepared";
9
11
  UnifiedBookingSalesHooks["onAvailabilitySelectionCommitted"] = "unifiedBookingSales:onAvailabilitySelectionCommitted";
10
12
  UnifiedBookingSalesHooks["onAvailabilityProjectionDiagnostic"] = "unifiedBookingSales:onAvailabilityProjectionDiagnostic";
11
13
  return UnifiedBookingSalesHooks;
12
- }({});
14
+ }({});
15
+ /** Original resource metadata. form_id is its resource type, not an associated customer form. */
@@ -0,0 +1,32 @@
1
+ import type { ProductData } from '../../modules/Product/types';
2
+ import type { ProductListLoadProductsParams } from '../../modules/ProductList';
3
+ import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult } from '../BaseSales/types';
4
+ import type { UnifiedBookingSalesVenueCatalogSession } from './types';
5
+ export type VenueCatalogRecord = Record<string, any>;
6
+ export interface VenueCatalogPool {
7
+ products: ProductData[];
8
+ menus: VenueCatalogRecord[];
9
+ /** Pricing menu_match follows the OS evaluator's full menu-definition contract. */
10
+ pricingMenus: VenueCatalogRecord[];
11
+ }
12
+ export declare function venueCatalogError(code: string, message: string): Error & {
13
+ code: string;
14
+ };
15
+ export declare function readVenueCatalogList(response: any, description: string): VenueCatalogRecord[];
16
+ export declare function validateVenueMenus(records: VenueCatalogRecord[], ids: number[]): VenueCatalogRecord[];
17
+ /** Same ID/collection union as the local OS product query; variant selection stays with SKU validation. */
18
+ export declare function productMatchesVenueMenu(product: VenueCatalogRecord, menu: VenueCatalogRecord): boolean;
19
+ export declare function activeVenueMenus(menus: VenueCatalogRecord[], schedules: VenueCatalogRecord[], datetime: string, dateOnly?: boolean): VenueCatalogRecord[];
20
+ /** Internal loader injection is not exposed to material callers. Rejected loads remain rejected until explicit retry. */
21
+ export declare function createVenueCatalogSessionAdapter(options: {
22
+ assertCurrent(): void;
23
+ load(): Promise<VenueCatalogPool>;
24
+ snapshot(pool: VenueCatalogPool, params: ProductListLoadProductsParams): ProductData[];
25
+ prepareDetail(pool: VenueCatalogPool, params: ProductListLoadProductsParams & {
26
+ product_id: number;
27
+ retry?: boolean;
28
+ }): Promise<void>;
29
+ quote(pool: VenueCatalogPool, params: BaseSalesCalculateProductBookingPriceParams): Promise<BaseSalesProductBookingPriceResult>;
30
+ onDispose?(): void;
31
+ onRetry?(): void;
32
+ }): UnifiedBookingSalesVenueCatalogSession;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.activeVenueMenus = activeVenueMenus;
7
+ exports.createVenueCatalogSessionAdapter = createVenueCatalogSessionAdapter;
8
+ exports.productMatchesVenueMenu = productMatchesVenueMenu;
9
+ exports.readVenueCatalogList = readVenueCatalogList;
10
+ exports.validateVenueMenus = validateVenueMenus;
11
+ exports.venueCatalogError = venueCatalogError;
12
+ var _lodashEs = require("lodash-es");
13
+ var _getDateIsInSchedule = require("../../modules/Schedule/getDateIsInSchedule");
14
+ function venueCatalogError(code, message) {
15
+ return Object.assign(new Error(message), {
16
+ code
17
+ });
18
+ }
19
+ function readVenueCatalogList(response, description) {
20
+ const list = response?.data?.list;
21
+ if (!response || response.status === false || response.success === false || response.code != null && Number(response.code) !== 200 || !Array.isArray(list)) {
22
+ throw venueCatalogError('VENUE_CATALOG_LOAD_FAILED', response?.message || `${description} could not be loaded.`);
23
+ }
24
+ const total = response.data.total ?? response.data.total_count ?? response.data.total_num;
25
+ if (total != null && Number.isFinite(Number(total)) && Number(total) > list.length) {
26
+ throw venueCatalogError('VENUE_CATALOG_INCOMPLETE', `${description} is incomplete. A complete catalog response is required.`);
27
+ }
28
+ return list;
29
+ }
30
+ function validateVenueMenus(records, ids) {
31
+ return ids.map(id => {
32
+ const menu = records.find(row => Number(row.form_record_id) === id);
33
+ const config = menu?.partyroom_package;
34
+ if (!menu || !['product_all', 'products', 'product_collection'].includes(config?.type) || !Array.isArray(menu.schedule) || menu.schedule.some(value => !Number.isSafeInteger(Number(value)) || Number(value) <= 0) || config.type !== 'product_all' && (!Array.isArray(config.products) || config.products.some(row => {
35
+ const value = Number(row?.[config.type === 'products' ? 'product_id' : 'product_collection_id']);
36
+ return !Number.isSafeInteger(value) || value <= 0;
37
+ }))) {
38
+ throw venueCatalogError('VENUE_MENU_INCOMPLETE', 'The configured menu is incomplete. Reload the booking page.');
39
+ }
40
+ return (0, _lodashEs.cloneDeep)(menu);
41
+ });
42
+ }
43
+
44
+ /** Same ID/collection union as the local OS product query; variant selection stays with SKU validation. */
45
+ function productMatchesVenueMenu(product, menu) {
46
+ if (menu.status && menu.status !== 'valid') return false;
47
+ const config = menu.partyroom_package;
48
+ if (config?.type === 'product_all') return true;
49
+ if (config?.type === 'products') return config.products.some(row => Number(row.product_id) === Number(product.id));
50
+ if (config?.type === 'product_collection') {
51
+ if (!Array.isArray(product.collection)) {
52
+ throw venueCatalogError('VENUE_CATALOG_INCOMPLETE', 'Product collection data is missing from the catalog.');
53
+ }
54
+ return config.products.some(row => product.collection.some(collection => Number(collection.id) === Number(row.product_collection_id)));
55
+ }
56
+ return false;
57
+ }
58
+ function activeVenueMenus(menus, schedules, datetime, dateOnly = false) {
59
+ const scheduleMap = new Map(schedules.map(row => [Number(row.id), row]));
60
+ return menus.filter(menu => {
61
+ if (menu.status && menu.status !== 'valid') return false;
62
+ const records = menu.schedule.map(id => scheduleMap.get(Number(id)));
63
+ if (records.some(record => !record)) {
64
+ throw venueCatalogError('VENUE_SCHEDULE_INCOMPLETE', 'Menu schedule data is not ready. Please retry.');
65
+ }
66
+ // A calendar/card read asks whether the menu opens at any point on that date.
67
+ // Only selected-time/retail quotes require membership at an exact instant.
68
+ return dateOnly ? (0, _getDateIsInSchedule.getScheduleStartEndTimePoints)(datetime.slice(0, 10), records).length > 0 : (0, _getDateIsInSchedule.getDateIsInSchedule)(datetime, records);
69
+ });
70
+ }
71
+
72
+ /** Internal loader injection is not exposed to material callers. Rejected loads remain rejected until explicit retry. */
73
+ function createVenueCatalogSessionAdapter(options) {
74
+ let disposed = false;
75
+ let failed = false;
76
+ let pending;
77
+ const assertCurrent = () => {
78
+ if (disposed) throw venueCatalogError('VENUE_CATALOG_DISPOSED', 'The venue catalog session is closed.');
79
+ options.assertCurrent();
80
+ };
81
+ const load = async () => {
82
+ assertCurrent();
83
+ if (!pending) {
84
+ pending = Promise.resolve().then(() => {
85
+ assertCurrent();
86
+ return options.load();
87
+ }).then(pool => {
88
+ assertCurrent();
89
+ return (0, _lodashEs.cloneDeep)(pool);
90
+ }).catch(error => {
91
+ failed = true;
92
+ throw error;
93
+ });
94
+ }
95
+ const pool = await pending;
96
+ assertCurrent();
97
+ return pool;
98
+ };
99
+ return {
100
+ queryCatalogSnapshot: async (params = {}) => {
101
+ const pool = await load();
102
+ const result = options.snapshot(pool, (0, _lodashEs.cloneDeep)(params));
103
+ assertCurrent();
104
+ return (0, _lodashEs.cloneDeep)(result);
105
+ },
106
+ queryCatalogProductDetail: async ({
107
+ product_id,
108
+ ...params
109
+ }) => {
110
+ const pool = await load();
111
+ const result = options.snapshot(pool, {
112
+ ...(0, _lodashEs.cloneDeep)(params),
113
+ product_ids: [product_id]
114
+ });
115
+ assertCurrent();
116
+ return (0, _lodashEs.cloneDeep)(result.find(product => Number(product.id) === Number(product_id)));
117
+ },
118
+ prepareProductDetail: async params => {
119
+ const pool = await load();
120
+ const query = {
121
+ ...(0, _lodashEs.cloneDeep)(params),
122
+ product_ids: [params.product_id]
123
+ };
124
+ if (!options.snapshot(pool, query).some(product => Number(product.id) === Number(params.product_id))) return undefined;
125
+ await options.prepareDetail(pool, (0, _lodashEs.cloneDeep)(params));
126
+ assertCurrent();
127
+ return (0, _lodashEs.cloneDeep)(options.snapshot(pool, query).find(product => Number(product.id) === Number(params.product_id)));
128
+ },
129
+ calculateProductBookingPrice: async params => {
130
+ const pool = await load();
131
+ const result = await options.quote(pool, (0, _lodashEs.cloneDeep)(params));
132
+ assertCurrent();
133
+ return (0, _lodashEs.cloneDeep)(result);
134
+ },
135
+ retry: () => {
136
+ assertCurrent();
137
+ if (failed) {
138
+ pending = undefined;
139
+ failed = false;
140
+ }
141
+ options.onRetry?.();
142
+ },
143
+ dispose: () => {
144
+ if (!disposed) {
145
+ disposed = true;
146
+ pending = undefined;
147
+ options.onDispose?.();
148
+ }
149
+ }
150
+ };
151
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.191",
4
+ "version": "2.3.193",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",