@wix/headless-restaurants-olo 0.0.14 → 0.0.16

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 (85) hide show
  1. package/cjs/dist/mappers/operation-mapper.d.ts +3 -0
  2. package/cjs/dist/mappers/operation-mapper.js +95 -0
  3. package/cjs/dist/react/ItemDetails.d.ts +4 -162
  4. package/cjs/dist/react/ItemDetails.js +6 -78
  5. package/cjs/dist/react/ModifierGroup.d.ts +57 -0
  6. package/cjs/dist/react/ModifierGroup.js +61 -0
  7. package/cjs/dist/react/OLO.d.ts +3 -2
  8. package/cjs/dist/react/OLOMenus.d.ts +20 -0
  9. package/cjs/dist/react/OLOMenus.js +22 -0
  10. package/cjs/dist/react/Settings.d.ts +160 -0
  11. package/cjs/dist/react/Settings.js +94 -0
  12. package/cjs/dist/react/core/ItemDetails.d.ts +1 -11
  13. package/cjs/dist/react/core/ItemDetails.js +4 -21
  14. package/cjs/dist/react/core/ModifierGroup.d.ts +42 -0
  15. package/cjs/dist/react/core/ModifierGroup.js +67 -0
  16. package/cjs/dist/react/core/OLO.js +16 -2
  17. package/cjs/dist/react/core/OLOMenus.d.ts +7 -0
  18. package/cjs/dist/react/core/OLOMenus.js +12 -0
  19. package/cjs/dist/react/core/Settings.d.ts +157 -0
  20. package/cjs/dist/react/core/Settings.js +192 -0
  21. package/cjs/dist/react/core/index.d.ts +1 -0
  22. package/cjs/dist/react/core/index.js +1 -0
  23. package/cjs/dist/react/index.d.ts +3 -0
  24. package/cjs/dist/react/index.js +3 -0
  25. package/cjs/dist/services/common-types.d.ts +18 -0
  26. package/cjs/dist/services/common-types.js +10 -0
  27. package/cjs/dist/services/fulfillments-service.d.ts +13 -0
  28. package/cjs/dist/services/fulfillments-service.js +64 -0
  29. package/cjs/dist/services/index.d.ts +1 -0
  30. package/cjs/dist/services/index.js +1 -0
  31. package/cjs/dist/services/item-details-service.d.ts +2 -0
  32. package/cjs/dist/services/item-details-service.js +8 -1
  33. package/cjs/dist/services/olo-settings-service.d.ts +14 -8
  34. package/cjs/dist/services/olo-settings-service.js +24 -5
  35. package/cjs/dist/services/utils.d.ts +17 -0
  36. package/cjs/dist/services/utils.js +104 -0
  37. package/cjs/dist/types/fulfillments-types.d.ts +33 -0
  38. package/cjs/dist/types/fulfillments-types.js +7 -0
  39. package/cjs/dist/types/operation.d.ts +57 -0
  40. package/cjs/dist/types/operation.js +1 -0
  41. package/cjs/dist/utils/fulfillments-utils.d.ts +23 -0
  42. package/cjs/dist/utils/fulfillments-utils.js +144 -0
  43. package/dist/mappers/operation-mapper.d.ts +3 -0
  44. package/dist/mappers/operation-mapper.js +95 -0
  45. package/dist/react/ItemDetails.d.ts +4 -162
  46. package/dist/react/ItemDetails.js +6 -78
  47. package/dist/react/ModifierGroup.d.ts +57 -0
  48. package/dist/react/ModifierGroup.js +61 -0
  49. package/dist/react/OLO.d.ts +3 -2
  50. package/dist/react/OLOMenus.d.ts +20 -0
  51. package/dist/react/OLOMenus.js +22 -0
  52. package/dist/react/Settings.d.ts +160 -0
  53. package/dist/react/Settings.js +94 -0
  54. package/dist/react/core/ItemDetails.d.ts +1 -11
  55. package/dist/react/core/ItemDetails.js +4 -21
  56. package/dist/react/core/ModifierGroup.d.ts +42 -0
  57. package/dist/react/core/ModifierGroup.js +67 -0
  58. package/dist/react/core/OLO.js +16 -2
  59. package/dist/react/core/OLOMenus.d.ts +7 -0
  60. package/dist/react/core/OLOMenus.js +12 -0
  61. package/dist/react/core/Settings.d.ts +157 -0
  62. package/dist/react/core/Settings.js +192 -0
  63. package/dist/react/core/index.d.ts +1 -0
  64. package/dist/react/core/index.js +1 -0
  65. package/dist/react/index.d.ts +3 -0
  66. package/dist/react/index.js +3 -0
  67. package/dist/services/common-types.d.ts +18 -0
  68. package/dist/services/common-types.js +10 -0
  69. package/dist/services/fulfillments-service.d.ts +13 -0
  70. package/dist/services/fulfillments-service.js +64 -0
  71. package/dist/services/index.d.ts +1 -0
  72. package/dist/services/index.js +1 -0
  73. package/dist/services/item-details-service.d.ts +2 -0
  74. package/dist/services/item-details-service.js +8 -1
  75. package/dist/services/olo-settings-service.d.ts +14 -8
  76. package/dist/services/olo-settings-service.js +24 -5
  77. package/dist/services/utils.d.ts +17 -0
  78. package/dist/services/utils.js +104 -0
  79. package/dist/types/fulfillments-types.d.ts +33 -0
  80. package/dist/types/fulfillments-types.js +7 -0
  81. package/dist/types/operation.d.ts +57 -0
  82. package/dist/types/operation.js +1 -0
  83. package/dist/utils/fulfillments-utils.d.ts +23 -0
  84. package/dist/utils/fulfillments-utils.js +144 -0
  85. package/package.json +5 -6
