@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
@@ -1507,6 +1507,96 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1507
1507
  }
1508
1508
  };
1509
1509
  }
1510
+
1511
+ /** Reuse an approved calendar cache; only the final commit may mutate the order. */
1512
+ async prepareDirectAddCalendarBooking(cacheItem, options = {}) {
1513
+ if ((0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) !== 'pos' || cacheItem?._data?.calendarManualBooking || cacheItem?.duration?.type === 'days') return null;
1514
+ if (!cacheItem?._data?.calendarBookingPreparationKey || (0, _utils.calendarBookingNeedsInput)(cacheItem)) {
1515
+ throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', 'Calendar booking still requires product input.');
1516
+ }
1517
+ const productId = Number(cacheItem.product_id ?? cacheItem.id);
1518
+ const bookingCount = Number(options.bookingCount ?? cacheItem._extend?.quantity ?? 1);
1519
+ const capacity = cacheItem._extend?.capacity || [];
1520
+ const partySize = Array.isArray(capacity) ? Math.max(1, capacity.reduce((sum, item) => sum + Number(item.value), 0)) : NaN;
1521
+ if (!Number.isSafeInteger(productId) || productId <= 0 || !Number.isInteger(bookingCount) || bookingCount <= 0 || !Array.isArray(capacity) || !capacity.every(item => Number.isInteger(Number(item.value)) && Number(item.value) >= 0) || !Number.isInteger(partySize)) throw new _ResourcePlanner.AvailabilityError('INVALID_RESERVATION_QUANTITY', 'Invalid calendar booking quantity.');
1522
+ const product = normalizeProductForAvailability(cacheItem, this.getAvailabilityScheduleCatalog(), this.getAvailabilityRuntimeOffsetMinutes());
1523
+ if (product.kind !== 'duration' && product.kind !== 'session') return null;
1524
+ const range = {
1525
+ startAt: `${(0, _dayjs.default)(cacheItem._extend.start_date).format('YYYY-MM-DD')}T${cacheItem._extend.start_time}:00${(0, _localClock.formatFixedOffset)(this.getAvailabilityRuntimeOffsetMinutes())}`,
1526
+ endAt: `${(0, _dayjs.default)(cacheItem._extend.end_date).format('YYYY-MM-DD')}T${cacheItem._extend.end_time}:00${(0, _localClock.formatFixedOffset)(this.getAvailabilityRuntimeOffsetMinutes())}`
1527
+ };
1528
+ const requirementSelections = [];
1529
+ for (const [formId, rows] of Object.entries(cacheItem._extend?.resource || {})) {
1530
+ if (!Array.isArray(rows)) throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', 'Invalid selected calendar resources.');
1531
+ if (!rows.length) continue;
1532
+ const groups = (product.requirementGroups || []).filter(group => String(group.formId) === formId);
1533
+ if (groups.length !== 1 || rows.some(row => row.form_id != null && String(row.form_id) !== formId)) {
1534
+ throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', 'Calendar resource group does not belong to this product.');
1535
+ }
1536
+ requirementSelections.push({
1537
+ requirementGroupId: groups[0].id,
1538
+ formId: groups[0].formId,
1539
+ resourceIds: rows.map(row => row.relation_id ?? row.resource_id)
1540
+ });
1541
+ }
1542
+ const order = this.getTempOrder();
1543
+ const calendarOrderSessionId = this.getOrderSessionId();
1544
+ const scope = JSON.stringify(this.getAvailabilityScopeDescriptor());
1545
+ const assertCurrent = () => {
1546
+ options.availabilityCommitGuard?.();
1547
+ if (calendarOrderSessionId && !this.isOrderSessionCurrent(calendarOrderSessionId) || this.getTempOrder() !== order || JSON.stringify(this.getAvailabilityScopeDescriptor()) !== scope) {
1548
+ throw new _ResourcePlanner.AvailabilityError('AVAILABILITY_SELECTION_STALE', 'Calendar booking order changed.');
1549
+ }
1550
+ };
1551
+ let contextId;
1552
+ try {
1553
+ assertCurrent();
1554
+ const context = await this.prepareAvailabilityProjection({
1555
+ productIds: [productId],
1556
+ dateRange: {
1557
+ startDate: range.startAt.slice(0, 10),
1558
+ endDate: range.endAt.slice(0, 10)
1559
+ },
1560
+ rawProducts: [...this.unifiedProductCatalog.filter(item => String(item.id) !== String(productId)), cacheItem]
1561
+ });
1562
+ contextId = context.contextId;
1563
+ assertCurrent();
1564
+ const groups = await this.getProductTimeRanges(contextId, {
1565
+ productIds: [productId],
1566
+ requestedRangesByProductId: {
1567
+ [String(productId)]: range
1568
+ }
1569
+ });
1570
+ assertCurrent();
1571
+ const ranges = groups.find(group => String(group.productId) === String(productId))?.ranges || [];
1572
+ if (ranges.length !== 1) throw new _ResourcePlanner.AvailabilityError('REVALIDATION_FAILED', 'Calendar booking requires one exact interval.');
1573
+ const candidate = ranges[0];
1574
+ const contextEntry = this.getAvailabilityContextEntry(contextId);
1575
+ contextEntry.calendarOrderSessionId = calendarOrderSessionId ?? undefined;
1576
+ const projection = this.getActiveAvailabilityProjectionEntry(contextEntry).projection;
1577
+ const forced = buildPosForcedAvailabilityAssignments({
1578
+ product,
1579
+ resources: projection.resources,
1580
+ candidate,
1581
+ requirementSelections,
1582
+ partySize
1583
+ });
1584
+ if (forced.conflicts.length) throw new _ResourcePlanner.AvailabilityError('REVALIDATION_FAILED', 'Invalid calendar resource selection.', {
1585
+ validation: forced
1586
+ });
1587
+ return {
1588
+ cacheItem,
1589
+ contextId,
1590
+ candidate,
1591
+ requirementSelections,
1592
+ partySize,
1593
+ bookingCount
1594
+ };
1595
+ } catch (error) {
1596
+ if (contextId) this.releaseAvailabilityContext(contextId);
1597
+ throw error;
1598
+ }
1599
+ }
1510
1600
  async resolveAvailabilityPrepareDefaults(params) {
1511
1601
  const needsOperatingHours = params.businessHours === undefined;
1512
1602
  const needsTimeSlice = params.slotStepMinutes === undefined;
@@ -3598,12 +3688,12 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
3598
3688
  schedule_date: prepare.catalogScope.params.schedule_date || dateRange.startDate
3599
3689
  });
