@wix/headless-bookings 1.0.4 → 1.0.6

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 (67) hide show
  1. package/cjs/dist/__mocks__/booking/booking-client-service.js +4 -1
  2. package/cjs/dist/api/create-booking/index.d.ts +4 -4
  3. package/cjs/dist/api/create-bulk-booking/index.d.ts +54 -0
  4. package/cjs/dist/api/create-bulk-booking/index.js +54 -0
  5. package/cjs/dist/api/create-multi-service-booking/index.d.ts +53 -0
  6. package/cjs/dist/api/create-multi-service-booking/index.js +47 -0
  7. package/cjs/dist/api/index.d.ts +4 -1
  8. package/cjs/dist/api/index.js +32 -13
  9. package/cjs/dist/react/core/booking/Booking.d.ts +6 -1
  10. package/cjs/dist/react/core/booking/Booking.js +2 -0
  11. package/cjs/dist/services/booking/book-action/bookAction.js +39 -27
  12. package/cjs/dist/services/booking/book-action/buildBookingRequest.d.ts +1 -1
  13. package/cjs/dist/services/booking/book-action/buildBookingRequest.js +4 -2
  14. package/cjs/dist/services/booking/book-action/buildCartRequest.d.ts +20 -2
  15. package/cjs/dist/services/booking/book-action/buildCartRequest.js +24 -13
  16. package/cjs/dist/services/booking/book-action/buildDayRangeBookingRequest.d.ts +37 -0
  17. package/cjs/dist/services/booking/book-action/buildDayRangeBookingRequest.js +70 -0
  18. package/cjs/dist/services/booking/book-action/canBook.d.ts +2 -1
  19. package/cjs/dist/services/booking/book-action/canBook.js +4 -2
  20. package/cjs/dist/services/booking/book-action/createBookingsForCart.d.ts +22 -0
  21. package/cjs/dist/services/booking/book-action/createBookingsForCart.js +69 -0
  22. package/cjs/dist/services/booking/book-action/dayRange.d.ts +34 -0
  23. package/cjs/dist/services/booking/book-action/dayRange.js +43 -0
  24. package/cjs/dist/services/booking/book-action/index.d.ts +9 -6
  25. package/cjs/dist/services/booking/book-action/index.js +23 -13
  26. package/cjs/dist/services/booking/book-action/types.d.ts +15 -0
  27. package/cjs/dist/services/booking/booking.d.ts +31 -2
  28. package/cjs/dist/services/booking/booking.js +8 -0
  29. package/cjs/dist/services/index.d.ts +1 -1
  30. package/cjs/dist/services/index.js +6 -1
  31. package/cjs/dist/services/payment/payment.d.ts +4 -0
  32. package/cjs/dist/services/payment/payment.def.d.ts +6 -0
  33. package/cjs/dist/services/payment/payment.js +39 -17
  34. package/dist/__mocks__/booking/booking-client-service.js +4 -1
  35. package/dist/api/create-booking/index.d.ts +4 -4
  36. package/dist/api/create-bulk-booking/index.d.ts +54 -0
  37. package/dist/api/create-bulk-booking/index.js +51 -0
  38. package/dist/api/create-multi-service-booking/index.d.ts +53 -0
  39. package/dist/api/create-multi-service-booking/index.js +44 -0
  40. package/dist/api/index.d.ts +4 -1
  41. package/dist/api/index.js +3 -0
  42. package/dist/react/core/booking/Booking.d.ts +6 -1
  43. package/dist/react/core/booking/Booking.js +2 -0
  44. package/dist/services/booking/book-action/bookAction.js +34 -22
  45. package/dist/services/booking/book-action/buildBookingRequest.d.ts +1 -1
  46. package/dist/services/booking/book-action/buildBookingRequest.js +4 -2
  47. package/dist/services/booking/book-action/buildCartRequest.d.ts +20 -2
  48. package/dist/services/booking/book-action/buildCartRequest.js +23 -13
  49. package/dist/services/booking/book-action/buildDayRangeBookingRequest.d.ts +37 -0
  50. package/dist/services/booking/book-action/buildDayRangeBookingRequest.js +67 -0
  51. package/dist/services/booking/book-action/canBook.d.ts +2 -1
  52. package/dist/services/booking/book-action/canBook.js +4 -2
  53. package/dist/services/booking/book-action/createBookingsForCart.d.ts +22 -0
  54. package/dist/services/booking/book-action/createBookingsForCart.js +66 -0
  55. package/dist/services/booking/book-action/dayRange.d.ts +34 -0
  56. package/dist/services/booking/book-action/dayRange.js +39 -0
  57. package/dist/services/booking/book-action/index.d.ts +9 -6
  58. package/dist/services/booking/book-action/index.js +9 -6
  59. package/dist/services/booking/book-action/types.d.ts +15 -0
  60. package/dist/services/booking/booking.d.ts +31 -2
  61. package/dist/services/booking/booking.js +8 -0
  62. package/dist/services/index.d.ts +1 -1
  63. package/dist/services/index.js +1 -1
  64. package/dist/services/payment/payment.d.ts +4 -0
  65. package/dist/services/payment/payment.def.d.ts +6 -0
  66. package/dist/services/payment/payment.js +39 -17
  67. package/package.json +2 -2
