@wix/headless-bookings 0.0.43 → 0.0.45

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 (53) hide show
  1. package/cjs/dist/__mocks__/booking.d.ts +9 -4
  2. package/cjs/dist/__mocks__/booking.js +48 -3
  3. package/cjs/dist/__mocks__/time-slots.d.ts +28 -0
  4. package/cjs/dist/__mocks__/time-slots.js +116 -0
  5. package/cjs/dist/api/index.d.ts +1 -0
  6. package/cjs/dist/api/index.js +1 -0
  7. package/cjs/dist/api/query-locations/index.d.ts +38 -0
  8. package/cjs/dist/api/query-locations/index.js +30 -0
  9. package/cjs/dist/react/core/location/Location.d.ts +113 -14
  10. package/cjs/dist/react/core/location/Location.js +189 -30
  11. package/cjs/dist/react/core/location-list/LocationList.d.ts +102 -0
  12. package/cjs/dist/react/core/location-list/LocationList.js +71 -0
  13. package/cjs/dist/react/index.d.ts +1 -0
  14. package/cjs/dist/react/index.js +1 -0
  15. package/cjs/dist/react/location/Location.d.ts +211 -41
  16. package/cjs/dist/react/location/Location.js +219 -46
  17. package/cjs/dist/react/location/LocationList.d.ts +98 -0
  18. package/cjs/dist/react/location/LocationList.js +120 -0
  19. package/cjs/dist/react/service/Service.d.ts +17 -24
  20. package/cjs/dist/react/service/Service.js +24 -36
  21. package/cjs/dist/services/index.d.ts +1 -0
  22. package/cjs/dist/services/index.js +1 -0
  23. package/cjs/dist/services/location-list/location-list.d.ts +100 -0
  24. package/cjs/dist/services/location-list/location-list.def.d.ts +62 -0
  25. package/cjs/dist/services/location-list/location-list.def.js +17 -0
  26. package/cjs/dist/services/location-list/location-list.js +212 -0
  27. package/dist/__mocks__/booking.d.ts +9 -4
  28. package/dist/__mocks__/booking.js +48 -3
  29. package/dist/__mocks__/time-slots.d.ts +28 -0
  30. package/dist/__mocks__/time-slots.js +116 -0
  31. package/dist/api/index.d.ts +1 -0
  32. package/dist/api/index.js +1 -0
  33. package/dist/api/query-locations/index.d.ts +38 -0
  34. package/dist/api/query-locations/index.js +30 -0
  35. package/dist/react/core/location/Location.d.ts +113 -14
  36. package/dist/react/core/location/Location.js +189 -30
  37. package/dist/react/core/location-list/LocationList.d.ts +102 -0
  38. package/dist/react/core/location-list/LocationList.js +71 -0
  39. package/dist/react/index.d.ts +1 -0
  40. package/dist/react/index.js +1 -0
  41. package/dist/react/location/Location.d.ts +211 -41
  42. package/dist/react/location/Location.js +219 -46
  43. package/dist/react/location/LocationList.d.ts +98 -0
  44. package/dist/react/location/LocationList.js +120 -0
  45. package/dist/react/service/Service.d.ts +17 -24
  46. package/dist/react/service/Service.js +24 -36
  47. package/dist/services/index.d.ts +1 -0
  48. package/dist/services/index.js +1 -0
  49. package/dist/services/location-list/location-list.d.ts +100 -0
  50. package/dist/services/location-list/location-list.def.d.ts +62 -0
  51. package/dist/services/location-list/location-list.def.js +17 -0
  52. package/dist/services/location-list/location-list.js +212 -0
  53. package/package.json +2 -2
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Location List Service Implementation
3
+ * Manages location state, auto-detection, and BookingService integration
4
+ *
5
+ * @module Services/LocationList
6
+ */
7
+ import { implementService } from '@wix/services-definitions';
8
+ import { SignalsServiceDefinition, } from '@wix/services-definitions/core-services/signals';
9
+ import { LocationType } from '@wix/auto_sdk_bookings_services';
10
+ import { LocationListServiceDefinition, } from './location-list.def.js';
11
+ import { BookingServiceDefinition } from '../booking/booking.js';
12
+ import { queryLocations } from '../../api/query-locations/index.js';
13
+ // ============================================================================
14
+ // Constants
15
+ // ============================================================================
16
+ /**
17
+ * Synthetic location IDs for non-business locations
18
+ */
19
+ const SYNTHETIC_CUSTOM_ID = '__synthetic_custom__';
20
+ const SYNTHETIC_CUSTOMER_ID = '__synthetic_customer__';
21
+ // ============================================================================
22
+ // Helper Functions
23
+ // ============================================================================
24
+ /**
25
+ * Build display locations from raw locations and flags
26
+ */
27
+ function buildDisplayLocations(locations, hasCustomLocations, hasCustomerLocations) {
28
+ const displayLocations = [];
29
+ // 1. Add all BUSINESS locations
30
+ const businessLocations = locations.filter((loc) => loc.type === LocationType.BUSINESS || loc.type === undefined);
31
+ for (const loc of businessLocations) {
32
+ displayLocations.push({
33
+ location: loc,
34
+ type: LocationType.BUSINESS,
35
+ isSynthetic: false,
36
+ id: loc.business?._id || loc._id || String(displayLocations.length),
37
+ });
38
+ }
39
+ // Check for existing CUSTOM/CUSTOMER in array
40
+ const customFromArray = locations.find((loc) => loc.type === LocationType.CUSTOM);
41
+ const customerFromArray = locations.find((loc) => loc.type === LocationType.CUSTOMER);
42
+ // 2. Add CUSTOM location (from array or synthetic)
43
+ if (customFromArray) {
44
+ displayLocations.push({
45
+ location: customFromArray,
46
+ type: LocationType.CUSTOM,
47
+ isSynthetic: false,
48
+ id: customFromArray.custom?._id || SYNTHETIC_CUSTOM_ID,
49
+ });
50
+ }
51
+ else if (hasCustomLocations) {
52
+ // Synthetic custom location (only from explicit flag, not array)
53
+ displayLocations.push({
54
+ location: null,
55
+ type: LocationType.CUSTOM,
56
+ isSynthetic: true,
57
+ id: SYNTHETIC_CUSTOM_ID,
58
+ });
59
+ }
60
+ // 3. Add CUSTOMER location (always synthetic display, real or flag-based)
61
+ if (customerFromArray || hasCustomerLocations) {
62
+ displayLocations.push({
63
+ location: customerFromArray || null,
64
+ type: LocationType.CUSTOMER,
65
+ isSynthetic: !customerFromArray,
66
+ id: SYNTHETIC_CUSTOMER_ID,
67
+ });
68
+ }
69
+ return displayLocations;
70
+ }
71
+ // ============================================================================
72
+ // Service Implementation
73
+ // ============================================================================
74
+ /**
75
+ * Implementation of the LocationList service
76
+ * Manages location state and integrates with BookingService for selection (optional)
77
+ */
78
+ export const LocationListService = implementService.withConfig()(LocationListServiceDefinition, ({ getService, config }) => {
79
+ const signalsService = getService(SignalsServiceDefinition);
80
+ // Try to get BookingService - it's optional (Location can be standalone)
81
+ let bookingService = null;
82
+ try {
83
+ bookingService = getService(BookingServiceDefinition);
84
+ }
85
+ catch {
86
+ // BookingService not available - Location is used standalone
87
+ bookingService = null;
88
+ }
89
+ // Initialize raw locations signal
90
+ const locationsSignal = signalsService.signal(config.locations || []);
91
+ // Auto-detect from array
92
+ const hasCustomInArray = (config.locations || []).some((loc) => loc.type === LocationType.CUSTOM);
93
+ const hasCustomerInArray = (config.locations || []).some((loc) => loc.type === LocationType.CUSTOMER);
94
+ // Final flags: explicit config OR auto-detected
95
+ const hasCustomLocationsSignal = signalsService.computed(() => config.hasCustomLocations ?? hasCustomInArray);
96
+ const hasCustomerLocationsSignal = signalsService.computed(() => config.hasCustomerLocations ?? hasCustomerInArray);
97
+ // Display locations - computed from raw + flags
98
+ const displayLocationsSignal = signalsService.computed(() => buildDisplayLocations(locationsSignal.get(), hasCustomLocationsSignal.get(), hasCustomerLocationsSignal.get()));
99
+ const isLoadingSignal = signalsService.signal(false);
100
+ const errorSignal = signalsService.signal(null);
101
+ // Selected location from BookingService (null if standalone)
102
+ const selectedLocationSignal = signalsService.computed(() => {
103
+ if (!bookingService)
104
+ return null;
105
+ return bookingService.location.get();
106
+ });
107
+ // Actions - integrate with BookingService if available
108
+ const actions = {
109
+ select: (displayLocation) => {
110
+ if (bookingService) {
111
+ bookingService.actions.setLocation(displayLocation.location);
112
+ }
113
+ // If standalone, selection is handled by consumer via asChild
114
+ },
115
+ };
116
+ return {
117
+ locations: locationsSignal,
118
+ displayLocations: displayLocationsSignal,
119
+ hasCustomLocations: hasCustomLocationsSignal,
120
+ hasCustomerLocations: hasCustomerLocationsSignal,
121
+ isLoading: isLoadingSignal,
122
+ error: errorSignal,
123
+ selectedLocation: selectedLocationSignal,
124
+ actions,
125
+ };
126
+ });
127
+ /**
128
+ * SSR Loader: Fetches locations from API for server-side rendering.
129
+ *
130
+ * @param options - Optional configuration
131
+ * @returns Configuration result for LocationListService with pre-fetched locations
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // Fetch from API
136
+ * const result = await loadLocationListServiceInitialData();
137
+ *
138
+ * if (result.type === 'error') {
139
+ * return Astro.redirect('/500');
140
+ * }
141
+ *
142
+ * const locationListConfig = result.config;
143
+ * ```
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * // Pass locations directly (e.g., from service.locations)
148
+ * const result = await loadLocationListServiceInitialData({
149
+ * locations: service.locations,
150
+ * // hasCustom/hasCustomer will be auto-detected from array
151
+ * });
152
+ * ```
153
+ */
154
+ export async function loadLocationListServiceInitialData(options) {
155
+ try {
156
+ // If locations are passed directly, use them (flags auto-detected if not provided)
157
+ if (options?.locations) {
158
+ return {
159
+ type: 'success',
160
+ config: {
161
+ locations: options.locations,
162
+ hasCustomLocations: options.hasCustomLocations,
163
+ hasCustomerLocations: options.hasCustomerLocations,
164
+ },
165
+ };
166
+ }
167
+ // Otherwise, fetch from API
168
+ const result = await queryLocations();
169
+ return {
170
+ type: 'success',
171
+ config: {
172
+ locations: result.locations,
173
+ hasCustomLocations: result.hasCustomLocations,
174
+ hasCustomerLocations: result.hasCustomerLocations,
175
+ },
176
+ };
177
+ }
178
+ catch (error) {
179
+ const message = error instanceof Error ? error.message : 'Failed to load locations';
180
+ console.error('loadLocationListServiceInitialData error:', error);
181
+ return { type: 'error', error: message };
182
+ }
183
+ }
184
+ // ============================================================================
185
+ // Service Binding Helper
186
+ // ============================================================================
187
+ /**
188
+ * Service binding helper for LocationListService.
189
+ * Bundles definition, implementation, and config for ServicesManager.
190
+ *
191
+ * @param servicesConfigs - Object containing LocationListServiceDefinition config
192
+ * @returns Tuple of [Definition, Implementation, Config] for addService()
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const servicesManager = createServicesManager(
197
+ * createServicesMap()
198
+ * .addService(...locationListServiceBinding(configs))
199
+ * );
200
+ * ```
201
+ */
202
+ export const locationListServiceBinding = (servicesConfigs) => {
203
+ return [
204
+ LocationListServiceDefinition,
205
+ LocationListService,
206
+ servicesConfigs['location-list'],
207
+ ];
208
+ };
209
+ // ============================================================================
210
+ // Re-exports
211
+ // ============================================================================
212
+ export { LocationListServiceDefinition, LocationType, } from './location-list.def.js';
@@ -1,9 +1,14 @@
1
- /**
2
- * Shared mock data for booking service tests
3
- */
4
1
  import type { Resource } from '@wix/auto_sdk_bookings_availability-time-slots';