3600
3690
  }
3601
- const normalized = rawProducts.map(product => normalizeProductForAvailability(product, params.scheduleList, this.getAvailabilityRuntimeOffsetMinutes()));
3691
+ const productIdSet = explicitProductIds.length ? new Set(explicitProductIds.map(String)) : null;
3692
+ const normalized = (productIdSet ? rawProducts.filter(product => productIdSet.has(String(product.id ?? product.product_id))) : rawProducts).map(product => normalizeProductForAvailability(product, params.scheduleList, this.getAvailabilityRuntimeOffsetMinutes()));
3602
3693
  if (!explicitProductIds.length && prepare.resourceIds?.length) {
3603
3694
  return normalized.filter(product => product.requirementGroups?.some(group => group.resourceIds?.some(resourceId => prepare.resourceIds.some(id => sameAvailabilityId(id, resourceId)))));
3604
3695
  }
3605
- const productIdSet = explicitProductIds.length ? new Set(explicitProductIds.map(String)) : null;
3606
- return productIdSet ? normalized.filter(product => productIdSet.has(String(product.id))) : normalized;
3696
+ return normalized;
3607
3697
  }
3608
3698
 
3609
3699
  /**
@@ -4036,6 +4126,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4036
4126
  lastPreparedAt: params.projection.meta.preparedAt,
4037
4127
  lastSnapshotId: params.projection.meta.snapshotId,
4038
4128
  durationCandidateAnchorAt: previousContext?.durationCandidateAnchorAt ?? this.getAvailabilityDurationCandidateAnchorAt(params.projection),
4129
+ calendarOrderSessionId: previousContext?.calendarOrderSessionId,
4039
4130
  refreshNonce: previousContext?.refreshNonce ?? 0,
4040
4131
  lifecycleGeneration: this.availabilityLifecycleGeneration
4041
4132
  };
@@ -4370,6 +4461,27 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4370
4461
  const isPosAvailabilityRequest = String(this.otherParams?.platform ?? '').trim().toLowerCase() === 'pos';
4371
4462
  const isEditingContext = Boolean(context.prepareParams.editingProductLineUids?.length);
4372
4463
  const editingOffset = (0, _localClock.extractFixedOffsetMinutes)(projectionEntry.projection.meta.now) ?? this.getAvailabilityRuntimeOffsetMinutes();
4464
+ const hasRequestedRanges = Object.keys(request.requestedRangesByProductId || {}).length > 0;
4465
+ if (hasRequestedRanges && (!isPosAvailabilityRequest || strictAvailability || request.rememberedStartAtByProductId || request.rememberedTimeByProductId)) {
4466
+ throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', '明确预约范围仅支持 POS 手工选择');
4467
+ }
4468
+ // Calendar entry carries absolute instants. Convert both endpoints once to
4469
+ // the projection clock; never reinterpret their HH:mm as a business date.
4470
+ const requestedRangesByProductId = hasRequestedRanges ? Object.fromEntries(Object.entries(request.requestedRangesByProductId).map(([productId, range]) => {
4471
+ try {
4472
+ const normalizeEndpoint = value => {
4473
+ const scalar = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(value));
4474
+ const inputOffset = (0, _localClock.extractFixedOffsetMinutes)(value) ?? editingOffset;
4475
+ return (0, _localClock.formatLocalDateTime)(scalar + (editingOffset - inputOffset) * 60000, editingOffset);
4476
+ };
4477
+ return [productId, {
4478
+ startAt: normalizeEndpoint(range.startAt),
4479
+ endAt: normalizeEndpoint(range.endAt)
4480
+ }];
4481
+ } catch {
4482
+ throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', '手工预约范围必须包含完整有效起止日期时间');
4483
+ }
4484
+ })) : undefined;
4373
4485
  // This new editing input represents an absolute instant. Normalize it once
4374
4486
  // to the projection's fixed business clock before the wall-clock planner.
4375
4487
  const editingStartAtByProductId = isEditingContext && request.editingStartAtByProductId ? Object.fromEntries(Object.entries(request.editingStartAtByProductId).map(([productId, startAt]) => {
@@ -4399,6 +4511,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4399
4511
  ...request,
4400
4512
  dateRange,
4401
4513
  editingStartAtByProductId,
4514
+ requestedRangesByProductId,
4402
4515
  rememberedStartAtByProductId,
4403
4516
  rememberedTimeByProductId,
4404
4517
  ...(rememberedStartAtByProductId || rememberedTimeByProductId ? {
@@ -4417,6 +4530,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4417
4530
  rememberedTimeByProductId,
4418
4531
  useExactDurationCandidateMinute: isPosAvailabilityRequest && !strictAvailability,
4419
4532
  allowSessionCustomRanges: isPosAvailabilityRequest && !strictAvailability,
4533
+ allowRequestedRanges: isPosAvailabilityRequest && !strictAvailability && !rememberedStartAtByProductId && !rememberedTimeByProductId,
4420
4534
  allowExcludedScheduleDateOverride: isPosAvailabilityRequest && !strictAvailability
4421
4535
  }).map(group => ({
4422
4536
  ...group,
@@ -4563,6 +4677,19 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4563
4677
  candidate: params.candidate
4564
4678
  });
4565
4679
  }
4680
+ const calendarOrderSessionId = this.availabilityContextRegistry.get(normalizedContextId)?.calendarOrderSessionId;
4681
+ if (calendarOrderSessionId) {
4682
+ const callerGuard = params.availabilityCommitGuard;
4683
+ params = {
4684
+ ...params,
4685
+ availabilityCommitGuard: () => {
4686
+ callerGuard?.();
4687
+ if (!this.isOrderSessionCurrent(calendarOrderSessionId)) {
4688
+ throw new _ResourcePlanner.AvailabilityError('AVAILABILITY_SELECTION_STALE', 'Calendar booking order session changed.');
4689
+ }
4690
+ }
4691
+ };
4692
+ }
4566
4693
  const isEditingSelection = params.mode === 'edit' || params.mode === 'replace';
4567
4694
  const isPartyReplacement = params.mode === 'replace' || params.relatedRetailProducts !== undefined;
4568
4695
  if (isPartyReplacement && (!isEditingSelection || !Array.isArray(params.relatedRetailProducts))) {
@@ -4762,6 +4889,14 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4762
4889
  startDate: candidateBusinessDate,
4763
4890
  endDate: candidateBusinessDate
4764
4891
  },
4892
+ ...(allowPosAvailabilityOverride && params.candidate.source === 'duration_window' ? {
4893
+ requestedRangesByProductId: {
4894
+ [String(params.candidate.productId)]: {
4895
+ startAt: params.candidate.bookingStartAt,
4896
+ endAt: params.candidate.bookingEndAt
4897
+ }
4898
+ }
4899
+ } : {}),
4765
4900
  ...(rememberedTimeByProductId ? {
4766
4901
  rememberedTimeByProductId
4767
4902
  } : isRememberedSelection ? {
@@ -4798,6 +4933,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4798
4933
  rememberedTimeByProductId,
4799
4934
  useExactDurationCandidateMinute: allowPosAvailabilityOverride,
4800
4935
  allowSessionCustomRanges: allowPosAvailabilityOverride,
4936
+ allowRequestedRanges: allowPosAvailabilityOverride,
4801
4937
  allowExcludedScheduleDateOverride: allowPosAvailabilityOverride
4802
4938
  }).flatMap(group => group.ranges);
4803
4939
  const refreshedCandidateBase = refreshedRanges.find(candidate => candidate.startAt === params.candidate.startAt && candidate.endAt === params.candidate.endAt && candidate.bookingStartAt === params.candidate.bookingStartAt && candidate.bookingEndAt === params.candidate.bookingEndAt);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.195",
4
+ "version": "2.3.196",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",