@@ -0,0 +1,192 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useService } from '@wix/services-manager-react';
3
+ import { OLOSettingsServiceDefinition } from '../../services/olo-settings-service.js';
4
+ import { FulfillmentsServiceDefinition } from '../../services/fulfillments-service.js';
5
+ /**
6
+ * Core Settings component that provides access to OLO settings data
7
+ * Integrates with OLOSettingsService to expose operation and operation group data
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * <CoreSettings.Root>
12
+ * {({ currentDetails, currentFulfillment, currentLocation, extraData, isLoading, error }) => (
13
+ * isLoading ? (
14
+ * <div>Loading settings...</div>
15
+ * ) : error ? (
16
+ * <div>Error: {error}</div>
17
+ * ) : (
18
+ * <div>
19
+ * <h2>{currentDetails.name}</h2>
20
+ * <p>Accepting Orders: {extraData.acceptingOrders ? 'Yes' : 'No'}</p>
21
+ * <p>Delivery Fee: ${extraData.deliveryFee}</p>
22
+ * </div>
23
+ * )
24
+ * )}
25
+ * </CoreSettings.Root>
26
+ * ```
27
+ */
28
+ export const Root = ({ children }) => {
29
+ const service = useService(OLOSettingsServiceDefinition);
30
+ const fulfillmentsService = useService(FulfillmentsServiceDefinition);
31
+ const operation = service.operation?.get();
32
+ const selectedFulfillment = fulfillmentsService.selectedFulfillment?.get();
33
+ console.log('selectedFulfillment', selectedFulfillment);
34
+ const isLoading = service.isLoading?.get() ?? false;
35
+ const error = service.error?.get();
36
+ // Extract current details from operation group
37
+ // Note: Using safe property access since the exact API structure may vary
38
+ const currentTime = {
39
+ timeSlot: 'TODO', // service.currentTimeSlot?.get(),
40
+ };
41
+ // Extract fulfillment options from operation
42
+ // Note: Using safe property access since the exact API structure may vary
43
+ const currentFulfillment = {
44
+ current: fulfillmentsService.selectedFulfillment?.get() ?? undefined,
45
+ };
46
+ // Extract location data from operation group
47
+ // Note: Using safe property access since the exact API structure may vary
48
+ const currentLocation = {
49
+ name: operation.locationDetails?.name,
50
+ };
51
+ // Extract extra data from operation
52
+ // Note: Using safe property access since the exact API structure may vary
53
+ const extraData = {
54
+ acceptingOrders: operation?.status === 'ACTIVE' && !operation?.paused,
55
+ deliveryFee: operation?.fulfillment?.delivery?.fee?.amount ||
56
+ operation?.deliveryFee,
57
+ minOrderAmount: operation?.orderingRules?.minimumOrderValue?.amount ||
58
+ operation?.minOrderAmount,
59
+ freeDeliveryThreshold: operation?.fulfillment?.delivery?.freeDeliveryThreshold
60
+ ?.amount || operation?.freeDeliveryThreshold,
61
+ taxRate: operation?.pricing?.taxRate || operation?.taxRate,
62
+ serviceCharge: operation?.pricing?.serviceCharge?.amount ||
63
+ operation?.serviceCharge,
64
+ isOnline: operation?.status === 'ACTIVE',
65
+ orderingDisabledReason: operation?.paused
66
+ ? operation?.pauseReason
67
+ : undefined,
68
+ };
69
+ return children({
70
+ currentTime,
71
+ currentFulfillment,
72
+ selectedFulfillment,
73
+ currentLocation,
74
+ extraData,
75
+ isLoading,
76
+ error,
77
+ });
78
+ };
79
+ /**
80
+ * Component that provides access to current store details
81
+ *
82
+ * @example
83
+ * ```tsx
84
+ * <CoreSettings.CurrentTimeSlot>
85
+ * {({ details, hasDetails }) => (
86
+ * hasDetails ? (
87
+ * <div>
88
+ * <h3>{details.timeSlot}</h3>
89
+ * </div>
90
+ * ) : (
91
+ * <div>No store details available</div>
92
+ * )
93
+ * )}
94
+ * </CoreSettings.CurrentTimeSlot>
95
+ * ```
96
+ */
97
+ export const CurrentTimeSlot = ({ children, }) => {
98
+ return (_jsx(Root, { children: ({ selectedFulfillment }) => {
99
+ const hasDetails = Boolean(selectedFulfillment);
100
+ console.log('selectedFulfillment', selectedFulfillment);
101
+ console.log('timeSlot', selectedFulfillment?.startTime.toLocaleString());
102
+ return children({
103
+ timeSlot: selectedFulfillment,
104
+ hasDetails,
105
+ });
106
+ } }));
107
+ };
108
+ /**
109
+ * Component that provides access to current fulfillment options
110
+ *
111
+ * @example
112
+ * ```tsx
113
+ * <CoreSettings.CurrentFulfillment>
114
+ * {({ fulfillment, availableOptions }) => (
115
+ * <div>
116
+ * <h3>Available Options:</h3>
117
+ * {availableOptions.map(option => (
118
+ * <div key={option}>{option}: Available</div>
119
+ * ))}
120
+ * </div>
121
+ * )}
122
+ * </CoreSettings.CurrentFulfillment>
123
+ * ```
124
+ */
125
+ export const CurrentFulfillment = ({ children, }) => {
126
+ return (_jsx(Root, { children: ({ currentFulfillment }) => {
127
+ const availableOptions = [];
128
+ // if (currentFulfillment.pickup?.enabled) availableOptions.push('pickup');
129
+ // if (currentFulfillment.delivery?.enabled) availableOptions.push('delivery');
130
+ const hasFulfillment = availableOptions.length > 0;
131
+ return children({
132
+ fulfillment: currentFulfillment,
133
+ hasFulfillment,
134
+ availableOptions,
135
+ });
136
+ } }));
137
+ };
138
+ /**
139
+ * Component that provides access to current location data
140
+ *
141
+ * @example
142
+ * ```tsx
143
+ * <CoreSettings.CurrentLocation>
144
+ * {({ location, hasCoordinates }) => (
145
+ * <div>
146
+ * <p>{location.address}</p>
147
+ * {hasCoordinates && (
148
+ * <p>Coordinates: {location.latitude}, {location.longitude}</p>
149
+ * )}
150
+ * </div>
151
+ * )}
152
+ * </CoreSettings.CurrentLocation>
153
+ * ```
154
+ */
155
+ export const CurrentLocation = ({ children, }) => {
156
+ return (_jsx(Root, { children: ({ currentLocation }) => {
157
+ console.log('currentLocation', currentLocation);
158
+ const hasLocation = Boolean(currentLocation.name);
159
+ return children({
160
+ location: currentLocation,
161
+ hasLocation,
162
+ });
163
+ } }));
164
+ };
165
+ /**
166
+ * Component that provides access to extra settings data
167
+ *
168
+ * @example
169
+ * ```tsx
170
+ * <CoreSettings.ExtraData>
171
+ * {({ extraData }) => (
172
+ * <div>
173
+ * <p>Accepting Orders: {extraData.acceptingOrders ? 'Yes' : 'No'}</p>
174
+ * <p>Delivery Fee: ${extraData.deliveryFee}</p>
175
+ * <p>Min Order: ${extraData.minOrderAmount}</p>
176
+ * <p>Free Delivery: ${extraData.freeDeliveryThreshold}</p>
177
+ * </div>
178
+ * )}
179
+ * </CoreSettings.ExtraData>
180
+ * ```
181
+ */
182
+ export const ExtraData = ({ children }) => {
183
+ return (_jsx(Root, { children: ({ extraData }) => {
184
+ const hasExtraData = Boolean(extraData.deliveryFee !== undefined ||
185
+ extraData.minOrderAmount !== undefined ||
186
+ extraData.freeDeliveryThreshold !== undefined);
187
+ return children({
188
+ extraData,
189
+ hasExtraData,
190
+ });
191
+ } }));
192
+ };
@@ -1,3 +1,4 @@
1
1
  export * as CoreItemDetails from './ItemDetails.js';