@@ -1,7 +1,28 @@
1
1
  import { ChannelType, } from '../../../api/create-cart/index.js';
2
2
  import { BOOKING_APP_ID } from '../../constants.js';
3
3
  export function buildCartRequest(params) {
4
- const { bookingId, contactDetails, businessLocationId, appId } = params;
4
+ return {
5
+ catalogItems: [buildCatalogItem(params.bookingId, params.appId)],
6
+ cart: buildCartShape(params),
7
+ };
8
+ }
9
+ export function buildDayRangeCartRequest(params) {
10
+ return {
11
+ catalogItems: params.bookingIds.map((id) => buildCatalogItem(id, params.appId)),
12
+ cart: buildCartShape(params),
13
+ };
14
+ }
15
+ function buildCatalogItem(bookingId, appId) {
16
+ return {
17
+ quantity: 1,
18
+ catalogReference: {
19
+ catalogItemId: bookingId,
20
+ appId: appId ?? BOOKING_APP_ID,
21
+ },
22
+ };
23
+ }
24
+ function buildCartShape(params) {
25
+ const { contactDetails, businessLocationId } = params;
5
26
  const cart = {
6
27
  source: { channelType: ChannelType.WEB },
7
28
  };
@@ -19,16 +40,5 @@ export function buildCartRequest(params) {
19
40
  };
20
41
  }
21
42
  }
22
- return {
23
- catalogItems: [
24
- {
25
- quantity: 1,
26
- catalogReference: {
27
- catalogItemId: bookingId,
28
- appId: appId ?? BOOKING_APP_ID,
29
- },
30
- },
31
- ],
32
- cart,
33
- };
43
+ return cart;
34
44
  }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Builds the request payload(s) for a single APPOINTMENT service whose
