@wix/headless-bookings 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/dist/services/booking/book-action/bookAction.js +9 -18
- package/cjs/dist/services/booking/book-action/buildCartRequest.d.ts +7 -18
- package/cjs/dist/services/booking/book-action/buildCartRequest.js +0 -7
- package/cjs/dist/services/booking/book-action/buildDayRangeBookingRequest.d.ts +7 -4
- package/cjs/dist/services/booking/book-action/buildDayRangeBookingRequest.js +4 -5
- package/cjs/dist/services/booking/book-action/createBookingsForCart.d.ts +2 -2
- package/cjs/dist/services/booking/book-action/createBookingsForCart.js +5 -21
- package/cjs/dist/services/booking/book-action/dayRange.d.ts +2 -1
- package/cjs/dist/services/booking/book-action/dayRange.js +2 -1
- package/cjs/dist/services/booking/book-action/types.d.ts +2 -3
- package/cjs/dist/services/booking/booking.d.ts +4 -4
- package/cjs/dist/services/index.d.ts +1 -1
- package/cjs/dist/services/index.js +1 -2
- package/dist/services/booking/book-action/bookAction.js +10 -19
- package/dist/services/booking/book-action/buildCartRequest.d.ts +7 -18
- package/dist/services/booking/book-action/buildCartRequest.js +0 -6
- package/dist/services/booking/book-action/buildDayRangeBookingRequest.d.ts +7 -4
- package/dist/services/booking/book-action/buildDayRangeBookingRequest.js +4 -5
- package/dist/services/booking/book-action/createBookingsForCart.d.ts +2 -2
- package/dist/services/booking/book-action/createBookingsForCart.js +3 -19
- package/dist/services/booking/book-action/dayRange.d.ts +2 -1
- package/dist/services/booking/book-action/dayRange.js +2 -1
- package/dist/services/booking/book-action/types.d.ts +2 -3
- package/dist/services/booking/booking.d.ts +4 -4
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/package.json +2 -2
|
@@ -17,7 +17,7 @@ async function executeBookAction(params) {
|
|
|
17
17
|
})) {
|
|
18
18
|
throw new Error('Cannot book: missing required data');
|
|
19
19
|
}
|
|
20
|
-
// Step 1: Create booking(s). The helper picks single vs
|
|
20
|
+
// Step 1: Create booking(s). The helper picks single vs
|
|
21
21
|
// multi-service (DAY-range routing) and returns a uniform
|
|
22
22
|
// { bookingIds, contactDetails } shape.
|
|
23
23
|
const { bookingIds, contactDetails } = await (0, createBookingsForCart_js_1.createBookingsForCart)(params);
|
|
@@ -38,23 +38,14 @@ 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
|
-
//
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
businessLocationId,
|
|
50
|
-
appId: params.appId,
|
|
51
|
-
})
|
|
52
|
-
: (0, buildCartRequest_js_1.buildCartRequest)({
|
|
53
|
-
bookingId: bookingIds[0],
|
|
54
|
-
contactDetails,
|
|
55
|
-
businessLocationId,
|
|
56
|
-
appId: params.appId,
|
|
57
|
-
});
|
|
41
|
+
// One cart item per booking ID. Single-day and allDay ranges produce one
|
|
42
|
+
// booking ID; DAY-range expansion produces one per day.
|
|
43
|
+
const cartRequest = (0, buildCartRequest_js_1.buildCartRequest)({
|
|
44
|
+
bookingIds,
|
|
45
|
+
contactDetails,
|
|
46
|
+
businessLocationId,
|
|
47
|
+
appId: params.appId,
|
|
48
|
+
});
|
|
58
49
|
const cart = await (0, index_js_1.createCart)(cartRequest);
|
|
59
50
|
if (!cart._id) {
|
|
60
51
|
throw new Error('Failed to create cart');
|
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
import { type CreateCartOptions } from '../../../api/create-cart/index.js';
|
|
2
2
|
import type { ContactDetails } from '@wix/auto_sdk_bookings_bookings';
|
|
3
3
|
export interface BuildCartParams {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export declare function buildCartRequest(params: BuildCartParams): CreateCartOptions;
|
|
12
|
-
/**
|
|
13
|
-
* DAY-range variant of `buildCartRequest`. Takes the N booking IDs returned
|
|
14
|
-
* by `bulkCreateBooking` (1 slot) or `createMultiServiceBooking` (2-8 slots)
|
|
15
|
-
* and emits one catalog item per ID. Per SDK guidance, never use
|
|
16
|
-
* `multiServiceBooking._id` here; always feed the per-day single-service
|
|
17
|
-
* booking IDs into the cart.
|
|
18
|
-
*/
|
|
19
|
-
export interface BuildDayRangeCartParams {
|
|
20
|
-
/** One catalog item per booking id. Bulk / multi-service responses produce N>=1 ids. */
|
|
4
|
+
/**
|
|
5
|
+
* One catalog item is emitted per booking id. Single-service and allDay
|
|
6
|
+
* bookings produce one id; DAY-range expansion produces one per day. Per SDK
|
|
7
|
+
* guidance, never use `multiServiceBooking._id` here; always feed the
|
|
8
|
+
* per-day single-service booking IDs into the cart.
|
|
9
|
+
*/
|
|
21
10
|
bookingIds: string[];
|
|
22
11
|
contactDetails?: ContactDetails;
|
|
23
12
|
/** `null` accepted so callers can forward SDK fields typed `string | null`. */
|
|
@@ -25,4 +14,4 @@ export interface BuildDayRangeCartParams {
|
|
|
25
14
|
/** Optional app ID override for the catalog reference. Defaults to BOOKING_APP_ID. */
|
|
26
15
|
appId?: string;
|
|
27
16
|
}
|
|
28
|
-
export declare function
|
|
17
|
+
export declare function buildCartRequest(params: BuildCartParams): CreateCartOptions;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildCartRequest = buildCartRequest;
|
|
4
|
-
exports.buildDayRangeCartRequest = buildDayRangeCartRequest;
|
|
5
4
|
const index_js_1 = require("../../../api/create-cart/index.js");
|
|
6
5
|
const constants_js_1 = require("../../constants.js");
|
|
7
6
|
function buildCartRequest(params) {
|
|
8
|
-
return {
|
|
9
|
-
catalogItems: [buildCatalogItem(params.bookingId, params.appId)],
|
|
10
|
-
cart: buildCartShape(params),
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function buildDayRangeCartRequest(params) {
|
|
14
7
|
return {
|
|
15
8
|
catalogItems: params.bookingIds.map((id) => buildCatalogItem(id, params.appId)),
|
|
16
9
|
cart: buildCartShape(params),
|
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
* and the picker emits one slot per day in `rangeTimeSlots`. The client just
|
|
7
7
|
* packages them as one Booking each. Routing is decided by `bookings.length`
|
|
8
8
|
* in `createBookingsForCart`:
|
|
9
|
-
* - length 1 -> `
|
|
9
|
+
* - length 1 -> `createBooking`
|
|
10
10
|
* - length 2-8 -> `createMultiServiceBooking`
|
|
11
11
|
*
|
|
12
|
+
* With `allDay`, the picked slots collapse into one Booking spanning the full
|
|
13
|
+
* range, so that case routes through `createBooking`.
|
|
14
|
+
*
|
|
12
15
|
* The 8-day cap is enforced server-side; the builder does not gate on it.
|
|
13
16
|
*/
|
|
14
17
|
import type { Booking, ParticipantNotification } from '@wix/auto_sdk_bookings_bookings';
|
|
@@ -17,9 +20,9 @@ import type { BookActionParams } from './types.js';
|
|
|
17
20
|
export interface BuildDayRangeBookingRequest {
|
|
18
21
|
/**
|
|
19
22
|
* The Bookings to create. With `allDay`, this is a single Booking spanning
|
|
20
|
-
* the whole range
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
+
* the whole range. Otherwise it is one Booking per picked per-day slot:
|
|
24
|
+
* length 1 routes to createBooking, length >=2 routes to
|
|
25
|
+
* createMultiServiceBooking.
|
|
23
26
|
*/
|
|
24
27
|
bookings: Booking[];
|
|
25
28
|
/** Notification settings forwarded to the server. */
|
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|
* and the picker emits one slot per day in `rangeTimeSlots`. The client just
|
|
8
8
|
* packages them as one Booking each. Routing is decided by `bookings.length`
|
|
9
9
|
* in `createBookingsForCart`:
|
|
10
|
-
* - length 1 -> `
|
|
10
|
+
* - length 1 -> `createBooking`
|
|
11
11
|
* - length 2-8 -> `createMultiServiceBooking`
|
|
12
12
|
*
|
|
13
|
+
* With `allDay`, the picked slots collapse into one Booking spanning the full
|
|
14
|
+
* range, so that case routes through `createBooking`.
|
|
15
|
+
*
|
|
13
16
|
* The 8-day cap is enforced server-side; the builder does not gate on it.
|
|
14
17
|
*/
|
|
15
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -59,10 +62,6 @@ function buildDayRangeBookingRequest(params) {
|
|
|
59
62
|
},
|
|
60
63
|
},
|
|
61
64
|
});
|
|
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
65
|
const bookings = params.allDay
|
|
67
66
|
? [buildBooking(slots[0].startDate, slots[slots.length - 1].endDate)]
|
|
68
67
|
: slots.map((slot) => buildBooking(slot.startDate, slot.endDate));
|
|
@@ -2,9 +2,9 @@
|
|
|
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 day -> `createBooking`
|
|
5
6
|
* - DAY-range path with `allDay` -> `createBooking` (one combined Booking)
|
|
6
|
-
* - DAY-range path with
|
|
7
|
-
* - DAY-range path with 2..8 picked slots -> `createMultiServiceBooking`
|
|
7
|
+
* - DAY-range path with 2..8 picked days -> `createMultiServiceBooking`
|
|
8
8
|
* - default path -> `createBooking`
|
|
9
9
|
*
|
|
10
10
|
* All branches return the same shape so `executeBookAction` can stay
|
|
@@ -3,9 +3,9 @@
|
|
|
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 day -> `createBooking`
|
|
6
7
|
* - DAY-range path with `allDay` -> `createBooking` (one combined Booking)
|
|
7
|
-
* - DAY-range path with
|
|
8
|
-
* - DAY-range path with 2..8 picked slots -> `createMultiServiceBooking`
|
|
8
|
+
* - DAY-range path with 2..8 picked days -> `createMultiServiceBooking`
|
|
9
9
|
* - default path -> `createBooking`
|
|
10
10
|
*
|
|
11
11
|
* All branches return the same shape so `executeBookAction` can stay
|
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.createBookingsForCart = createBookingsForCart;
|
|
18
18
|
const index_js_1 = require("../../../api/create-booking/index.js");
|
|
19
|
-
const index_js_2 = require("../../../api/create-
|
|
20
|
-
const index_js_3 = require("../../../api/create-multi-service-booking/index.js");
|
|
19
|
+
const index_js_2 = require("../../../api/create-multi-service-booking/index.js");
|
|
21
20
|
const buildBookingRequest_js_1 = require("./buildBookingRequest.js");
|
|
22
21
|
const buildDayRangeBookingRequest_js_1 = require("./buildDayRangeBookingRequest.js");
|
|
23
22
|
const dayRange_js_1 = require("./dayRange.js");
|
|
@@ -28,9 +27,7 @@ async function createBookingsForCart(params) {
|
|
|
28
27
|
}
|
|
29
28
|
if ((0, dayRange_js_1.isDayRangeService)(firstSelection.service)) {
|
|
30
29
|
const req = (0, buildDayRangeBookingRequest_js_1.buildDayRangeBookingRequest)(params);
|
|
31
|
-
|
|
32
|
-
// Booking. Create it with plain `createBooking` (not bulk / multi-service).
|
|
33
|
-
if (params.allDay) {
|
|
30
|
+
if (req.bookings.length === 1) {
|
|
34
31
|
const bookingResponse = await (0, index_js_1.createBooking)(req.bookings[0], {
|
|
35
32
|
participantNotification: req.participantNotification,
|
|
36
33
|
sendSmsReminder: req.sendSmsReminder,
|
|
@@ -42,20 +39,7 @@ async function createBookingsForCart(params) {
|
|
|
42
39
|
contactDetails: bookingResponse.booking?.contactDetails,
|
|
43
40
|
};
|
|
44
41
|
}
|
|
45
|
-
|
|
46
|
-
const response = await (0, index_js_2.bulkCreateBooking)([{ booking: req.bookings[0] }], {
|
|
47
|
-
participantNotification: req.participantNotification,
|
|
48
|
-
sendSmsReminder: req.sendSmsReminder,
|
|
49
|
-
formSubmission: req.formSubmission,
|
|
50
|
-
});
|
|
51
|
-
const results = response.results ?? [];
|
|
52
|
-
return {
|
|
53
|
-
bookingIds: results.map((r) => r.item?._id).filter(Boolean),
|
|
54
|
-
// All N daily bookings share the same customer; read from the first.
|
|
55
|
-
contactDetails: results[0]?.item?.contactDetails,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
const response = await (0, index_js_3.createMultiServiceBooking)(req.bookings, {
|
|
42
|
+
const response = await (0, index_js_2.createMultiServiceBooking)(req.bookings, {
|
|
59
43
|
participantNotification: req.participantNotification,
|
|
60
44
|
sendSmsReminder: req.sendSmsReminder,
|
|
61
45
|
formSubmission: req.formSubmission,
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* APPOINTMENT services whose schedule has a `durationRange` with
|
|
5
5
|
* `unitType === DAY` route through the per-day slot path:
|
|
6
|
-
* - 1 picked slot -> `
|
|
6
|
+
* - 1 picked slot -> `createBooking`
|
|
7
7
|
* - 2..8 picked slots -> `createMultiServiceBooking`
|
|
8
|
+
* - 2..8 picked slots with `allDay` -> `createBooking`
|
|
8
9
|
*
|
|
9
10
|
* CLASS/COURSE selections and HOUR-range / fixed-duration APPOINTMENT
|
|
10
11
|
* selections keep using the existing `createBooking` path.
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
*
|
|
5
5
|
* APPOINTMENT services whose schedule has a `durationRange` with
|
|
6
6
|
* `unitType === DAY` route through the per-day slot path:
|
|
7
|
-
* - 1 picked slot -> `
|
|
7
|
+
* - 1 picked slot -> `createBooking`
|
|
8
8
|
* - 2..8 picked slots -> `createMultiServiceBooking`
|
|
9
|
+
* - 2..8 picked slots with `allDay` -> `createBooking`
|
|
9
10
|
*
|
|
10
11
|
* CLASS/COURSE selections and HOUR-range / fixed-duration APPOINTMENT
|
|
11
12
|
* selections keep using the existing `createBooking` path.
|
|
@@ -56,9 +56,8 @@ export interface BookActionParams {
|
|
|
56
56
|
/**
|
|
57
57
|
* DAY-range only. When `true`, the picked per-day slots are collapsed into a
|
|
58
58
|
* single Booking spanning the whole range (`firstSlot.startDate ->
|
|
59
|
-
* lastSlot.endDate`) and created via plain `createBooking
|
|
60
|
-
*
|
|
61
|
-
* `createMultiServiceBooking` (2-8 slots). Ignored for non-DAY-range services.
|
|
59
|
+
* lastSlot.endDate`) and created via plain `createBooking`. Ignored for
|
|
60
|
+
* non-DAY-range services.
|
|
62
61
|
*/
|
|
63
62
|
allDay?: boolean;
|
|
64
63
|
}
|
|
@@ -48,8 +48,9 @@ export interface ServiceSelection {
|
|
|
48
48
|
* picker after the customer picks a start + end date: one entry per day
|
|
49
49
|
* in the picked range. When set, supersedes `timeSlot` for the DAY-range
|
|
50
50
|
* builder, which produces one Booking per entry and routes via length:
|
|
51
|
-
* - 1 ->
|
|
51
|
+
* - 1 -> createBooking
|
|
52
52
|
* - 2-8 -> createMultiServiceBooking
|
|
53
|
+
* - 2-8 with allDay -> createBooking
|
|
53
54
|
* Optional & additive: existing single-slot callers stay on `timeSlot`.
|
|
54
55
|
*/
|
|
55
56
|
rangeTimeSlots?: ServiceSelectionTimeSlot[];
|
|
@@ -90,9 +91,8 @@ export interface BookingServiceActions {
|
|
|
90
91
|
setSelectedPaymentOption(value: SelectedPaymentOption | null): void;
|
|
91
92
|
/**
|
|
92
93
|
* Toggle the DAY-range `allDay` flag. When `true`, `book()` collapses the
|
|
93
|
-
* picked per-day slots
|
|
94
|
-
*
|
|
95
|
-
* Ignored for non-DAY-range services.
|
|
94
|
+
* picked per-day slots into one range-spanning Booking created via
|
|
95
|
+
* `createBooking`. Ignored for non-DAY-range services.
|
|
96
96
|
*/
|
|
97
97
|
setAllDay(value: boolean): void;
|
|
98
98
|
clearAll(): void;
|
|
@@ -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,
|
|
10
|
+
export { executeBookAction, canBook, buildBookingRequest, buildCartRequest, buildDayRangeBookingRequest, createBookingsForCart, isDayRangeService, getDayRangeBounds, type CanBookParams, type BookResult, type BookingError, type BookActionParams, type BookChildProps, type BookProps, type BuildCartParams, 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';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Main export file for all service definitions and implementations
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.staffMemberListServiceBinding = exports.loadStaffMemberListServiceInitialData = exports.StaffMemberListServiceDefinition = exports.StaffMemberListService = exports.getLocationById = exports.locationListServiceBinding = exports.loadLocationListServiceInitialData = exports.LocationType = exports.LocationListServiceDefinition = exports.LocationListService = exports.loadPaymentConfig = exports.PaymentServiceDefinition = exports.PaymentService = exports.BookingFormServiceDefinition = exports.BookingFormService = exports.getDayRangeBounds = exports.isDayRangeService = exports.createBookingsForCart = exports.buildDayRangeBookingRequest = exports.
|
|
7
|
+
exports.staffMemberListServiceBinding = exports.loadStaffMemberListServiceInitialData = exports.StaffMemberListServiceDefinition = exports.StaffMemberListService = exports.getLocationById = exports.locationListServiceBinding = exports.loadLocationListServiceInitialData = exports.LocationType = exports.LocationListServiceDefinition = exports.LocationListService = exports.loadPaymentConfig = exports.PaymentServiceDefinition = exports.PaymentService = exports.BookingFormServiceDefinition = exports.BookingFormService = exports.getDayRangeBounds = exports.isDayRangeService = exports.createBookingsForCart = exports.buildDayRangeBookingRequest = exports.buildCartRequest = exports.buildBookingRequest = exports.canBook = exports.executeBookAction = exports.SYNTHETIC_CUSTOMER_ID = exports.SYNTHETIC_CUSTOM_ID = exports.loadServiceListServiceInitialData = exports.ServiceListServiceDefinition = exports.ServiceListService = exports.loadTimeSlotListConfig = exports.ViewMode = exports.TimeSlotServiceDefinition = exports.TimeSlotService = exports.TimeSlotListServiceDefinition = exports.TimeSlotListService = exports.BookingServiceDefinition = exports.BookingService = exports.loadServiceServiceInitialData = exports.ServiceServiceDefinition = exports.ServiceService = void 0;
|
|
8
8
|
var service_js_1 = require("./service/service.js");
|
|
9
9
|
Object.defineProperty(exports, "ServiceService", { enumerable: true, get: function () { return service_js_1.ServiceService; } });
|
|
10
10
|
Object.defineProperty(exports, "ServiceServiceDefinition", { enumerable: true, get: function () { return service_js_1.ServiceServiceDefinition; } });
|
|
@@ -31,7 +31,6 @@ Object.defineProperty(exports, "executeBookAction", { enumerable: true, get: fun
|
|
|
31
31
|
Object.defineProperty(exports, "canBook", { enumerable: true, get: function () { return index_js_3.canBook; } });
|
|
32
32
|
Object.defineProperty(exports, "buildBookingRequest", { enumerable: true, get: function () { return index_js_3.buildBookingRequest; } });
|
|
33
33
|
Object.defineProperty(exports, "buildCartRequest", { enumerable: true, get: function () { return index_js_3.buildCartRequest; } });
|
|
34
|
-
Object.defineProperty(exports, "buildDayRangeCartRequest", { enumerable: true, get: function () { return index_js_3.buildDayRangeCartRequest; } });
|
|
35
34
|
Object.defineProperty(exports, "buildDayRangeBookingRequest", { enumerable: true, get: function () { return index_js_3.buildDayRangeBookingRequest; } });
|
|
36
35
|
Object.defineProperty(exports, "createBookingsForCart", { enumerable: true, get: function () { return index_js_3.createBookingsForCart; } });
|
|
37
36
|
Object.defineProperty(exports, "isDayRangeService", { enumerable: true, get: function () { return index_js_3.isDayRangeService; } });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createCart } from '../../../api/create-cart/index.js';
|
|
2
2
|
import { calculateCart } from '../../../api/calculate-cart/index.js';
|
|
3
3
|
import { placeOrder } from '../../../api/place-order/index.js';
|
|
4
|
-
import { buildCartRequest
|
|
4
|
+
import { buildCartRequest } from './buildCartRequest.js';
|
|
5
5
|
import { canBook } from './canBook.js';
|
|
6
6
|
import { createBookingsForCart } from './createBookingsForCart.js';
|
|
7
7
|
import { isCheckoutRequired } from './isCheckoutRequired.js';
|
|
@@ -14,7 +14,7 @@ export async function executeBookAction(params) {
|
|
|
14
14
|
})) {
|
|
15
15
|
throw new Error('Cannot book: missing required data');
|
|
16
16
|
}
|
|
17
|
-
// Step 1: Create booking(s). The helper picks single vs
|
|
17
|
+
// Step 1: Create booking(s). The helper picks single vs
|
|
18
18
|
// multi-service (DAY-range routing) and returns a uniform
|
|
19
19
|
// { bookingIds, contactDetails } shape.
|
|
20
20
|
const { bookingIds, contactDetails } = await createBookingsForCart(params);
|
|
@@ -35,23 +35,14 @@ 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
|
-
//
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
businessLocationId,
|
|
47
|
-
appId: params.appId,
|
|
48
|
-
})
|
|
49
|
-
: buildCartRequest({
|
|
50
|
-
bookingId: bookingIds[0],
|
|
51
|
-
contactDetails,
|
|
52
|
-
businessLocationId,
|
|
53
|
-
appId: params.appId,
|
|
54
|
-
});
|
|
38
|
+
// One cart item per booking ID. Single-day and allDay ranges produce one
|
|
39
|
+
// booking ID; DAY-range expansion produces one per day.
|
|
40
|
+
const cartRequest = buildCartRequest({
|
|
41
|
+
bookingIds,
|
|
42
|
+
contactDetails,
|
|
43
|
+
businessLocationId,
|
|
44
|
+
appId: params.appId,
|
|
45
|
+
});
|
|
55
46
|
const cart = await createCart(cartRequest);
|
|
56
47
|
if (!cart._id) {
|
|
57
48
|
throw new Error('Failed to create cart');
|
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
import { type CreateCartOptions } from '../../../api/create-cart/index.js';
|
|
2
2
|
import type { ContactDetails } from '@wix/auto_sdk_bookings_bookings';
|
|
3
3
|
export interface BuildCartParams {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export declare function buildCartRequest(params: BuildCartParams): CreateCartOptions;
|
|
12
|
-
/**
|
|
13
|
-
* DAY-range variant of `buildCartRequest`. Takes the N booking IDs returned
|
|
14
|
-
* by `bulkCreateBooking` (1 slot) or `createMultiServiceBooking` (2-8 slots)
|
|
15
|
-
* and emits one catalog item per ID. Per SDK guidance, never use
|
|
16
|
-
* `multiServiceBooking._id` here; always feed the per-day single-service
|
|
17
|
-
* booking IDs into the cart.
|
|
18
|
-
*/
|
|
19
|
-
export interface BuildDayRangeCartParams {
|
|
20
|
-
/** One catalog item per booking id. Bulk / multi-service responses produce N>=1 ids. */
|
|
4
|
+
/**
|
|
5
|
+
* One catalog item is emitted per booking id. Single-service and allDay
|
|
6
|
+
* bookings produce one id; DAY-range expansion produces one per day. Per SDK
|
|
7
|
+
* guidance, never use `multiServiceBooking._id` here; always feed the
|
|
8
|
+
* per-day single-service booking IDs into the cart.
|
|
9
|
+
*/
|
|
21
10
|
bookingIds: string[];
|
|
22
11
|
contactDetails?: ContactDetails;
|
|
23
12
|
/** `null` accepted so callers can forward SDK fields typed `string | null`. */
|
|
@@ -25,4 +14,4 @@ export interface BuildDayRangeCartParams {
|
|
|
25
14
|
/** Optional app ID override for the catalog reference. Defaults to BOOKING_APP_ID. */
|
|
26
15
|
appId?: string;
|
|
27
16
|
}
|
|
28
|
-
export declare function
|
|
17
|
+
export declare function buildCartRequest(params: BuildCartParams): CreateCartOptions;
|
|
@@ -1,12 +1,6 @@
|
|
|
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
|
-
return {
|
|
5
|
-
catalogItems: [buildCatalogItem(params.bookingId, params.appId)],
|
|
6
|
-
cart: buildCartShape(params),
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
export function buildDayRangeCartRequest(params) {
|
|
10
4
|
return {
|
|
11
5
|
catalogItems: params.bookingIds.map((id) => buildCatalogItem(id, params.appId)),
|
|
12
6
|
cart: buildCartShape(params),
|
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
* and the picker emits one slot per day in `rangeTimeSlots`. The client just
|
|
7
7
|
* packages them as one Booking each. Routing is decided by `bookings.length`
|
|
8
8
|
* in `createBookingsForCart`:
|
|
9
|
-
* - length 1 -> `
|
|
9
|
+
* - length 1 -> `createBooking`
|
|
10
10
|
* - length 2-8 -> `createMultiServiceBooking`
|
|
11
11
|
*
|
|
12
|
+
* With `allDay`, the picked slots collapse into one Booking spanning the full
|
|
13
|
+
* range, so that case routes through `createBooking`.
|
|
14
|
+
*
|
|
12
15
|
* The 8-day cap is enforced server-side; the builder does not gate on it.
|
|
13
16
|
*/
|
|
14
17
|
import type { Booking, ParticipantNotification } from '@wix/auto_sdk_bookings_bookings';
|
|
@@ -17,9 +20,9 @@ import type { BookActionParams } from './types.js';
|
|
|
17
20
|
export interface BuildDayRangeBookingRequest {
|
|
18
21
|
/**
|
|
19
22
|
* The Bookings to create. With `allDay`, this is a single Booking spanning
|
|
20
|
-
* the whole range
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
+
* the whole range. Otherwise it is one Booking per picked per-day slot:
|
|
24
|
+
* length 1 routes to createBooking, length >=2 routes to
|
|
25
|
+
* createMultiServiceBooking.
|
|
23
26
|
*/
|
|
24
27
|
bookings: Booking[];
|
|
25
28
|
/** Notification settings forwarded to the server. */
|
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
* and the picker emits one slot per day in `rangeTimeSlots`. The client just
|
|
7
7
|
* packages them as one Booking each. Routing is decided by `bookings.length`
|
|
8
8
|
* in `createBookingsForCart`:
|
|
9
|
-
* - length 1 -> `
|
|
9
|
+
* - length 1 -> `createBooking`
|
|
10
10
|
* - length 2-8 -> `createMultiServiceBooking`
|
|
11
11
|
*
|
|
12
|
+
* With `allDay`, the picked slots collapse into one Booking spanning the full
|
|
13
|
+
* range, so that case routes through `createBooking`.
|
|
14
|
+
*
|
|
12
15
|
* The 8-day cap is enforced server-side; the builder does not gate on it.
|
|
13
16
|
*/
|
|
14
17
|
import { buildBookingRequest } from './buildBookingRequest.js';
|
|
@@ -56,10 +59,6 @@ export function buildDayRangeBookingRequest(params) {
|
|
|
56
59
|
},
|
|
57
60
|
},
|
|
58
61
|
});
|
|
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
62
|
const bookings = params.allDay
|
|
64
63
|
? [buildBooking(slots[0].startDate, slots[slots.length - 1].endDate)]
|
|
65
64
|
: slots.map((slot) => buildBooking(slot.startDate, slot.endDate));
|
|
@@ -2,9 +2,9 @@
|
|
|
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 day -> `createBooking`
|
|
5
6
|
* - DAY-range path with `allDay` -> `createBooking` (one combined Booking)
|
|
6
|
-
* - DAY-range path with
|
|
7
|
-
* - DAY-range path with 2..8 picked slots -> `createMultiServiceBooking`
|
|
7
|
+
* - DAY-range path with 2..8 picked days -> `createMultiServiceBooking`
|
|
8
8
|
* - default path -> `createBooking`
|
|
9
9
|
*
|
|
10
10
|
* All branches return the same shape so `executeBookAction` can stay
|
|
@@ -2,9 +2,9 @@
|
|
|
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 day -> `createBooking`
|
|
5
6
|
* - DAY-range path with `allDay` -> `createBooking` (one combined Booking)
|
|
6
|
-
* - DAY-range path with
|
|
7
|
-
* - DAY-range path with 2..8 picked slots -> `createMultiServiceBooking`
|
|
7
|
+
* - DAY-range path with 2..8 picked days -> `createMultiServiceBooking`
|
|
8
8
|
* - default path -> `createBooking`
|
|
9
9
|
*
|
|
10
10
|
* All branches return the same shape so `executeBookAction` can stay
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* `multiServiceBooking._id`.
|
|
14
14
|
*/
|
|
15
15
|
import { createBooking } from '../../../api/create-booking/index.js';
|
|
16
|
-
import { bulkCreateBooking } from '../../../api/create-bulk-booking/index.js';
|
|
17
16
|
import { createMultiServiceBooking } from '../../../api/create-multi-service-booking/index.js';
|
|
18
17
|
import { buildBookingRequest } from './buildBookingRequest.js';
|
|
19
18
|
import { buildDayRangeBookingRequest } from './buildDayRangeBookingRequest.js';
|
|
@@ -25,9 +24,7 @@ export async function createBookingsForCart(params) {
|
|
|
25
24
|
}
|
|
26
25
|
if (isDayRangeService(firstSelection.service)) {
|
|
27
26
|
const req = buildDayRangeBookingRequest(params);
|
|
28
|
-
|
|
29
|
-
// Booking. Create it with plain `createBooking` (not bulk / multi-service).
|
|
30
|
-
if (params.allDay) {
|
|
27
|
+
if (req.bookings.length === 1) {
|
|
31
28
|
const bookingResponse = await createBooking(req.bookings[0], {
|
|
32
29
|
participantNotification: req.participantNotification,
|
|
33
30
|
sendSmsReminder: req.sendSmsReminder,
|
|
@@ -39,19 +36,6 @@ export async function createBookingsForCart(params) {
|
|
|
39
36
|
contactDetails: bookingResponse.booking?.contactDetails,
|
|
40
37
|
};
|
|
41
38
|
}
|
|
42
|
-
if (req.bookings.length === 1) {
|
|
43
|
-
const response = await bulkCreateBooking([{ booking: req.bookings[0] }], {
|
|
44
|
-
participantNotification: req.participantNotification,
|
|
45
|
-
sendSmsReminder: req.sendSmsReminder,
|
|
46
|
-
formSubmission: req.formSubmission,
|
|
47
|
-
});
|
|
48
|
-
const results = response.results ?? [];
|
|
49
|
-
return {
|
|
50
|
-
bookingIds: results.map((r) => r.item?._id).filter(Boolean),
|
|
51
|
-
// All N daily bookings share the same customer; read from the first.
|
|
52
|
-
contactDetails: results[0]?.item?.contactDetails,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
39
|
const response = await createMultiServiceBooking(req.bookings, {
|
|
56
40
|
participantNotification: req.participantNotification,
|
|
57
41
|
sendSmsReminder: req.sendSmsReminder,
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* APPOINTMENT services whose schedule has a `durationRange` with
|
|
5
5
|
* `unitType === DAY` route through the per-day slot path:
|
|
6
|
-
* - 1 picked slot -> `
|
|
6
|
+
* - 1 picked slot -> `createBooking`
|
|
7
7
|
* - 2..8 picked slots -> `createMultiServiceBooking`
|
|
8
|
+
* - 2..8 picked slots with `allDay` -> `createBooking`
|
|
8
9
|
*
|
|
9
10
|
* CLASS/COURSE selections and HOUR-range / fixed-duration APPOINTMENT
|
|
10
11
|
* selections keep using the existing `createBooking` path.
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* APPOINTMENT services whose schedule has a `durationRange` with
|
|
5
5
|
* `unitType === DAY` route through the per-day slot path:
|
|
6
|
-
* - 1 picked slot -> `
|
|
6
|
+
* - 1 picked slot -> `createBooking`
|
|
7
7
|
* - 2..8 picked slots -> `createMultiServiceBooking`
|
|
8
|
+
* - 2..8 picked slots with `allDay` -> `createBooking`
|
|
8
9
|
*
|
|
9
10
|
* CLASS/COURSE selections and HOUR-range / fixed-duration APPOINTMENT
|
|
10
11
|
* selections keep using the existing `createBooking` path.
|
|
@@ -56,9 +56,8 @@ export interface BookActionParams {
|
|
|
56
56
|
/**
|
|
57
57
|
* DAY-range only. When `true`, the picked per-day slots are collapsed into a
|
|
58
58
|
* single Booking spanning the whole range (`firstSlot.startDate ->
|
|
59
|
-
* lastSlot.endDate`) and created via plain `createBooking
|
|
60
|
-
*
|
|
61
|
-
* `createMultiServiceBooking` (2-8 slots). Ignored for non-DAY-range services.
|
|
59
|
+
* lastSlot.endDate`) and created via plain `createBooking`. Ignored for
|
|
60
|
+
* non-DAY-range services.
|
|
62
61
|
*/
|
|
63
62
|
allDay?: boolean;
|
|
64
63
|
}
|
|
@@ -48,8 +48,9 @@ export interface ServiceSelection {
|
|
|
48
48
|
* picker after the customer picks a start + end date: one entry per day
|
|
49
49
|
* in the picked range. When set, supersedes `timeSlot` for the DAY-range
|
|
50
50
|
* builder, which produces one Booking per entry and routes via length:
|
|
51
|
-
* - 1 ->
|
|
51
|
+
* - 1 -> createBooking
|
|
52
52
|
* - 2-8 -> createMultiServiceBooking
|
|
53
|
+
* - 2-8 with allDay -> createBooking
|
|
53
54
|
* Optional & additive: existing single-slot callers stay on `timeSlot`.
|
|
54
55
|
*/
|
|
55
56
|
rangeTimeSlots?: ServiceSelectionTimeSlot[];
|
|
@@ -90,9 +91,8 @@ export interface BookingServiceActions {
|
|
|
90
91
|
setSelectedPaymentOption(value: SelectedPaymentOption | null): void;
|
|
91
92
|
/**
|
|
92
93
|
* Toggle the DAY-range `allDay` flag. When `true`, `book()` collapses the
|
|
93
|
-
* picked per-day slots
|
|
94
|
-
*
|
|
95
|
-
* Ignored for non-DAY-range services.
|
|
94
|
+
* picked per-day slots into one range-spanning Booking created via
|
|
95
|
+
* `createBooking`. Ignored for non-DAY-range services.
|
|
96
96
|
*/
|
|
97
97
|
setAllDay(value: boolean): void;
|
|
98
98
|
clearAll(): void;
|
package/dist/services/index.d.ts
CHANGED
|
@@ -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,
|
|
10
|
+
export { executeBookAction, canBook, buildBookingRequest, buildCartRequest, buildDayRangeBookingRequest, createBookingsForCart, isDayRangeService, getDayRangeBounds, type CanBookParams, type BookResult, type BookingError, type BookActionParams, type BookChildProps, type BookProps, type BuildCartParams, 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';
|
package/dist/services/index.js
CHANGED
|
@@ -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,
|
|
10
|
+
export { executeBookAction, canBook, buildBookingRequest, buildCartRequest, 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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-bookings",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"groupId": "com.wixpress.headless-components"
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
-
"falconPackageHash": "
|
|
79
|
+
"falconPackageHash": "1d7f35a0513a0780cb412d80a034e1ed5b5e3bccbbc1bb20f4ad1481"
|
|
80
80
|
}
|