2
2
  export { CoreClickableItem } from './ClickableItem.js';
3
3
  export * as CoreOLO from './OLO.js';
4
+ export * as CoreSettings from './Settings.js';
@@ -1,3 +1,4 @@
1
1
  export * as CoreItemDetails from './ItemDetails.js';
2
2
  export { CoreClickableItem } from './ClickableItem.js';
3
3
  export * as CoreOLO from './OLO.js';
4
+ export * as CoreSettings from './Settings.js';
@@ -1,3 +1,6 @@
1
1
  export * as ItemDetails from './ItemDetails.js';
2
+ export * as ModifierGroup from './ModifierGroup.js';
2
3
  export * as ClickableItem from './ClickableItem.js';
3
4
  export * as OLO from './OLO.js';
5
+ export * as Settings from './Settings.js';
6
+ export * as OLOMenus from './OLOMenus.js';
@@ -1,3 +1,6 @@
1
1
  export * as ItemDetails from './ItemDetails.js';
2
+ export * as ModifierGroup from './ModifierGroup.js';
2
3
  export * as ClickableItem from './ClickableItem.js';
3
4
  export * as OLO from './OLO.js';
5
+ export * as Settings from './Settings.js';
6
+ export * as OLOMenus from './OLOMenus.js';
@@ -1,6 +1,24 @@
1
1
  import * as currentCart from '@wix/auto_sdk_ecom_current-cart';