5
2
  import type { FormValues } from '@wix/form-public';
6
- import type { ServiceSelection, ServiceSelectionTimeSlot, BookingServiceConfig } from '../services/booking/booking.js';
3
+ import type { ServiceSelection, ServiceSelectionTimeSlot, BookingServiceConfig, BookingService } from '../services/booking/booking.js';
4
+ import type { Signal } from '@wix/services-definitions/core-services/signals';
5
+ export declare function mockSignal<T>(initialValue: T): Signal<T>;
6
+ export declare function createMockSignalsService(): {
7
+ signal: typeof mockSignal;
8
+ computed: <T>(fn: () => T) => Signal<T>;
9
+ effect: (fn: () => void) => void;
10
+ };
11
+ export declare function createMockBookingService(initialSelections?: ServiceSelection[]): BookingService;
7
12
  /**
8
13
  * Mock resource (staff member)
9
14
  */
@@ -1,7 +1,52 @@
1
- /**
2
- * Shared mock data for booking service tests
3
- */
4
1
  import { mockService, mockServiceClass } from './services.js';
2
+ import { vi } from 'vitest';
3
+ export function mockSignal(initialValue) {
4
+ let value = initialValue;
5
+ return {
6
+ get: () => value,
7
+ peek: () => value,
8
+ set: (newValue) => {
9
+ value = newValue;
10
+ },
11
+ };
12
+ }
13
+ export function createMockSignalsService() {
14
+ return {
15
+ signal: mockSignal,
16
+ computed: (fn) => mockSignal(fn()),
17
+ effect: vi.fn((fn) => {
18
+ fn();
19
+ }),
20
+ };
21
+ }
22
+ export function createMockBookingService(initialSelections = []) {
23
+ const serviceSelectionsSignal = mockSignal(initialSelections);
24
+ const locationSignal = mockSignal(null);
25
+ const timezoneSignal = mockSignal('UTC');
26
+ const formSubmissionSignal = mockSignal(null);
27
+ return {
28
+ serviceSelections: serviceSelectionsSignal,
29
+ location: locationSignal,
30
+ timezone: timezoneSignal,
31
+ formSubmission: formSubmissionSignal,
32
+ actions: {
33
+ updateItem: vi.fn(),
34
+ setItem: vi.fn(),
35
+ addItem: vi.fn(),
36
+ removeItem: vi.fn(),
37
+ clearItems: vi.fn(),
38
+ setResourceById: vi.fn(),
39
+ getResourceById: vi.fn(),
40
+ setLocation: vi.fn(),
41
+ clearLocation: vi.fn(),
42
+ setTimezone: vi.fn(),
43
+ setFormSubmission: vi.fn(),
44
+ clearFormSubmission: vi.fn(),
45
+ clearAll: vi.fn(),
46
+ book: vi.fn(),
47
+ },
48
+ };
49
+ }
5
50
  /**
6
51
  * Mock resource (staff member)
7
52
  */