3
+ * duration is configured as a DAY range.
4
+ *
5
+ * The slot list comes from availability — the user picks a start + end date
6
+ * and the picker emits one slot per day in `rangeTimeSlots`. The client just
7
+ * packages them as one Booking each. Routing is decided by `bookings.length`
8
+ * in `createBookingsForCart`:
9
+ * - length 1 -> `bulkCreateBooking`
10
+ * - length 2-8 -> `createMultiServiceBooking`
11
+ *
12
+ * The 8-day cap is enforced server-side; the builder does not gate on it.
13
+ */
14
+ import type { Booking, ParticipantNotification } from '@wix/auto_sdk_bookings_bookings';
15
+ import type { BookActionParams } from './types.js';
16
+ export interface BuildDayRangeBookingRequest {
17
+ /**
18
+ * One Booking per picked per-day slot. Length 1 routes to bulkCreateBooking,
19
+ * length >=2 routes to createMultiServiceBooking.
20
+ */
21
+ bookings: Booking[];
22
+ /** Notification settings forwarded to the server. */
23
+ participantNotification?: ParticipantNotification;
24
+ /** Whether to send SMS reminder. */
25
+ sendSmsReminder: boolean;
26
+ }
27
+ /**
28
+ * Builds N Bookings from a DAY-range selection.
29
+ *
30
+ * The base Booking (service, resource, location, payment, participants) is
31
+ * produced by `buildBookingRequest` from the singular `timeSlot`; per-slot
32
+ * cloning then overrides only `bookedEntity.slot.startDate` / `endDate` from
33
+ * the multi-slot input.
34
+ *
35
+ * @throws if no service selection or no slots are available.
36
+ */
37
+ export declare function buildDayRangeBookingRequest(params: BookActionParams): BuildDayRangeBookingRequest;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Builds the request payload(s) for a single APPOINTMENT service whose
3
+ * duration is configured as a DAY range.
4
+ *
5
+ * The slot list comes from availability — the user picks a start + end date
6
+ * and the picker emits one slot per day in `rangeTimeSlots`. The client just
7
+ * packages them as one Booking each. Routing is decided by `bookings.length`
8
+ * in `createBookingsForCart`:
9
+ * - length 1 -> `bulkCreateBooking`
10
+ * - length 2-8 -> `createMultiServiceBooking`
11
+ *
12
+ * The 8-day cap is enforced server-side; the builder does not gate on it.
13
+ */
14
+ import { buildBookingRequest } from './buildBookingRequest.js';
15
+ /**
16
+ * Builds N Bookings from a DAY-range selection.
17
+ *
18
+ * The base Booking (service, resource, location, payment, participants) is
19
+ * produced by `buildBookingRequest` from the singular `timeSlot`; per-slot
20
+ * cloning then overrides only `bookedEntity.slot.startDate` / `endDate` from
21
+ * the multi-slot input.
22
+ *
23
+ * @throws if no service selection or no slots are available.
24
+ */
25
+ export function buildDayRangeBookingRequest(params) {
26
+ const item = params.serviceSelections[0];
27
+ if (!item) {
28
+ throw new Error('No service selection provided');
29
+ }
30
+ const slots = item.rangeTimeSlots && item.rangeTimeSlots.length > 0
31
+ ? item.rangeTimeSlots
32
+ : item.timeSlot
33
+ ? [item.timeSlot]
34
+ : [];
35
+ if (slots.length === 0) {
36
+ throw new Error('No time slot selected for service selection');
37
+ }
38
+ // Build the base Booking using the singular timeSlot path so that shared
39
+ // fields (service, resource, location, payment, participants) are derived
40
+ // exactly once and consistently. Each per-day Booking is then a shallow
41
+ // clone with only the slot start/end overridden from `slots[i]`.
42
+ const baseSelection = item.timeSlot ? item : { ...item, timeSlot: slots[0] };
43
+ const baseRequest = buildBookingRequest({
44
+ ...params,
45
+ serviceSelections: [baseSelection, ...params.serviceSelections.slice(1)],
46
+ });
47
+ const bookings = slots.map((slot) => ({
48
+ ...baseRequest.booking,
49
+ bookedEntity: {
50
+ ...baseRequest.booking.bookedEntity,
51
+ slot: {
52
+ ...baseRequest.booking.bookedEntity?.slot,
53
+ startDate: slot.startDate,
54
+ endDate: slot.endDate,
55
+ },
56
+ },
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).
62
+ return {
63
+ bookings,
64
+ participantNotification: baseRequest.participantNotification,
65
+ sendSmsReminder: baseRequest.sendSmsReminder ?? true,
66
+ };
67
+ }
@@ -14,7 +14,8 @@ export interface CanBookParams {
14
14
  * Validates if booking can be executed
15
15
  * Checks that all required data is present:
16
16
  * - At least one service selection
17
- * - Each service selection has a time slot selected
17
+ * - Each service selection has either a `timeSlot` or a non-empty
18
+ * `rangeTimeSlots` (DAY-range path)
18
19
  * - Form submission filled
19
20
  *
20
21
  * @param params - The booking data to validate
@@ -5,7 +5,8 @@
5
5
  * Validates if booking can be executed
6
6
  * Checks that all required data is present:
7
7
  * - At least one service selection
8
- * - Each service selection has a time slot selected
8
+ * - Each service selection has either a `timeSlot` or a non-empty
9
+ * `rangeTimeSlots` (DAY-range path)
9
10
  * - Form submission filled
10
11
  *
11
12
  * @param params - The booking data to validate
@@ -14,6 +15,7 @@
14
15
  export function canBook(params) {
15
16
  const { serviceSelections, formSubmission } = params;
16
17
  return (serviceSelections.length > 0 &&
17
- serviceSelections.every((item) => item.timeSlot !== undefined) &&
18
+ serviceSelections.every((item) => item.timeSlot !== undefined ||
19
+ (item.rangeTimeSlots !== undefined && item.rangeTimeSlots.length > 0)) &&
18
20
  formSubmission !== null);
19
21
  }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Creates the booking(s) needed for cart construction.
3
+ *
4
+ * Branches on the service selection:
5
+ * - DAY-range path with 1 picked slot -> `bulkCreateBooking`
6
+ * - DAY-range path with 2..8 picked slots -> `createMultiServiceBooking`
7
+ * - default path -> `createBooking`
8
+ *
9
+ * All branches return the same shape so `executeBookAction` can stay
10
+ * branchless from cart-creation onwards. Cart construction reads each
11
+ * single-service booking ID — per SDK guidance, never the
12
+ * `multiServiceBooking._id`.
13
+ */
14
+ import type { ContactDetails } from '@wix/auto_sdk_bookings_bookings';
15
+ import type { BookActionParams } from './types.js';
16
+ export interface CreatedBookings {
17
+ /** One ID per single-service booking. >=1 on success. */
18
+ bookingIds: string[];
19
+ /** Canonical contact details echoed by the server (read from the first booking). */
20
+ contactDetails?: ContactDetails;
21
+ }
22
+ export declare function createBookingsForCart(params: BookActionParams): Promise<CreatedBookings>;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Creates the booking(s) needed for cart construction.
3
+ *
4
+ * Branches on the service selection:
5
+ * - DAY-range path with 1 picked slot -> `bulkCreateBooking`
6
+ * - DAY-range path with 2..8 picked slots -> `createMultiServiceBooking`
7
+ * - default path -> `createBooking`
8
+ *
9
+ * All branches return the same shape so `executeBookAction` can stay
10
+ * branchless from cart-creation onwards. Cart construction reads each
11
+ * single-service booking ID — per SDK guidance, never the
12
+ * `multiServiceBooking._id`.
13
+ */
14
+ import { createBooking } from '../../../api/create-booking/index.js';
15
+ import { bulkCreateBooking } from '../../../api/create-bulk-booking/index.js';
16
+ import { createMultiServiceBooking } from '../../../api/create-multi-service-booking/index.js';
17
+ import { buildBookingRequest } from './buildBookingRequest.js';
18
+ import { buildDayRangeBookingRequest } from './buildDayRangeBookingRequest.js';
19
+ import { isDayRangeService } from './dayRange.js';
20
+ export async function createBookingsForCart(params) {
21
+ const firstSelection = params.serviceSelections[0];
22
+ if (!firstSelection) {
23
+ throw new Error('No service selection provided');
24
+ }
25
+ if (isDayRangeService(firstSelection.service)) {
26
+ 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.
31
+ if (req.bookings.length === 1) {
32
+ const response = await bulkCreateBooking([{ booking: req.bookings[0] }], {
33
+ participantNotification: req.participantNotification,
34
+ sendSmsReminder: req.sendSmsReminder,
35
+ });
36
+ const results = response.results ?? [];
37
+ return {
38
+ bookingIds: results.map((r) => r.item?._id).filter(Boolean),
39
+ // All N daily bookings share the same customer; read from the first.
40
+ contactDetails: results[0]?.item?.contactDetails,
41
+ };
42
+ }
43
+ const response = await createMultiServiceBooking(req.bookings, {
44
+ participantNotification: req.participantNotification,
45
+ sendSmsReminder: req.sendSmsReminder,
46
+ });
47
+ const bookings = response.multiServiceBooking?.bookings ?? [];
48
+ return {
49
+ bookingIds: bookings
50
+ .map((b) => b.booking?._id)
51
+ .filter(Boolean),
52
+ contactDetails: bookings[0]?.booking?.contactDetails,
53
+ };
54
+ }
55
+ const createBookingRequest = buildBookingRequest(params);
56
+ const bookingResponse = await createBooking(createBookingRequest.booking, {
57
+ participantNotification: createBookingRequest.participantNotification,
58
+ sendSmsReminder: createBookingRequest.sendSmsReminder,
59
+ formSubmission: createBookingRequest.formSubmission,
60
+ });
61
+ const bookingId = bookingResponse.booking?._id;
62
+ return {
63
+ bookingIds: bookingId ? [bookingId] : [],
64
+ contactDetails: bookingResponse.booking?.contactDetails,
65
+ };
66
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * DAY-range service helpers.
3
+ *
4
+ * APPOINTMENT services whose schedule has a `durationRange` with
5
+ * `unitType === DAY` route through the per-day slot path:
6
+ * - 1 picked slot -> `bulkCreateBooking`
7
+ * - 2..8 picked slots -> `createMultiServiceBooking`
8
+ *
9
+ * CLASS/COURSE selections and HOUR-range / fixed-duration APPOINTMENT
10
+ * selections keep using the existing `createBooking` path.
11
+ */
12
+ import { type Service } from '@wix/auto_sdk_bookings_services';
13
+ /**
14
+ * Returns true when the given service is an APPOINTMENT whose duration is
15
+ * configured as a DAY range. Useful at the UI layer (e.g. routing) to know
16
+ * before a slot has been picked whether the selection will go through the
17
+ * DAY-range create path.
18
+ */
19
+ export declare function isDayRangeService(service: Service): boolean;
20
+ /**
21
+ * Bounds (in days) that a customer may pick for a DAY-range service.
22
+ * Both bounds are inclusive. The server enforces 1..8 per `DailyConfig` (SDK);
23
+ * this helper just exposes whatever the configured values are.
24
+ */
25
+ export type DayRangeBounds = {
26
+ min: number;
27
+ max: number;
28
+ };
29
+ /**
30
+ * Returns the configured min/max day bounds for a DAY-range service, or
31
+ * `null` if the service is not DAY-range. Falls back to `min = 1` / `max = min`
32
+ * when the service is missing `dayOptions` configuration values.
33
+ */
34
+ export declare function getDayRangeBounds(service: Service): DayRangeBounds | null;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * DAY-range service helpers.
3
+ *
4
+ * APPOINTMENT services whose schedule has a `durationRange` with
5
+ * `unitType === DAY` route through the per-day slot path:
6
+ * - 1 picked slot -> `bulkCreateBooking`
7
+ * - 2..8 picked slots -> `createMultiServiceBooking`
8
+ *
9
+ * CLASS/COURSE selections and HOUR-range / fixed-duration APPOINTMENT
10
+ * selections keep using the existing `createBooking` path.
11
+ */
12
+ import { ServiceType, UnitType, } from '@wix/auto_sdk_bookings_services';
13
+ /**
14
+ * Returns true when the given service is an APPOINTMENT whose duration is
15
+ * configured as a DAY range. Useful at the UI layer (e.g. routing) to know
16
+ * before a slot has been picked whether the selection will go through the
17
+ * DAY-range create path.
18
+ */
19
+ export function isDayRangeService(service) {
20
+ const isAppointment = service.type === ServiceType.APPOINTMENT;
21
+ const isDayRange = service.schedule?.availabilityConstraints?.durationRange?.unitType ===
22
+ UnitType.DAY;
23
+ return isAppointment && isDayRange;
24
+ }
25
+ /**
26
+ * Returns the configured min/max day bounds for a DAY-range service, or
27
+ * `null` if the service is not DAY-range. Falls back to `min = 1` / `max = min`
28
+ * when the service is missing `dayOptions` configuration values.
29
+ */
30
+ export function getDayRangeBounds(service) {
31
+ if (!isDayRangeService(service))
32
+ return null;
33
+ const dayOptions = service.schedule?.availabilityConstraints?.durationRange?.dayOptions;
34
+ const min = dayOptions?.minDurationInDays ?? 1;
35
+ const max = dayOptions?.maxDurationInDays ?? min;
36
+ if (max < min)
37
+ return null;
38
+ return { min, max };
39
+ }
@@ -1,9 +1,12 @@
1
1
  /**
2
2
  * Book Action - Exports
3
3
  */
4
- export { executeBookAction } from './bookAction.js';
5
- export { canBook, type CanBookParams } from './canBook.js';
6
- export { buildBookingRequest } from './buildBookingRequest.js';
7
- export { buildCartRequest, type BuildCartParams } from './buildCartRequest.js';
8
- export { isCheckoutRequired } from './isCheckoutRequired.js';
9
- export { BookResultType, type BookProps, type BookResult, type BookingError, type BookActionParams, type BookChildProps, } from './types.js';
4
+ export * from './bookAction.js';
5
+ export * from './canBook.js';
6
+ export * from './buildBookingRequest.js';
7
+ export * from './buildDayRangeBookingRequest.js';
8
+ export * from './buildCartRequest.js';
9
+ export * from './createBookingsForCart.js';
10
+ export * from './dayRange.js';
11
+ export * from './isCheckoutRequired.js';
12
+ export * from './types.js';
@@ -1,9 +1,12 @@
1
1
  /**
2
2
  * Book Action - Exports
3
3
  */
4
- export { executeBookAction } from './bookAction.js';
5
- export { canBook } from './canBook.js';
6
- export { buildBookingRequest } from './buildBookingRequest.js';
7
- export { buildCartRequest } from './buildCartRequest.js';
8
- export { isCheckoutRequired } from './isCheckoutRequired.js';
9
- export { BookResultType, } from './types.js';
4
+ export * from './bookAction.js';
5
+ export * from './canBook.js';
6
+ export * from './buildBookingRequest.js';
7
+ export * from './buildDayRangeBookingRequest.js';
8
+ export * from './buildCartRequest.js';
9
+ export * from './createBookingsForCart.js';
10
+ export * from './dayRange.js';
11
+ export * from './isCheckoutRequired.js';
12
+ export * from './types.js';
@@ -4,6 +4,14 @@
4
4
  import type { ServiceSelection } from '../booking.js';
5
5
  import type { FormValues } from '@wix/forms/components';
6
6
  import type { Location as TimeSlotLocationType } from '@wix/auto_sdk_bookings_availability-time-slots';
7
+ import type { SelectedPaymentOptionWithLiterals } from '@wix/auto_sdk_bookings_bookings';
8
+ /**
9
+ * Narrowed booking-API `selectedPaymentOption` to the two values a consumer
10
+ * can pick in the UI. Derived from the SDK enum (`SelectedPaymentOption`) so
11
+ * the type stays in sync; MEMBERSHIP variants are intentionally excluded
12
+ * because they require pricing-plan plumbing not exposed here.
13
+ */
14
+ export type SelectedPaymentOption = Extract<SelectedPaymentOptionWithLiterals, 'ONLINE' | 'OFFLINE'>;
7
15
  /**
8
16
  * Enum for book result types
9
17
  */
@@ -38,6 +46,13 @@ export interface BookActionParams {
38
46
  timezone?: string;
39
47
  /** Optional app ID override for the catalog reference. Defaults to the bookings app ID. */
40
48
  appId?: string;
49
+ /**
50
+ * Optional consumer-selected payment option. When provided, overrides the
51
+ * heuristic derived from `service.payment.options` in `buildBookingRequest`
52
+ * and matches the line item's `paymentOption` produced by the payment
53
+ * service. When omitted, the existing service-config heuristic applies.
54
+ */
55
+ selectedPaymentOption?: SelectedPaymentOption;
41
56
  }
42
57
  /**
43
58
  * Props passed to children of Book component
@@ -7,7 +7,8 @@ import { type Signal } from '@wix/services-definitions/core-services/signals';
7
7
  import type { Service, V2Location as ServiceLocationType } from '@wix/auto_sdk_bookings_services';
8
8
  import type { Resource, EventInfo, Location as TimeSlotLocationType } from '@wix/auto_sdk_bookings_availability-time-slots';
9
9
  import type { FormValues } from '@wix/forms/components';
10
- import type { BookResult } from './book-action/types.js';
10
+ import type { BookResult, SelectedPaymentOption } from './book-action/types.js';
11
+ export type { SelectedPaymentOption } from './book-action/types.js';
11
12
  /**
12
13
  * Extended Resource type with a type field for categorization
13
14
  */
@@ -40,8 +41,18 @@ export interface ServiceSelection {
40
41
  service: Service;
41
42
  /** Selected resources (staff members, rooms, etc.) with type information */
42
43
  resources: ExtendedResource[];
43
- /** Per-item time slot data */
44
+ /** Per-item time slot data (single-slot path; existing behavior). */
44
45
  timeSlot?: ServiceSelectionTimeSlot;
46
+ /**
47
+ * Per-day slots for DAY-range services. Populated by the availability
48
+ * picker after the customer picks a start + end date: one entry per day
49
+ * in the picked range. When set, supersedes `timeSlot` for the DAY-range
50
+ * builder, which produces one Booking per entry and routes via length:
51
+ * - 1 -> bulkCreateBooking
52
+ * - 2-8 -> createMultiServiceBooking
53
+ * Optional & additive: existing single-slot callers stay on `timeSlot`.
54
+ */
55
+ rangeTimeSlots?: ServiceSelectionTimeSlot[];
45
56
  /** Number of participants for this service selection */
46
57
  totalParticipants?: number;
47
58
  }
@@ -70,6 +81,13 @@ export interface BookingServiceActions {
70
81
  setTimezone(timezone: string): void;
71
82
  setFormSubmission(values: FormValues | null): void;
72
83
  clearFormSubmission(): void;
84
+ /**
85
+ * Set (or clear with `null`) the consumer-selected payment option. When set
86
+ * to `'ONLINE'` or `'OFFLINE'`, this overrides the service-config heuristic
87
+ * used by `book()` and the payment preview. When set to `null`, the override
88
+ * is cleared and the heuristic applies again.
89
+ */
90
+ setSelectedPaymentOption(value: SelectedPaymentOption | null): void;
73
91
  clearAll(): void;
74
92
  book(): Promise<BookResult>;
75
93
  }
@@ -86,6 +104,12 @@ export interface BookingService {
86
104
  timezone: Signal<string | undefined>;
87
105
  /** Signal containing the form submission */
88
106
  formSubmission: Signal<FormValues | null>;
107
+ /**
108
+ * Signal containing the consumer-selected payment option. `undefined` means
109
+ * "not chosen" — `book()` and the payment preview fall back to the
110
+ * service-config heuristic. Set to `'ONLINE'` or `'OFFLINE'` to override.
111
+ */
112
+ selectedPaymentOption: Signal<SelectedPaymentOption | undefined>;
89
113
  /** Actions for modifying booking state */
90
114
  actions: BookingServiceActions;
91
115
  }
@@ -110,6 +134,11 @@ export interface BookingServiceConfig {
110
134
  timezone?: string;
111
135
  /** Optional initial form submission */
112
136
  formSubmission?: FormValues | null;
137
+ /**
138
+ * Optional initial consumer-selected payment option. Omit to use the
139
+ * service-config heuristic; set to `'ONLINE'` or `'OFFLINE'` to override.
140
+ */
141
+ selectedPaymentOption?: SelectedPaymentOption;
113
142
  /** Optional app ID override for the catalog reference. Defaults to the bookings app ID. */
114
143
  appId?: string;
115
144
  }
@@ -70,6 +70,7 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
70
70
  const locationSignal = signalsService.signal(config.location || null);
71
71
  const timezoneSignal = signalsService.signal(config.timezone ?? getClientTimezone());
72
72
  const formSubmissionSignal = signalsService.signal(config.formSubmission || null);
73
+ const selectedPaymentOptionSignal = signalsService.signal(config.selectedPaymentOption);
73
74
  // ========================================================================
74
75
  // Helpers
75
76
  // ========================================================================
@@ -164,6 +165,10 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
164
165
  clearFormSubmission() {
165
166
  formSubmissionSignal.set(null);
166
167
  },
168
+ // Payment option action
169
+ setSelectedPaymentOption(value) {
170
+ selectedPaymentOptionSignal.set(value ?? undefined);
171
+ },
167
172
  // Clear all
168
173
  clearAll() {
169
174
  this.clearItems();
@@ -177,6 +182,7 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
177
182
  const formSubmission = formSubmissionSignal.get();
178
183
  const location = locationSignal.get();
179
184
  const timezone = timezoneSignal.get();
185
+ const selectedPaymentOption = selectedPaymentOptionSignal.get();
180
186
  // Validation happens inside executeBookAction
181
187
  return executeBookAction({
182
188
  serviceSelections,
@@ -184,6 +190,7 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
184
190
  location,
185
191
  timezone,
186
192
  appId: config.appId,
193
+ selectedPaymentOption,
187
194
  });
188
195
  },
189
196
  };
@@ -192,6 +199,7 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
192
199
  location: locationSignal,
193
200
  timezone: timezoneSignal,
194
201
  formSubmission: formSubmissionSignal,
202
+ selectedPaymentOption: selectedPaymentOptionSignal,
195
203
  actions,
196
204
  };
197
205
  });