2
2
  export type LineItem = currentCart.LineItem;
3
3
  export type DescriptionLine = currentCart.DescriptionLine;
4
+ export declare enum RuleType {
5
+ NO_LIMIT = "NO_LIMIT",
6
+ CHOOSE_ONE = "CHOOSE_ONE",
7
+ CHOOSE_X = "CHOOSE_X",
8
+ CHOOSE_AT_LEAST_ONE = "CHOOSE_AT_LEAST_ONE",
9
+ CHOOSE_AT_LEAST_X = "CHOOSE_AT_LEAST_X",
10
+ CHOOSE_UP_TO_X = "CHOOSE_UP_TO_X",
11
+ CHOOSE_BETWEEN_X_AND_Y = "CHOOSE_BETWEEN_X_AND_Y"
12
+ }
13
+ export interface RuleTypeMap {
14
+ [RuleType.NO_LIMIT]?: (modifierGroupName: string) => string;
15
+ [RuleType.CHOOSE_ONE]?: (modifierGroupName: string) => string;
16
+ [RuleType.CHOOSE_X]?: (modifierGroupName: string, x: number) => string;
17
+ [RuleType.CHOOSE_AT_LEAST_ONE]?: (modifierGroupName: string) => string;
18
+ [RuleType.CHOOSE_AT_LEAST_X]?: (modifierGroupName: string, x: number) => string;
19
+ [RuleType.CHOOSE_UP_TO_X]?: (modifierGroupName: string, x: number) => string;
20
+ [RuleType.CHOOSE_BETWEEN_X_AND_Y]?: (modifierGroupName: string, x: number, y: number) => string;
21
+ }
4
22
  export declare enum AvailabilityStatus {
5
23
  AVAILABLE = 0,
6
24
  NOT_AVAILABLE = 1,
@@ -1,3 +1,13 @@
1
+ export var RuleType;
2
+ (function (RuleType) {
3
+ RuleType["NO_LIMIT"] = "NO_LIMIT";
4
+ RuleType["CHOOSE_ONE"] = "CHOOSE_ONE";
5
+ RuleType["CHOOSE_X"] = "CHOOSE_X";
6
+ RuleType["CHOOSE_AT_LEAST_ONE"] = "CHOOSE_AT_LEAST_ONE";
7
+ RuleType["CHOOSE_AT_LEAST_X"] = "CHOOSE_AT_LEAST_X";
8
+ RuleType["CHOOSE_UP_TO_X"] = "CHOOSE_UP_TO_X";
9
+ RuleType["CHOOSE_BETWEEN_X_AND_Y"] = "CHOOSE_BETWEEN_X_AND_Y";
10
+ })(RuleType || (RuleType = {}));
1
11
  export var AvailabilityStatus;
2
12
  (function (AvailabilityStatus) {
3
13
  AvailabilityStatus[AvailabilityStatus["AVAILABLE"] = 0] = "AVAILABLE";
@@ -0,0 +1,13 @@
1
+ import * as operationsSDK from '@wix/auto_sdk_restaurants_operations';
2
+ import { FulfillmentsServiceAPI, FulfillmentsServiceConfig } from '../types/fulfillments-types.js';
3
+ export declare const FulfillmentsServiceDefinition: string & {
4
+ __api: FulfillmentsServiceAPI;
5
+ __config: {};
6
+ isServiceDefinition?: boolean;
7
+ } & FulfillmentsServiceAPI;
8
+ export declare const FulfillmentsService: import("@wix/services-definitions").ServiceFactory<string & {
9
+ __api: FulfillmentsServiceAPI;
10
+ __config: {};
11
+ isServiceDefinition?: boolean;
12
+ } & FulfillmentsServiceAPI, FulfillmentsServiceConfig>;
13
+ export declare const loadFulfillmentsServiceConfig: (operation?: operationsSDK.Operation) => Promise<FulfillmentsServiceConfig>;
@@ -0,0 +1,64 @@
1
+ import { defineService, implementService } from '@wix/services-definitions';
2
+ import { SignalsServiceDefinition } from '@wix/services-definitions/core-services/signals';
3
+ import * as operationsSDK from '@wix/auto_sdk_restaurants_operations';
4
+ import * as fulfillemtMethodsSDK from '@wix/auto_sdk_restaurants_fulfillment-methods';
5
+ import { processFulfillmentTimeSlotByOperationList } from '../utils/fulfillments-utils.js';
6
+ export const FulfillmentsServiceDefinition = defineService('fulfillments');
7
+ export const FulfillmentsService = implementService.withConfig()(FulfillmentsServiceDefinition, ({ getService, config }) => {
8
+ console.log('config', config);
9
+ if (!config.operation) {
10
+ throw new Error('Operation ID is required');
11
+ }
12
+ const signalsService = getService(SignalsServiceDefinition);
13
+ const fulfillmentsMap = new Map(config.fulfillments?.map(processFulfillmentTimeSlotByOperationList) ??
14
+ []);
15
+ const fulfillments = signalsService.signal(
16
+ // @ts-expect-error - operation is not typed
17
+ fulfillmentsMap.get(config.operation?.id ?? '') ?? []);
18
+ const isLoading = signalsService.signal(false);
19
+ const error = signalsService.signal(null);
20
+ const initialSelected = fulfillments.get()?.[0] ?? null;
21
+ const selectedFulfillment = signalsService.signal(initialSelected);
22
+ selectedFulfillment.set(initialSelected);
23
+ const setSelectedFulfillment = (fulfillment) => {
24
+ selectedFulfillment.set(fulfillment);
25
+ };
26
+ if (!config.fulfillments && config.operation) {
27
+ loadFulfillmentsServiceConfig(config.operation).then((config) => {
28
+ const fulfillmentsMap = new Map(config.fulfillments?.map(processFulfillmentTimeSlotByOperationList) ?? []);
29
+ fulfillments.set(
30
+ // @ts-expect-error - operation is not typed
31
+ fulfillmentsMap.get(config.operation?.id ?? '') ?? []);
32
+ const initialSelected = fulfillments.get()?.[0] ?? null;
33
+ selectedFulfillment.set(initialSelected);
34
+ });
35
+ }
36
+ return {
37
+ fulfillments,
38
+ selectedFulfillment,
39
+ isLoading,
40
+ error,
41
+ setSelectedFulfillment,
42
+ };
43
+ });
44
+ export const loadFulfillmentsServiceConfig = async (operation) => {
45
+ const [timeSlots, fulfillments] = await Promise.all([
46
+ operationsSDK.calculateFirstAvailableTimeSlotsPerOperation([
47
+ // @ts-expect-error - operation is not typed
48
+ operation.id,
49
+ ]),
50
+ fulfillemtMethodsSDK
51
+ .queryFulfillmentMethods()
52
+ .in('_id', operation?.fulfillmentIds)
53
+ .find(),
54
+ ]);
55
+ // const fulfillments = await operationsSDK.calculateFirstAvailableTimeSlotsPerOperation([
56
+ // operationId,
57
+ // ]);
58
+ console.log('fulfillments', fulfillments.items);
59
+ // const fulfillmentsMap = new Map(fulfillments.timeSlotsPerOperation?.map(processFulfillmentTimeSlotByOperationList));
60
+ return {
61
+ fulfillments: timeSlots.timeSlotsPerOperation, //fulfillmentsMap.get(operationId) ?? [],
62
+ operation: operation,
63
+ };
64
+ };
@@ -1,3 +1,4 @@
1
1
  export { ItemService, ItemServiceDefinition, loadItemServiceConfig, ItemServiceConfig, } from './item-details-service.js';
2
2
  export { OLOSettingsService, OLOSettingsServiceDefinition, loadOLOSettingsServiceConfig, type OLOSettingsServiceConfig, type OLOSettingsServiceAPI, } from './olo-settings-service.js';
3
3
  export { AvailabilityStatus, AvailabilityStatusMap } from './common-types.js';
4
+ export { FulfillmentsService, FulfillmentsServiceDefinition, loadFulfillmentsServiceConfig, } from './fulfillments-service.js';
@@ -1,3 +1,4 @@
1
1
  export { ItemService, ItemServiceDefinition, loadItemServiceConfig, } from './item-details-service.js';
2
2
  export { OLOSettingsService, OLOSettingsServiceDefinition, loadOLOSettingsServiceConfig, } from './olo-settings-service.js';
3
3
  export { AvailabilityStatus } from './common-types.js';
4
+ export { FulfillmentsService, FulfillmentsServiceDefinition, loadFulfillmentsServiceConfig, } from './fulfillments-service.js';
@@ -23,6 +23,8 @@ export interface ItemServiceAPI {
23
23
  isLoading: Signal<boolean>;
24
24
  /** Reactive signal containing any error message, or null if no error */
25
25
  error: Signal<string | null>;
26
+ /** Reactive signal containing error state for each modifier group */
27
+ modifierGroupError: Signal<Record<string, boolean>>;
26
28
  /** Function to update the quantity of the item */
27
29
  updateQuantity: (quantity: number) => void;
28
30
  /** Function to update the special request of the item */
@@ -58,8 +58,14 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
58
58
  const modifierGroups = config.item?.modifierGroups || [];
59
59
  const initialSelectedModifiers = getModifiersInitState(modifierGroups);
60
60
  const selectedModifiers = signalsService.signal(initialSelectedModifiers);
61
+ const initialModifierGroupError = modifierGroups.reduce((acc, group) => {
62
+ if (group._id) {
63
+ acc[group._id] = false;
64
+ }
65
+ return acc;
66
+ }, {});
67
+ const modifierGroupError = signalsService.signal(initialModifierGroupError);
61
68
  if (config.item) {
62
- console.log('config.item', config.item);
63
69
  lineItem.set({
64
70
  quantity: quantity.get(),
65
71
  catalogReference: {
@@ -150,6 +156,7 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
150
156
  selectedModifiers,
151
157
  availabilityStatus,
152
158
  getSelectedModifiers,
159
+ modifierGroupError,
153
160
  };
154
161
  });
155
162
  /**
@@ -1,18 +1,22 @@
1
- import * as operationGroupsApi from '@wix/auto_sdk_restaurants_operation-groups';
2
- import * as operationsApi from '@wix/auto_sdk_restaurants_operations';
1
+ import { operations as operationsSDK, operationGroups as operationGroupsSDK } from '@wix/restaurants';
3
2
  import { type Signal } from '@wix/services-definitions/core-services/signals';
3
+ import { MenusServiceConfig } from '@wix/restaurants/services';
4
4
  export interface OLOSettingsServiceAPI {
5
- operationGroup: Signal<operationGroupsApi.OperationGroup | undefined>;
6
- operation: Signal<operationsApi.Operation | undefined>;
5
+ operationGroup: Signal<operationGroupsSDK.OperationGroup | undefined>;
6
+ operation: Signal<operationsSDK.Operation | undefined>;
7
7
  selectedItem?: Signal<unknown>;
8
8
  isLoading: Signal<boolean>;
9
9
  error: Signal<string | null>;
10
10
  availabilityDispatchAction?: Signal<(() => void) | undefined>;
11
+ currentFulfillment: Signal<string>;
12
+ currentTimeSlot: Signal<string>;
13
+ filterMenus: (menus: MenusServiceConfig['menus']) => MenusServiceConfig['menus'];
11
14
  }
12
15
  export interface OLOSettingsServiceConfig {
13
- operationGroup?: operationGroupsApi.OperationGroup;
14
- operation?: operationsApi.Operation;
16
+ operationGroup?: operationGroupsSDK.OperationGroup;
17
+ operation?: operationsSDK.Operation;
15
18
  availabilityDispatchAction?: () => void;
19
+ menuIdsByOperation?: string[];
16
20
  }
17
21
  export declare const OLOSettingsServiceDefinition: string & {
18
22
  __api: OLOSettingsServiceAPI;
@@ -25,8 +29,9 @@ export declare const OLOSettingsService: import("@wix/services-definitions").Ser
25
29
  isServiceDefinition?: boolean;
26
30
  } & OLOSettingsServiceAPI, OLOSettingsServiceConfig>;
27
31
  export declare function loadOLOSettingsServiceConfig(): Promise<{
28
- operationGroup: operationGroupsApi.OperationGroup | undefined;
29
- operation: operationsApi.Operation | undefined;
32
+ operationGroup: operationGroupsSDK.OperationGroup | undefined;
33
+ operation: import("../types/operation.js").Operation;
34
+ menuIdsByOperation: (string | null | undefined)[];
30
35
  isLoading?: undefined;
31
36
  error?: undefined;
32
37
  } | {
@@ -34,4 +39,5 @@ export declare function loadOLOSettingsServiceConfig(): Promise<{
34
39
  operation: undefined;
35
40
  isLoading: boolean;
36
41
  error: string;
42
+ menuIdsByOperation?: undefined;
37
43
  }>;
@@ -1,7 +1,7 @@
1
1
  import { defineService, implementService } from '@wix/services-definitions';
2
- import * as operationGroupsApi from '@wix/auto_sdk_restaurants_operation-groups';
3
- import * as operationsApi from '@wix/auto_sdk_restaurants_operations';
2
+ import { operations as operationsSDK, operationGroups as operationGroupsSDK, menuOrderingSettings as menuOrderingSettingsSDK, } from '@wix/restaurants';
4
3
  import { SignalsServiceDefinition, } from '@wix/services-definitions/core-services/signals';
4
+ import { OperationMapper } from '../mappers/operation-mapper.js';
5
5
  export const OLOSettingsServiceDefinition = defineService('oloSettings');
6
6
  export const OLOSettingsService = implementService.withConfig()(OLOSettingsServiceDefinition, ({ getService, config }) => {
7
7
  const signalsService = getService(SignalsServiceDefinition);
@@ -11,6 +11,12 @@ export const OLOSettingsService = implementService.withConfig()(OLOSettingsServi
11
11
  const selectedItem = signalsService.signal(null);
12
12
  const isLoading = signalsService.signal(false);
13
13
  const error = signalsService.signal(null);
14
+ const currentFulfillment = signalsService.signal('Pickup');
15
+ const currentTimeSlot = signalsService.signal('10-14');
16
+ // const isAsap = operation.get()?.orderSchedulingType === OrderSchedulingType.ASAP;
17
+ const filterMenus = (menus) => {
18
+ return menus?.filter((menu) => menu.visible && config.menuIdsByOperation?.includes(menu._id || ''));
19
+ };
14
20
  return {
15
21
  operationGroup,
16
22
  operation,
@@ -18,18 +24,31 @@ export const OLOSettingsService = implementService.withConfig()(OLOSettingsServi
18
24
  error,
19
25
  selectedItem,
20
26
  availabilityDispatchAction,
27
+ currentFulfillment,
28
+ currentTimeSlot,
29
+ filterMenus,
21
30
  };
22
31
  });
23
32
  export async function loadOLOSettingsServiceConfig() {
24
33
  try {
25
34
  // Fetch operation groups and operations in parallel
26
35
  const [operationGroupsResponse, operationsResponse] = await Promise.all([
27
- operationGroupsApi.queryOperationGroups().find(),
28
- operationsApi.queryOperation().find(),
36
+ operationGroupsSDK.queryOperationGroups().find(),
37
+ operationsSDK.queryOperation().find(),
29
38
  ]);
39
+ const [currentOperation] = operationsResponse.items;
40
+ if (!currentOperation) {
41
+ throw new Error('Operation not found');
42
+ }
43
+ const operation = OperationMapper(currentOperation);
44
+ const menuIdsByOperation = await menuOrderingSettingsSDK
45
+ .queryMenuOrderingSettings()
46
+ .in('operationId', operationsResponse.items[0]?._id)
47
+ .find();
30
48
  return {
31
49
  operationGroup: operationGroupsResponse.items[0] || undefined,
32
- operation: operationsResponse.items[0] || undefined,
50
+ operation,
51
+ menuIdsByOperation: menuIdsByOperation.items.map((menu) => menu.menuId),
33
52
  };
34
53
  }
35
54
  catch (error) {
@@ -1,4 +1,10 @@
1
1
  import type { EnhancedModifier, EnhancedModifierGroup } from '@wix/headless-restaurants-menus/services';
2
+ import { RuleType, RuleTypeMap } from './common-types.js';
3
+ interface ruleUtilsArgs {
4
+ required: boolean;
5
+ minSelections: number;
6
+ maxSelections?: number | null;
7
+ }
2
8
  export declare const getModifiersInitState: (modifierGroups: EnhancedModifierGroup[]) => Record<string, string[]>;
3
9
  export declare const isSingleSelectRule: (rule: NonNullable<EnhancedModifierGroup["rule"]>) => boolean | null | undefined;
4
10
  export declare const getFirstPreSelectedModifier: (modifiers: EnhancedModifier[]) => string | null | undefined;
@@ -18,3 +24,14 @@ export declare const convertModifierToFormModifier: (modifier: EnhancedModifier,
18
24
  };
19
25
  preSelected?: boolean;
20
26
  };
27
+ export declare const getModifierGroupRuleType: (modifierGroupRule: EnhancedModifierGroup["rule"]) => RuleType;
28
+ export declare const hasNoLimit: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
29
+ export declare const canChooseOne: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
30
+ export declare const hasToChooseOne: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
31
+ export declare const hasToChooseX: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean | 0 | null | undefined;
32
+ export declare const hasToChooseAtLeastOne: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
33
+ export declare const hasToChooseAtLeastX: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
34
+ export declare const chooseUpToX: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
35
+ export declare const hasToChooseBetweenXAndY: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
36
+ export declare const getRuleTypeMapValue: (ruleTypeMap: RuleTypeMap, ruleType: RuleType, modifierGroupName: string, rule: EnhancedModifierGroup["rule"]) => string | undefined;
37
+ export {};
@@ -1,3 +1,4 @@
1
+ import { RuleType } from './common-types.js';
1
2
  export const getModifiersInitState = (modifierGroups) => {
2
3
  const initialSelectedModifiers = {};
3
4
  modifierGroups.forEach((group) => {
@@ -32,3 +33,106 @@ export const convertModifierToFormModifier = (modifier, index) => {
32
33
  _id: `${modifier._id}~${index}`,
33
34
  };
34
35
  };
36
+ export const getModifierGroupRuleType = (modifierGroupRule) => {
37
+ const required = modifierGroupRule?.required ?? false;
38
+ const minSelections = modifierGroupRule?.minSelections ?? 0;
39
+ const maxSelections = modifierGroupRule?.maxSelections;
40
+ const ruleFields = { required, minSelections, maxSelections };
41
+ if (hasNoLimit(ruleFields)) {
42
+ return RuleType.NO_LIMIT;
43
+ }
44
+ if (hasToChooseOne(ruleFields) || canChooseOne(ruleFields)) {
45
+ return RuleType.CHOOSE_ONE;
46
+ }
47
+ if (hasToChooseX(ruleFields)) {
48
+ return RuleType.CHOOSE_X;
49
+ }
50
+ if (hasToChooseAtLeastOne(ruleFields)) {
51
+ return RuleType.CHOOSE_AT_LEAST_ONE;
52
+ }
53
+ if (hasToChooseAtLeastX(ruleFields)) {
54
+ return RuleType.CHOOSE_AT_LEAST_X;
55
+ }
56
+ if (chooseUpToX(ruleFields)) {
57
+ return RuleType.CHOOSE_UP_TO_X;
58
+ }
59
+ if (hasToChooseBetweenXAndY(ruleFields)) {
60
+ return RuleType.CHOOSE_BETWEEN_X_AND_Y;
61
+ }
62
+ return RuleType.NO_LIMIT;
63
+ };
64
+ const hasNoValue = (variable) => variable === null || variable === undefined;
65
+ export const hasNoLimit = ({ required, minSelections, maxSelections, }) => !required && minSelections < 1 && (maxSelections ? maxSelections < 1 : true);
66
+ export const canChooseOne = ({ required, minSelections, maxSelections, }) => !required &&
67
+ minSelections === 0 &&
68
+ (maxSelections ? maxSelections === 1 : false);
69
+ export const hasToChooseOne = ({ required, minSelections, maxSelections, }) => required &&
70
+ minSelections === 1 &&
71
+ (maxSelections ? maxSelections === 1 : false);
72
+ export const hasToChooseX = ({ required, minSelections, maxSelections, }) => required ? maxSelections && minSelections === maxSelections : false;
73
+ export const hasToChooseAtLeastOne = ({ required, minSelections, maxSelections, }) => required ? minSelections === 1 && hasNoValue(maxSelections) : false;
74
+ export const hasToChooseAtLeastX = ({ required, minSelections, maxSelections, }) => required ? minSelections > 1 && hasNoValue(maxSelections) : false;
75
+ export const chooseUpToX = ({ required, minSelections, maxSelections, }) => !required &&
76
+ minSelections === 0 &&
77
+ (maxSelections ? maxSelections > 1 : false);
78
+ export const hasToChooseBetweenXAndY = ({ required, minSelections, maxSelections, }) => required
79
+ ? maxSelections
80
+ ? minSelections > 0 && maxSelections > minSelections
81
+ : false
82
+ : false;
83
+ export const getRuleTypeMapValue = (ruleTypeMap, ruleType, modifierGroupName, rule) => {
84
+ const minSelections = rule?.minSelections ?? 0;
85
+ const maxSelections = rule?.maxSelections;
86
+ switch (ruleType) {
87
+ case RuleType.NO_LIMIT: {
88
+ const callback = ruleTypeMap[RuleType.NO_LIMIT];
89
+ if (callback) {
90
+ return callback(modifierGroupName);
91
+ }
92
+ break;
93
+ }
94
+ case RuleType.CHOOSE_ONE: {
95
+ const callback = ruleTypeMap[RuleType.CHOOSE_ONE];
96
+ if (callback) {
97
+ return callback(modifierGroupName);
98
+ }
99
+ break;
100
+ }
101
+ case RuleType.CHOOSE_X: {
102
+ const callback = ruleTypeMap[RuleType.CHOOSE_X];
103
+ if (callback) {
104
+ return callback(modifierGroupName, minSelections);
105
+ }
106
+ break;
107
+ }
108
+ case RuleType.CHOOSE_AT_LEAST_ONE: {
109
+ const callback = ruleTypeMap[RuleType.CHOOSE_AT_LEAST_ONE];
110
+ if (callback) {
111
+ return callback(modifierGroupName);
112
+ }
113
+ break;
114
+ }
115
+ case RuleType.CHOOSE_AT_LEAST_X: {
116
+ const callback = ruleTypeMap[RuleType.CHOOSE_AT_LEAST_X];
117
+ if (callback) {
118
+ return callback(modifierGroupName, minSelections);
119
+ }
120
+ break;
121
+ }
122
+ case RuleType.CHOOSE_UP_TO_X: {
123
+ const callback = ruleTypeMap[RuleType.CHOOSE_UP_TO_X];
124
+ if (callback && maxSelections) {
125
+ return callback(modifierGroupName, maxSelections);
126
+ }
127
+ break;
128
+ }
129
+ case RuleType.CHOOSE_BETWEEN_X_AND_Y: {
130
+ const callback = ruleTypeMap[RuleType.CHOOSE_BETWEEN_X_AND_Y];
131
+ if (callback && maxSelections) {
132
+ return callback(modifierGroupName, minSelections, maxSelections);
133
+ }
134
+ break;
135
+ }
136
+ }
137
+ return undefined;
138
+ };
@@ -0,0 +1,33 @@
1
+ import * as operationsSDK from '@wix/auto_sdk_restaurants_operations';
2
+ import { Signal } from '@wix/services-definitions/core-services/signals';
3
+ export declare enum DispatchType {
4
+ /** Pickup fulfillment */
5
+ PICKUP = "PICKUP",
6
+ /** Delivery fulfillment */
7
+ DELIVERY = "DELIVERY"
8
+ }
9
+ export type TimeSlot = {
10
+ id: string;
11
+ startTime: Date;
12
+ endTime: Date;
13
+ dispatchType: DispatchType;
14
+ startsNow?: boolean;
15
+ fulfillmentDetails: operationsSDK.FulfillmentDetails;
16
+ };
17
+ export interface Fulfillment {
18
+ id: string;
19
+ name: string;
20
+ type: string;
21
+ isAvailable: boolean;
22
+ }
23
+ export interface FulfillmentsServiceAPI {
24
+ fulfillments: Signal<TimeSlot[]>;
25
+ selectedFulfillment: Signal<TimeSlot | null>;
26
+ isLoading: Signal<boolean>;
27
+ error: Signal<string | null>;
28
+ setSelectedFulfillment: (fulfillment: TimeSlot) => void;
29
+ }
30
+ export interface FulfillmentsServiceConfig {
31
+ fulfillments?: operationsSDK.TimeSlotForOperation[];
32
+ operation?: operationsSDK.Operation;
33
+ }