@wix/headless-bookings 1.0.7 → 1.0.8

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.
@@ -56,6 +56,7 @@ function createMockBookingService(config = {}) {
56
56
  setFormSubmission: vitest_1.vi.fn(),
57
57
  clearFormSubmission: vitest_1.vi.fn(),
58
58
  setSelectedPaymentOption: vitest_1.vi.fn(),
59
+ setAllDay: vitest_1.vi.fn(),
59
60
  clearAll: vitest_1.vi.fn(),
60
61
  book: vitest_1.vi.fn(),
61
62
  },
@@ -38,7 +38,11 @@ async function executeBookAction(params) {
38
38
  // it from the service's first configured location.
39
39
  firstSelection.service.locations?.[0]?._id
40
40
  : firstSelection.timeSlot?.location?._id;
41
- const cartRequest = isDayRange
41
+ // `allDay` DAY-range bookings collapse to a single booking ID, so they use
42
+ // the single-booking cart shape (like the default path). Only the per-slot
43
+ // DAY-range expansion produces N>1 ids needing the multi-item cart.
44
+ const isMultiBookingCart = isDayRange && !params.allDay;
45
+ const cartRequest = isMultiBookingCart
42
46
  ? (0, buildCartRequest_js_1.buildDayRangeCartRequest)({
43
47
  bookingIds,
44
48
  contactDetails,
@@ -110,8 +110,6 @@ function mapTimeSlotLocationTypeToBookingLocationType(slotLocationType) {
110
110
  return auto_sdk_bookings_bookings_1.LocationType.CUSTOM;
111
111
  case auto_sdk_bookings_availability_time_slots_1.LocationType.CUSTOM:
112
112
  return auto_sdk_bookings_bookings_1.LocationType.OWNER_CUSTOM;
113
- case auto_sdk_bookings_availability_time_slots_1.LocationType.UNKNOWN_LOCATION_TYPE:
114
- return auto_sdk_bookings_bookings_1.LocationType.UNDEFINED;
115
113
  default:
116
114
  return auto_sdk_bookings_bookings_1.LocationType.OWNER_BUSINESS;
117
115
  }
@@ -16,7 +16,9 @@ import type { FormValues } from '@wix/forms/components';
16
16
  import type { BookActionParams } from './types.js';
17
17
  export interface BuildDayRangeBookingRequest {
18
18
  /**
19
- * One Booking per picked per-day slot. Length 1 routes to bulkCreateBooking,
19
+ * The Bookings to create. With `allDay`, this is a single Booking spanning
20
+ * the whole range, routed to plain `createBooking`. Otherwise it is one
21
+ * Booking per picked per-day slot: length 1 routes to bulkCreateBooking,
20
22
  * length >=2 routes to createMultiServiceBooking.
21
23
  */
22
24
  bookings: Booking[];
@@ -47,21 +47,25 @@ function buildDayRangeBookingRequest(params) {
47
47
  ...params,
48
48
  serviceSelections: [baseSelection, ...params.serviceSelections.slice(1)],
49
49
  });
50
- const bookings = slots.map((slot) => ({
50
+ // Clone the base Booking, overriding only the slot start/end.
51
+ const buildBooking = (startDate, endDate) => ({
51
52
  ...baseRequest.booking,
52
53
  bookedEntity: {
53
54
  ...baseRequest.booking.bookedEntity,
54
55
  slot: {
55
56
  ...baseRequest.booking.bookedEntity?.slot,
56
- startDate: slot.startDate,
57
- endDate: slot.endDate,
57
+ startDate,
58
+ endDate,
58
59
  },
59
60
  },
60
- }));
61
- // TODO(createAsOneBooking): when the server flag lands, this builder should
62
- // optionally collapse all slots into a single Booking spanning
63
- // `slots[0].startDate -> slots[N-1].endDate` with `fullDay: true`, and
64
- // routing should use plain `createBooking` (not bulk / multi-service).
61
+ });
62
+ // `allDay`: collapse every picked slot into one Booking spanning the whole
63
+ // range (`slots[0].startDate -> slots[N-1].endDate`). `createBookingsForCart`
64
+ // then routes this single Booking through plain `createBooking` instead of
65
+ // bulk / multi-service. Otherwise, emit one Booking per picked slot.
66
+ const bookings = params.allDay
67
+ ? [buildBooking(slots[0].startDate, slots[slots.length - 1].endDate)]
68
+ : slots.map((slot) => buildBooking(slot.startDate, slot.endDate));
65
69
  return {
66
70
  bookings,
67
71
  participantNotification: baseRequest.participantNotification,
@@ -2,9 +2,10 @@
2
2
  * Creates the booking(s) needed for cart construction.
3
3
  *
4
4
  * Branches on the service selection:
5
- * - DAY-range path with 1 picked slot -> `bulkCreateBooking`
5
+ * - DAY-range path with `allDay` -> `createBooking` (one combined Booking)
6
+ * - DAY-range path with 1 picked slot -> `bulkCreateBooking`
6
7
  * - DAY-range path with 2..8 picked slots -> `createMultiServiceBooking`
7
- * - default path -> `createBooking`
8
+ * - default path -> `createBooking`
8
9
  *
9
10
  * All branches return the same shape so `executeBookAction` can stay
10
11
  * branchless from cart-creation onwards. Cart construction reads each
@@ -3,9 +3,10 @@
3
3
  * Creates the booking(s) needed for cart construction.
4
4
  *
5
5
  * Branches on the service selection:
6
- * - DAY-range path with 1 picked slot -> `bulkCreateBooking`
6
+ * - DAY-range path with `allDay` -> `createBooking` (one combined Booking)
7
+ * - DAY-range path with 1 picked slot -> `bulkCreateBooking`
7
8
  * - DAY-range path with 2..8 picked slots -> `createMultiServiceBooking`
8
- * - default path -> `createBooking`
9
+ * - default path -> `createBooking`
9
10
  *
10
11
  * All branches return the same shape so `executeBookAction` can stay
11
12
  * branchless from cart-creation onwards. Cart construction reads each
@@ -27,10 +28,20 @@ async function createBookingsForCart(params) {
27
28
  }
28
29
  if ((0, dayRange_js_1.isDayRangeService)(firstSelection.service)) {
29
30
  const req = (0, buildDayRangeBookingRequest_js_1.buildDayRangeBookingRequest)(params);
30
- // TODO(createAsOneBooking): when the server flag lands, branch here:
31
- // if (createAsOneBooking) -> createBooking({ ...wideRange, fullDay: true })
32
- // collapsing all slots into one combined Booking. Until then, we always
33
- // use one Booking per picked slot.
31
+ // `allDay`: the builder has already collapsed the range into a single
32
+ // Booking. Create it with plain `createBooking` (not bulk / multi-service).
33
+ if (params.allDay) {
34
+ const bookingResponse = await (0, index_js_1.createBooking)(req.bookings[0], {
35
+ participantNotification: req.participantNotification,
36
+ sendSmsReminder: req.sendSmsReminder,
37
+ formSubmission: req.formSubmission,
38
+ });
39
+ const bookingId = bookingResponse.booking?._id;
40
+ return {
41
+ bookingIds: bookingId ? [bookingId] : [],
42
+ contactDetails: bookingResponse.booking?.contactDetails,
43
+ };
44
+ }
34
45
  if (req.bookings.length === 1) {
35
46
  const response = await (0, index_js_2.bulkCreateBooking)([{ booking: req.bookings[0] }], {
36
47
  participantNotification: req.participantNotification,
@@ -53,6 +53,14 @@ export interface BookActionParams {
53
53
  * service. When omitted, the existing service-config heuristic applies.
54
54
  */
55
55
  selectedPaymentOption?: SelectedPaymentOption;
56
+ /**
57
+ * DAY-range only. When `true`, the picked per-day slots are collapsed into a
58
+ * single Booking spanning the whole range (`firstSlot.startDate ->
59
+ * lastSlot.endDate`) and created via plain `createBooking` — instead of the
60
+ * default per-slot expansion that routes to `bulkCreateBooking` (1 slot) or
61
+ * `createMultiServiceBooking` (2-8 slots). Ignored for non-DAY-range services.
62
+ */
63
+ allDay?: boolean;
56
64
  }
57
65
  /**
58
66
  * Props passed to children of Book component
@@ -88,6 +88,13 @@ export interface BookingServiceActions {
88
88
  * is cleared and the heuristic applies again.
89
89
  */
90
90
  setSelectedPaymentOption(value: SelectedPaymentOption | null): void;
91
+ /**
92
+ * Toggle the DAY-range `allDay` flag. When `true`, `book()` collapses the
93
+ * picked per-day slots of a DAY-range service into a single Booking created
94
+ * via `createBooking` (instead of the per-slot bulk / multi-service path).
95
+ * Ignored for non-DAY-range services.
96
+ */
97
+ setAllDay(value: boolean): void;
91
98
  clearAll(): void;
92
99
  book(): Promise<BookResult>;
93
100
  }
@@ -74,6 +74,10 @@ exports.BookingService = services_definitions_1.implementService.withConfig()(ex
74
74
  const timezoneSignal = signalsService.signal(config.timezone ?? getClientTimezone());
75
75
  const formSubmissionSignal = signalsService.signal(config.formSubmission || null);
76
76
  const selectedPaymentOptionSignal = signalsService.signal(config.selectedPaymentOption);
77
+ // Internal-only signal: set via `setAllDay`, read by `book()`. Not
78
+ // exposed on the service surface — consumers derive and push the value
79
+ // (e.g. from the picker's selection mode), so there's no read-back.
80
+ const allDaySignal = signalsService.signal(false);
77
81
  // ========================================================================
78
82
  // Helpers
79
83
  // ========================================================================
@@ -172,11 +176,16 @@ exports.BookingService = services_definitions_1.implementService.withConfig()(ex
172
176
  setSelectedPaymentOption(value) {
173
177
  selectedPaymentOptionSignal.set(value ?? undefined);
174
178
  },
179
+ // All-day (DAY-range) action
180
+ setAllDay(value) {
181
+ allDaySignal.set(value);
182
+ },
175
183
  // Clear all
176
184
  clearAll() {
177
185
  this.clearItems();
178
186
  this.clearLocation();
179
187
  this.clearFormSubmission();
188
+ this.setAllDay(false);
180
189
  },
181
190
  // Book action - collects data from signals and delegates to executeBookAction
182
191
  // Loading/error state management is handled in Book.tsx component
@@ -186,6 +195,7 @@ exports.BookingService = services_definitions_1.implementService.withConfig()(ex
186
195
  const location = locationSignal.get();
187
196
  const timezone = timezoneSignal.get();
188
197
  const selectedPaymentOption = selectedPaymentOptionSignal.get();
198
+ const allDay = allDaySignal.get();
189
199
  // Validation happens inside executeBookAction
190
200
  return (0, bookAction_js_1.executeBookAction)({
191
201
  serviceSelections,
@@ -194,6 +204,7 @@ exports.BookingService = services_definitions_1.implementService.withConfig()(ex
194
204
  timezone,
195
205
  appId: config.appId,
196
206
  selectedPaymentOption,
207
+ allDay,
197
208
  });
198
209
  },
199
210
  };
@@ -51,6 +51,7 @@ export function createMockBookingService(config = {}) {
51
51
  setFormSubmission: vi.fn(),
52
52
  clearFormSubmission: vi.fn(),
53
53
  setSelectedPaymentOption: vi.fn(),
54
+ setAllDay: vi.fn(),
54
55
  clearAll: vi.fn(),
55
56
  book: vi.fn(),
56
57
  },
@@ -35,7 +35,11 @@ export async function executeBookAction(params) {
35
35
  // it from the service's first configured location.
36
36
  firstSelection.service.locations?.[0]?._id
37
37
  : firstSelection.timeSlot?.location?._id;
38
- const cartRequest = isDayRange
38
+ // `allDay` DAY-range bookings collapse to a single booking ID, so they use
39
+ // the single-booking cart shape (like the default path). Only the per-slot
40
+ // DAY-range expansion produces N>1 ids needing the multi-item cart.
41
+ const isMultiBookingCart = isDayRange && !params.allDay;
42
+ const cartRequest = isMultiBookingCart
39
43
  ? buildDayRangeCartRequest({
40
44
  bookingIds,
41
45
  contactDetails,
@@ -107,8 +107,6 @@ function mapTimeSlotLocationTypeToBookingLocationType(slotLocationType) {
107
107
  return BookingLocationType.CUSTOM;
108
108
  case TimeSlotLocationType.CUSTOM:
109
109
  return BookingLocationType.OWNER_CUSTOM;
110
- case TimeSlotLocationType.UNKNOWN_LOCATION_TYPE:
111
- return BookingLocationType.UNDEFINED;
112
110
  default:
113
111
  return BookingLocationType.OWNER_BUSINESS;
114
112
  }
@@ -16,7 +16,9 @@ import type { FormValues } from '@wix/forms/components';
16
16
  import type { BookActionParams } from './types.js';
17
17
  export interface BuildDayRangeBookingRequest {
18
18
  /**
19
- * One Booking per picked per-day slot. Length 1 routes to bulkCreateBooking,
19
+ * The Bookings to create. With `allDay`, this is a single Booking spanning
20
+ * the whole range, routed to plain `createBooking`. Otherwise it is one
21
+ * Booking per picked per-day slot: length 1 routes to bulkCreateBooking,
20
22
  * length >=2 routes to createMultiServiceBooking.
21
23
  */
22
24
  bookings: Booking[];
@@ -44,21 +44,25 @@ export function buildDayRangeBookingRequest(params) {
44
44
  ...params,
45
45
  serviceSelections: [baseSelection, ...params.serviceSelections.slice(1)],
46
46
  });
47
- const bookings = slots.map((slot) => ({
47
+ // Clone the base Booking, overriding only the slot start/end.
48
+ const buildBooking = (startDate, endDate) => ({
48
49
  ...baseRequest.booking,
49
50
  bookedEntity: {
50
51
  ...baseRequest.booking.bookedEntity,
51
52
  slot: {
52
53
  ...baseRequest.booking.bookedEntity?.slot,
53
- startDate: slot.startDate,
54
- endDate: slot.endDate,
54
+ startDate,
55
+ endDate,
55
56
  },
56
57
  },
57
- }));
58
- // TODO(createAsOneBooking): when the server flag lands, this builder should
59
- // optionally collapse all slots into a single Booking spanning
60
- // `slots[0].startDate -> slots[N-1].endDate` with `fullDay: true`, and
61
- // routing should use plain `createBooking` (not bulk / multi-service).
58
+ });
59
+ // `allDay`: collapse every picked slot into one Booking spanning the whole
60
+ // range (`slots[0].startDate -> slots[N-1].endDate`). `createBookingsForCart`
61
+ // then routes this single Booking through plain `createBooking` instead of
62
+ // bulk / multi-service. Otherwise, emit one Booking per picked slot.
63
+ const bookings = params.allDay
64
+ ? [buildBooking(slots[0].startDate, slots[slots.length - 1].endDate)]
65
+ : slots.map((slot) => buildBooking(slot.startDate, slot.endDate));
62
66
  return {
63
67
  bookings,
64
68
  participantNotification: baseRequest.participantNotification,
@@ -2,9 +2,10 @@
2
2
  * Creates the booking(s) needed for cart construction.
3
3
  *
4
4
  * Branches on the service selection:
5
- * - DAY-range path with 1 picked slot -> `bulkCreateBooking`
5
+ * - DAY-range path with `allDay` -> `createBooking` (one combined Booking)
6
+ * - DAY-range path with 1 picked slot -> `bulkCreateBooking`
6
7
  * - DAY-range path with 2..8 picked slots -> `createMultiServiceBooking`
7
- * - default path -> `createBooking`
8
+ * - default path -> `createBooking`
8
9
  *
9
10
  * All branches return the same shape so `executeBookAction` can stay
10
11
  * branchless from cart-creation onwards. Cart construction reads each
@@ -2,9 +2,10 @@
2
2
  * Creates the booking(s) needed for cart construction.
3
3
  *
4
4
  * Branches on the service selection:
5
- * - DAY-range path with 1 picked slot -> `bulkCreateBooking`
5
+ * - DAY-range path with `allDay` -> `createBooking` (one combined Booking)
6
+ * - DAY-range path with 1 picked slot -> `bulkCreateBooking`
6
7
  * - DAY-range path with 2..8 picked slots -> `createMultiServiceBooking`
7
- * - default path -> `createBooking`
8
+ * - default path -> `createBooking`
8
9
  *
9
10
  * All branches return the same shape so `executeBookAction` can stay
10
11
  * branchless from cart-creation onwards. Cart construction reads each
@@ -24,10 +25,20 @@ export async function createBookingsForCart(params) {
24
25
  }
25
26
  if (isDayRangeService(firstSelection.service)) {
26
27
  const req = buildDayRangeBookingRequest(params);
27
- // TODO(createAsOneBooking): when the server flag lands, branch here:
28
- // if (createAsOneBooking) -> createBooking({ ...wideRange, fullDay: true })
29
- // collapsing all slots into one combined Booking. Until then, we always
30
- // use one Booking per picked slot.
28
+ // `allDay`: the builder has already collapsed the range into a single
29
+ // Booking. Create it with plain `createBooking` (not bulk / multi-service).
30
+ if (params.allDay) {
31
+ const bookingResponse = await createBooking(req.bookings[0], {
32
+ participantNotification: req.participantNotification,
33
+ sendSmsReminder: req.sendSmsReminder,
34
+ formSubmission: req.formSubmission,
35
+ });
36
+ const bookingId = bookingResponse.booking?._id;
37
+ return {
38
+ bookingIds: bookingId ? [bookingId] : [],
39
+ contactDetails: bookingResponse.booking?.contactDetails,
40
+ };
41
+ }
31
42
  if (req.bookings.length === 1) {
32
43
  const response = await bulkCreateBooking([{ booking: req.bookings[0] }], {
33
44
  participantNotification: req.participantNotification,
@@ -53,6 +53,14 @@ export interface BookActionParams {
53
53
  * service. When omitted, the existing service-config heuristic applies.
54
54
  */
55
55
  selectedPaymentOption?: SelectedPaymentOption;
56
+ /**
57
+ * DAY-range only. When `true`, the picked per-day slots are collapsed into a
58
+ * single Booking spanning the whole range (`firstSlot.startDate ->
59
+ * lastSlot.endDate`) and created via plain `createBooking` — instead of the
60
+ * default per-slot expansion that routes to `bulkCreateBooking` (1 slot) or
61
+ * `createMultiServiceBooking` (2-8 slots). Ignored for non-DAY-range services.
62
+ */
63
+ allDay?: boolean;
56
64
  }
57
65
  /**
58
66
  * Props passed to children of Book component
@@ -88,6 +88,13 @@ export interface BookingServiceActions {
88
88
  * is cleared and the heuristic applies again.
89
89
  */
90
90
  setSelectedPaymentOption(value: SelectedPaymentOption | null): void;
91
+ /**
92
+ * Toggle the DAY-range `allDay` flag. When `true`, `book()` collapses the
93
+ * picked per-day slots of a DAY-range service into a single Booking created
94
+ * via `createBooking` (instead of the per-slot bulk / multi-service path).
95
+ * Ignored for non-DAY-range services.
96
+ */
97
+ setAllDay(value: boolean): void;
91
98
  clearAll(): void;
92
99
  book(): Promise<BookResult>;
93
100
  }
@@ -71,6 +71,10 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
71
71
  const timezoneSignal = signalsService.signal(config.timezone ?? getClientTimezone());
72
72
  const formSubmissionSignal = signalsService.signal(config.formSubmission || null);
73
73
  const selectedPaymentOptionSignal = signalsService.signal(config.selectedPaymentOption);
74
+ // Internal-only signal: set via `setAllDay`, read by `book()`. Not
75
+ // exposed on the service surface — consumers derive and push the value
76
+ // (e.g. from the picker's selection mode), so there's no read-back.
77
+ const allDaySignal = signalsService.signal(false);
74
78
  // ========================================================================
75
79
  // Helpers
76
80
  // ========================================================================
@@ -169,11 +173,16 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
169
173
  setSelectedPaymentOption(value) {
170
174
  selectedPaymentOptionSignal.set(value ?? undefined);
171
175
  },
176
+ // All-day (DAY-range) action
177
+ setAllDay(value) {
178
+ allDaySignal.set(value);
179
+ },
172
180
  // Clear all
173
181
  clearAll() {
174
182
  this.clearItems();
175
183
  this.clearLocation();
176
184
  this.clearFormSubmission();
185
+ this.setAllDay(false);
177
186
  },
178
187
  // Book action - collects data from signals and delegates to executeBookAction
179
188
  // Loading/error state management is handled in Book.tsx component
@@ -183,6 +192,7 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
183
192
  const location = locationSignal.get();
184
193
  const timezone = timezoneSignal.get();
185
194
  const selectedPaymentOption = selectedPaymentOptionSignal.get();
195
+ const allDay = allDaySignal.get();
186
196
  // Validation happens inside executeBookAction
187
197
  return executeBookAction({
188
198
  serviceSelections,
@@ -191,6 +201,7 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
191
201
  timezone,
192
202
  appId: config.appId,
193
203
  selectedPaymentOption,
204
+ allDay,
194
205
  });
195
206
  },
196
207
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-bookings",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -34,6 +34,7 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
+ "@wix/auto_sdk_bookings_availability-time-slots": "^1.0.244",
37
38
  "@wix/auto_sdk_bookings_bookings": "^1.0.192",
38
39
  "@wix/auto_sdk_bookings_event-time-slots": "^1.0.112",
39
40
  "@wix/auto_sdk_bookings_pricing": "^1.0.87",
@@ -75,5 +76,5 @@
75
76
  "groupId": "com.wixpress.headless-components"
76
77
  }
77
78
  },
78
- "falconPackageHash": "60796dfbabc73eb7b2ec7543eb4062986b78906203ede122471a8080"
79
+ "falconPackageHash": "fd8f02351f0165bcc83688ccbf4bafc628fde453ffb4fc6e0ead24dc"
79
80
  }