@@ -7,7 +7,7 @@ export { BookingService, BookingServiceDefinition, type BookingServiceConfig, ty
7
7
  export { TimeSlotListService, TimeSlotListServiceDefinition, TimeSlotService, TimeSlotServiceDefinition, ViewMode, loadTimeSlotListConfig, type TimeSlotListServiceAPI, type TimeSlotListServiceActions, type TimeSlotListServiceConfig, type TimeSlotServiceAPI, type TimeSlotServiceConfig, type LoadTimeSlotListConfigOptions, type LoadTimeSlotListConfigResult, } from './time-slot-list/index.js';
8
8
  export { ServiceListService, ServiceListServiceDefinition, type ServiceListServiceAPI, type ServiceListServiceConfig, type ServiceListActions, type QueryOptions, loadServiceListServiceInitialData, type SuccessServiceListServiceConfigResult, type ErrorServiceListServiceConfigResult, } from './service-list/service-list.js';
9
9
  export { SYNTHETIC_CUSTOM_ID, SYNTHETIC_CUSTOMER_ID, } from '../api/query-services/index.js';
10
- export { executeBookAction, canBook, buildBookingRequest, buildCartRequest, type CanBookParams, type BookResult, type BookingError, type BookActionParams, type BookChildProps, type BookProps, type BuildCartParams, } from './booking/book-action/index.js';
10
+ export { executeBookAction, canBook, buildBookingRequest, buildCartRequest, buildDayRangeCartRequest, buildDayRangeBookingRequest, createBookingsForCart, isDayRangeService, getDayRangeBounds, type CanBookParams, type BookResult, type BookingError, type BookActionParams, type BookChildProps, type BookProps, type BuildCartParams, type BuildDayRangeCartParams, type BuildDayRangeBookingRequest, type CreatedBookings, type DayRangeBounds, } from './booking/book-action/index.js';
11
11
  export { BookingFormService, BookingFormServiceDefinition, type BookingFormServiceAPI, type BookingFormServiceConfig, } from './booking-form/booking-form.js';
12
12
  export { PaymentService, PaymentServiceDefinition, type PaymentServiceAPI, type PaymentServiceConfig, type PaymentDetails, type PricingServiceSelection, type LineItemAdditionalInfo, type ServicePaymentOptions, loadPaymentConfig, type SuccessPaymentConfigResult, type ErrorPaymentConfigResult, } from './payment/payment.js';
13
13
  export { LocationListService, LocationListServiceDefinition, LocationType, loadLocationListServiceInitialData, locationListServiceBinding, type LocationListServiceAPI, type LocationListServiceConfig, type LocationListActions, type Location, type LoadLocationListServiceResult, getLocationById, } from './location-list/location-list.js';
@@ -7,7 +7,7 @@ export { BookingService, BookingServiceDefinition, } from './booking/booking.js'
7
7
  export { TimeSlotListService, TimeSlotListServiceDefinition, TimeSlotService, TimeSlotServiceDefinition, ViewMode, loadTimeSlotListConfig, } from './time-slot-list/index.js';
8
8
  export { ServiceListService, ServiceListServiceDefinition, loadServiceListServiceInitialData, } from './service-list/service-list.js';
9
9
  export { SYNTHETIC_CUSTOM_ID, SYNTHETIC_CUSTOMER_ID, } from '../api/query-services/index.js';
10
- export { executeBookAction, canBook, buildBookingRequest, buildCartRequest, } from './booking/book-action/index.js';
10
+ export { executeBookAction, canBook, buildBookingRequest, buildCartRequest, buildDayRangeCartRequest, buildDayRangeBookingRequest, createBookingsForCart, isDayRangeService, getDayRangeBounds, } from './booking/book-action/index.js';
11
11
  export { BookingFormService, BookingFormServiceDefinition, } from './booking-form/booking-form.js';
12
12
  export { PaymentService, PaymentServiceDefinition, loadPaymentConfig, } from './payment/payment.js';
13
13
  export { LocationListService, LocationListServiceDefinition, LocationType, loadLocationListServiceInitialData, locationListServiceBinding, getLocationById, } from './location-list/location-list.js';
@@ -4,6 +4,7 @@
4
4
  * Supports two modes: SSR (config with pre-fetched data) and lazy loading (reactive)
5
5
  */
6
6
  import { type PaymentServiceConfig, type PaymentServiceInternalConfig, type PricingServiceSelection } from './payment.def.js';
7
+ import type { SelectedPaymentOption } from '../booking/book-action/types.js';
7
8
  export { PaymentServiceDefinition, type PaymentServiceConfig, type PaymentDetails, type LineItemAdditionalInfo, type PricingServiceSelection, type ServicePaymentOptions, } from './payment.def.js';
8
9
  export type { PaymentServiceAPI, PaymentServiceInternalConfig, } from './payment.def.js';
9
10
  export declare const PaymentService: import("@wix/services-definitions").ServiceFactory<string & {
@@ -25,8 +26,11 @@ export type ErrorPaymentConfigResult = {
25
26
  *
26
27
  * @param params.pricingServiceSelections - Pricing service selections for calculation
27
28
  * @param params.totalParticipants - Number of participants (default: 1)
29
+ * @param params.selectedPaymentOption - Optional consumer-selected payment option;
30
+ * overrides the service-config heuristic on each line item's `paymentOption`.
28
31
  */
29
32
  export declare function loadPaymentConfig(params: {
30
33
  pricingServiceSelections: PricingServiceSelection[];
31
34
  totalParticipants?: number;
35
+ selectedPaymentOption?: SelectedPaymentOption;
32
36
  }): Promise<SuccessPaymentConfigResult | ErrorPaymentConfigResult>;
@@ -5,6 +5,7 @@
5
5
  import type { Signal } from '@wix/services-definitions/core-services/signals';
6
6
  import type { CalculateTotalsResponse } from '@wix/auto_sdk_ecom_totals-calculator';
7
7
  import type { Service } from '@wix/auto_sdk_bookings_services';
8
+ import type { SelectedPaymentOption } from '../booking/book-action/types.js';
8
9
  /**
9
10
  * Service payment options derived from service.payment.options.
10
11
  * Describes which payment methods the service supports.
@@ -74,6 +75,11 @@ export interface PaymentServiceInternalConfig extends PaymentServiceConfig {
74
75
  pricingServiceSelections?: PricingServiceSelection[];
75
76
  /** Number of participants for lazy loading (internal use) */
76
77
  totalParticipants?: number;
78
+ /**
79
+ * Optional consumer-selected payment option used for lazy loading. When
80
+ * set, overrides the service-config heuristic in line item `paymentOption`.
81
+ */
82
+ selectedPaymentOption?: SelectedPaymentOption;
77
83
  }
78
84
  export interface PaymentServiceAPI {
79
85
  paymentDetailsSignal: Signal<PaymentDetails | null>;