@@ -0,0 +1,28 @@
1
+ import type { TimeSlot } from '@wix/auto_sdk_bookings_availability-time-slots';
2
+ import type { TimeSlotListServiceConfig, TimeSlotListServiceAPI } from '../services/time-slot-list/time-slot-list.def.js';
3
+ import type { BookingService } from '../services/booking/booking.js';
4
+ export declare function createTimeSlotListService(overrides?: Partial<TimeSlotListServiceConfig>): {
5
+ service: TimeSlotListServiceAPI;
6
+ bookingService: BookingService;
7
+ };
8
+ export declare function createTimeSlot(overrides?: Partial<TimeSlot>): TimeSlot;
9
+ export declare function createTimeSlots(count: number): TimeSlot[];
10
+ export declare function createTimeSlotListConfig(overrides?: Partial<TimeSlotListServiceConfig>): TimeSlotListServiceConfig;
11
+ export declare const mockTimeSlot: TimeSlot;
12
+ export declare const mockTimeSlotMultipleStaff: TimeSlot;
13
+ export declare const mockTimeSlotNotBookable: TimeSlot;
14
+ export declare const mockTimeSlots: TimeSlot[];
15
+ export declare const mockStartDate: Date;
16
+ export declare const mockEndDate: Date;
17
+ export declare const mockTimezone = "America/New_York";
18
+ export declare const mockTimeSlotListConfig: TimeSlotListServiceConfig;
19
+ export declare const mockEmptyTimeSlotListConfig: TimeSlotListServiceConfig;
20
+ export declare const mockCursorPagingMetadataWithMore: {
21
+ cursors: {
22
+ next: string;
23
+ };
24
+ };
25
+ export declare const mockCursorPagingMetadataNoMore: {
26
+ cursors: {};
27
+ };
28
+ export declare function createMockTimeSlotListService(config?: Partial<TimeSlotListServiceConfig>): TimeSlotListServiceAPI;
@@ -0,0 +1,116 @@
1
+ import { vi } from 'vitest';
2
+ import { TimeSlotListService } from '../services/time-slot-list/time-slot-list.js';
3
+ import { createMockBookingService, createMockSignalsService, mockSignal, } from './booking.js';
4
+ export function createTimeSlotListService(overrides = {}) {
5
+ const config = createTimeSlotListConfig(overrides);
6
+ const mockBookingService = createMockBookingService();
7
+ const mockSignalsService = createMockSignalsService();
8
+ const getService = (definition) => {
9
+ const def = definition;
10
+ if (def.name === 'signals') {
11
+ return mockSignalsService;
12
+ }
13
+ if (def.name === 'booking') {
14
+ return mockBookingService;
15
+ }
16
+ throw new Error(`Unknown service: ${def.name}`);
17
+ };
18
+ const service = TimeSlotListService({
19
+ getService,
20
+ config,
21
+ });
22
+ return {
23
+ service,
24
+ bookingService: mockBookingService,
25
+ };
26
+ }
27
+ export function createTimeSlot(overrides = {}) {
28
+ return {
29
+ localStartDate: '2024-01-15T10:00:00',
30
+ localEndDate: '2024-01-15T11:00:00',
31
+ bookable: true,
32
+ totalCapacity: 10,
33
+ remainingCapacity: 5,
34
+ scheduleId: 'schedule-1',
35
+ location: { _id: 'loc-1', name: 'Main Office' },
36
+ availableResources: [{ resources: [{ _id: 'staff-1', name: 'John Doe' }] }],
37
+ ...overrides,
38
+ };
39
+ }
40
+ export function createTimeSlots(count) {
41
+ return Array.from({ length: count }, (_, i) => createTimeSlot({
42
+ localStartDate: `2024-01-15T${String(9 + (i % 8)).padStart(2, '0')}:00:00`,
43
+ localEndDate: `2024-01-15T${String(10 + (i % 8)).padStart(2, '0')}:00:00`,
44
+ scheduleId: `schedule-${i}`,
45
+ }));
46
+ }
47
+ export function createTimeSlotListConfig(overrides = {}) {
48
+ const { startDate = new Date('2024-01-15T00:00:00'), endDate = new Date('2024-01-22T00:00:00'), timezone = 'America/New_York', timeSlots, ...rest } = overrides;
49
+ return {
50
+ startDate,
51
+ endDate,
52
+ timezone,
53
+ ...rest,
54
+ ...(timeSlots !== undefined ? { timeSlots } : {}),
55
+ };
56
+ }
57
+ export const mockTimeSlot = createTimeSlot();
58
+ export const mockTimeSlotMultipleStaff = createTimeSlot({
59
+ availableResources: [
60
+ {
61
+ resources: [
62
+ { _id: 'staff-1', name: 'John Doe' },
63
+ { _id: 'staff-2', name: 'Jane Smith' },
64
+ ],
65
+ },
66
+ ],
67
+ });
68
+ export const mockTimeSlotNotBookable = createTimeSlot({
69
+ localStartDate: '2024-01-15T14:00:00',
70
+ localEndDate: '2024-01-15T15:00:00',
71
+ bookable: false,
72
+ remainingCapacity: 0,
73
+ location: { _id: 'loc-2', name: 'Downtown Branch' },
74
+ });
75
+ export const mockTimeSlots = [
76
+ mockTimeSlot,
77
+ mockTimeSlotMultipleStaff,
78
+ mockTimeSlotNotBookable,
79
+ ];
80
+ export const mockStartDate = new Date('2024-01-15T00:00:00');
81
+ export const mockEndDate = new Date('2024-01-22T00:00:00');
82
+ export const mockTimezone = 'America/New_York';
83
+ export const mockTimeSlotListConfig = createTimeSlotListConfig({
84
+ timeSlots: mockTimeSlots,
85
+ });
86
+ export const mockEmptyTimeSlotListConfig = createTimeSlotListConfig();
87
+ export const mockCursorPagingMetadataWithMore = {
88
+ cursors: { next: 'next-cursor-token' },
89
+ };
90
+ export const mockCursorPagingMetadataNoMore = { cursors: {} };
91
+ export function createMockTimeSlotListService(config = {}) {
92
+ const timeSlotsSignal = mockSignal(config.timeSlots || []);
93
+ const isLoadingSignal = mockSignal(false);
94
+ const errorSignal = mockSignal(null);
95
+ const hasMoreSignal = mockSignal(false);
96
+ const dateRangeSignal = mockSignal({
97
+ start: config.startDate || mockStartDate,
98
+ end: config.endDate || mockEndDate,
99
+ });
100
+ return {
101
+ timeSlots: timeSlotsSignal,
102
+ isLoading: isLoadingSignal,
103
+ error: errorSignal,
104
+ hasMore: hasMoreSignal,
105
+ dateRange: dateRangeSignal,
106
+ actions: {
107
+ selectSlot: vi.fn(),
108
+ selectStaffMember: vi.fn(),
109
+ clearStaffSelection: vi.fn(),
110
+ loadMore: vi.fn(),
111
+ setDateRange: vi.fn((start, end) => {
112
+ dateRangeSignal.set({ start, end });
113
+ }),
114
+ },
115
+ };
116
+ }
@@ -8,6 +8,7 @@ export { getServiceById, getServiceBySlug, queryServices, type PagingMetadata, t
8
8
  export { fetchAvailability } from './fetch-availability/index.js';
9
9
  export { createBooking, type CreateBookingOptions, type Booking, type CreateBookingRequest, type CreateBookingResponse, type ParticipantNotification, type ContactDetails, } from './create-booking/index.js';
10
10
  export { createCheckout, ChannelType, type CreateCheckoutRequest, type CreateCheckoutResponse, } from './create-checkout/index.js';
11
+ export { queryLocations, type QueryLocationsResult, type LocationData, } from './query-locations/index.js';
11
12
  /**
12
13
  * PagingMetadata includes:
13
14
  * - limit: Number of items per page
package/dist/api/index.js CHANGED
@@ -8,6 +8,7 @@ export { getServiceById, getServiceBySlug, queryServices, } from './query-servic
8
8
  export { fetchAvailability } from './fetch-availability/index.js';
9
9
  export { createBooking, } from './create-booking/index.js';
10
10
  export { createCheckout, ChannelType, } from './create-checkout/index.js';
11
+ export { queryLocations, } from './query-locations/index.js';
11
12
  /**
12
13
  * PagingMetadata includes:
13
14
  * - limit: Number of items per page
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Query Locations API
3
+ * Fetches business locations from Wix Bookings Services
4
+ *
5
+ * @module API/QueryLocations
6
+ */
7
+ import type { Service } from '@wix/auto_sdk_bookings_services';
8
+ /**
9
+ * LocationData type - from Service['locations'][number]
10
+ */
11
+ export type LocationData = NonNullable<Service['locations']>[number];
12
+ /**
13
+ * Result from querying locations
14
+ */
15
+ export interface QueryLocationsResult {
16
+ /** Business locations array */
17
+ locations: LocationData[];
18
+ /** Whether custom locations exist for any service */
19
+ hasCustomLocations: boolean;
20
+ /** Whether customer locations (at customer's place) exist for any service */
21
+ hasCustomerLocations: boolean;
22
+ }
23
+ /**
24
+ * Query all locations connected to services.
25
+ * Returns business locations array and existence flags for custom/customer locations.
26
+ *
27
+ * @returns Promise resolving to locations and existence flags
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const { locations, hasCustomLocations, hasCustomerLocations } = await queryLocations();
32
+ *
33
+ * // locations contains all business locations
34
+ * // hasCustomLocations indicates if any service uses custom locations
35
+ * // hasCustomerLocations indicates if any service is at customer's place
36
+ * ```
37
+ */
38
+ export declare function queryLocations(): Promise<QueryLocationsResult>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Query Locations API
3
+ * Fetches business locations from Wix Bookings Services
4
+ *
5
+ * @module API/QueryLocations
6
+ */
7
+ import { queryLocations as queryLocationsApi, } from '@wix/auto_sdk_bookings_services';
8
+ /**
9
+ * Query all locations connected to services.
10
+ * Returns business locations array and existence flags for custom/customer locations.
11
+ *
12
+ * @returns Promise resolving to locations and existence flags
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const { locations, hasCustomLocations, hasCustomerLocations } = await queryLocations();
17
+ *
18
+ * // locations contains all business locations
19
+ * // hasCustomLocations indicates if any service uses custom locations
20
+ * // hasCustomerLocations indicates if any service is at customer's place
21
+ * ```
22
+ */
23
+ export async function queryLocations() {
24
+ const response = await queryLocationsApi();
25
+ return {
26
+ locations: (response.businessLocations?.locations || []),
27
+ hasCustomLocations: response.customLocations?.exists || false,
28
+ hasCustomerLocations: response.customerLocations?.exists || false,
29
+ };
30
+ }
@@ -2,6 +2,8 @@
2
2
  * Core Location Component - Parses service location data
3
3
  * Handles business, custom, and customer location types
4
4
  * Converts location data to Address component format
5
+ *
6
+ * @module Core/Location
5
7
  */
6
8
  import React from 'react';
7
9
  import { LocationType, type Service } from '@wix/auto_sdk_bookings_services';
@@ -10,35 +12,132 @@ import type { AddressData as AddressDataType } from '@wix/headless-components/re
10
12
  * Re-export AddressData type from Address component for convenience
11
13
  */
12
14
  export type AddressData = AddressDataType;
15
+ /**
16
+ * Service location type - from Service['locations'][number]
17
+ */
18
+ export type ServiceLocation = NonNullable<Service['locations']>[number];
19
+ /**
20
+ * Synthetic location - represents a location type without real data
21
+ * Used for CUSTOMER or CUSTOM locations when no real location data exists
22
+ */
23
+ export interface SyntheticLocation {
24
+ /** Location type */
25
+ locationType: LocationType.CUSTOMER | LocationType.CUSTOM;
26
+ /** Marker to identify synthetic locations */
27
+ synthetic: true;
28
+ /** Optional ID for tracking */
29
+ id?: string;
30
+ }
31
+ /**
32
+ * Union type - location prop accepts Service or Synthetic location
33
+ */
34
+ export type LocationInput = ServiceLocation | SyntheticLocation;
13
35
  /**
14
36
  * Location render props passed to children
15
37
  */
16
38
  export interface LocationRenderProps {
39
+ /** Location type */
17
40
  locationType: LocationType;
41
+ /** Parsed address data compatible with Address.Root, null if not available */
18
42
  address: AddressData | null;
43
+ /** Location name (business.name or custom name) */
44
+ name: string | undefined;
45
+ /** Location ID */
46
+ locationId: string | undefined;
47
+ /** Whether this is a customer location */
48
+ isCustomerLocation: boolean;
49
+ /** Whether this is a custom location */
50
+ isCustomLocation: boolean;
51
+ /** Whether this is a synthetic entry (not from array) */
52
+ isSynthetic: boolean;
53
+ /** Phone number (only for BUSINESS ServiceLocations) */
54
+ phone: string | undefined;
55
+ /** Email address (only for BUSINESS ServiceLocations) */
56
+ email: string | undefined;
57
+ /** Raw location object (Service or Synthetic location) */
58
+ rawLocation: LocationInput | null;
19
59
  }
20
60
  /**
21
- * Props for the core Location component
61
+ * Props for the Core Location Root component
22
62
  */
23
- export interface LocationProps {
24
- location: NonNullable<Service['locations']>[number];
63
+ export interface RootProps {
64
+ /** Raw location data - accepts Service or Synthetic location */
65
+ location?: LocationInput;
66
+ /** Children */
67
+ children: React.ReactNode;
68
+ }
69
+ /**
70
+ * Props for the Core Location Data component
71
+ */
72
+ export interface DataProps {
73
+ /** Children render prop that receives location data */
25
74
  children: (props: LocationRenderProps) => React.ReactNode;
26
75
  }
27
76
  /**
28
- * Core Location component that parses service location data
29
- * and provides location type and address data to children
77
+ * Hook to access location context from CoreLocation.Root
78
+ * @throws Error if used outside of CoreLocation.Root
79
+ */
80
+ export declare function useLocationContext(): LocationRenderProps;
81
+ /**
82
+ * Core Location Root component that provides location context.
83
+ * Parses location data and makes it available to all child components via context.
84
+ *
85
+ * @component
86
+ * @example
87
+ * ```tsx
88
+ * <CoreLocation.Root location={serviceLocation}>
89
+ * <Location.Name />
90
+ * <Location.Address />
91
+ * </CoreLocation.Root>
92
+ * ```
93
+ */
94
+ export declare function Root(props: RootProps): React.ReactNode;
95
+ /**
96
+ * Core Location Data component that exposes location data via render props.
97
+ * Must be used within a CoreLocation.Root component.
98
+ *
99
+ * @component
100
+ * @example
101
+ * ```tsx
102
+ * <CoreLocation.Root location={serviceLocation}>
103
+ * <CoreLocation.Data>
104
+ * {({ displayName, address }) => (
105
+ * <div>
106
+ * <span>{displayName}</span>
107
+ * {address && <Address.Formatted address={address} />}
108
+ * </div>
109
+ * )}
110
+ * </CoreLocation.Data>
111
+ * </CoreLocation.Root>
112
+ * ```
113
+ */
114
+ export declare function Data(props: DataProps): React.ReactNode;
115
+ /**
116
+ * Props for Actions render prop component
117
+ */
118
+ export interface ActionsProps {
119
+ children: (actions: {
120
+ select: () => void;
121
+ rawLocation: LocationInput | null;
122
+ selected: boolean;
123
+ }) => React.ReactNode;
124
+ }
125
+ /**
126
+ * Core component that provides location selection actions via render props.
127
+ * Sets the location in BookingService when select is called.
30
128
  *
31
129
  * @component
32
130
  * @example
33
131
  * ```tsx
34
- * <CoreLocation location={serviceLocation}>
35
- * {({ locationType, address }) => (
36
- * <div>
37
- * <span>Type: {locationType}</span>
38
- * {address && <Address.Root address={address}><Address.Formatted /></Address.Root>}
39
- * </div>
40
- * )}
41
- * </CoreLocation>
132
+ * <CoreLocation.Root location={serviceLocation}>
133
+ * <CoreLocation.Actions>
134
+ * {({ select, selected, rawLocation }) => (
135
+ * <button onClick={select}>
136
+ * {selected ? 'Selected' : 'Select'}
137
+ * </button>
138
+ * )}
139
+ * </CoreLocation.Actions>
140
+ * </CoreLocation.Root>
42
141
  * ```
43
142
  */
44
- export declare function Location(props: LocationProps): React.ReactNode;
143
+ export declare function Actions(props: ActionsProps): React.ReactNode;