@open-tender/utils 0.0.69 → 0.1.0

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 (91) hide show
  1. package/dist/cjs/hooks/menu/useBuilder.d.ts +8 -7
  2. package/dist/cjs/hooks/menu/useBuilder.js +92 -86
  3. package/dist/cjs/hooks/menu/useOrderItem.d.ts +33 -43
  4. package/dist/cjs/hooks/menu/useOrderItem.js +21 -22
  5. package/dist/cjs/hooks/useAddressForm.js +1 -1
  6. package/dist/cjs/hooks/useAllergenForm.js +1 -1
  7. package/dist/cjs/hooks/useCartGuestForm.js +2 -2
  8. package/dist/cjs/hooks/useCheckoutLoginForm.js +1 -1
  9. package/dist/cjs/hooks/useCreditCard.js +2 -2
  10. package/dist/cjs/hooks/useCreditCardForm.js +3 -3
  11. package/dist/cjs/hooks/useCurbside.js +1 -1
  12. package/dist/cjs/hooks/useDineInForm.js +1 -1
  13. package/dist/cjs/hooks/useDonationForm.js +5 -5
  14. package/dist/cjs/hooks/useGiftCardAssignForm.js +1 -1
  15. package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +1 -1
  16. package/dist/cjs/hooks/useGiftCardForm.js +6 -4
  17. package/dist/cjs/hooks/useGiftCardsForm.js +22 -9
  18. package/dist/cjs/hooks/useGuestForm.js +1 -1
  19. package/dist/cjs/hooks/useLevelUpForm.js +1 -1
  20. package/dist/cjs/hooks/useOrderFulfillmentForm.js +3 -3
  21. package/dist/cjs/hooks/useOrderRating.js +1 -1
  22. package/dist/cjs/hooks/useOrderRatingForm.js +1 -1
  23. package/dist/cjs/hooks/useProfileForm.js +3 -3
  24. package/dist/cjs/hooks/useResetPasswordForm.js +2 -2
  25. package/dist/cjs/hooks/useSendResetForm.js +4 -2
  26. package/dist/cjs/hooks/useSignUpForm.js +14 -10
  27. package/dist/cjs/hooks/useSignUpGuestForm.js +3 -3
  28. package/dist/cjs/hooks/useSigninForm.js +1 -1
  29. package/dist/cjs/utils/cart.d.ts +97 -453
  30. package/dist/cjs/utils/cart.js +288 -361
  31. package/dist/cjs/utils/customer.js +1 -1
  32. package/dist/cjs/utils/errors.js +4 -2
  33. package/dist/cjs/utils/favorites.d.ts +3 -3
  34. package/dist/cjs/utils/favorites.js +11 -4
  35. package/dist/cjs/utils/helpers.d.ts +8 -3
  36. package/dist/cjs/utils/helpers.js +31 -3
  37. package/dist/cjs/utils/index.d.ts +1 -0
  38. package/dist/cjs/utils/index.js +1 -0
  39. package/dist/cjs/utils/maps.js +1 -1
  40. package/dist/cjs/utils/orders.d.ts +3 -3
  41. package/dist/cjs/utils/refunds.d.ts +4 -4
  42. package/dist/cjs/utils/revenueCenters.d.ts +11 -0
  43. package/dist/cjs/utils/revenueCenters.js +125 -0
  44. package/dist/cjs/utils/rewards.js +5 -5
  45. package/dist/cjs/utils/theme.js +7 -7
  46. package/dist/esm/hooks/menu/useBuilder.d.ts +8 -7
  47. package/dist/esm/hooks/menu/useBuilder.js +92 -86
  48. package/dist/esm/hooks/menu/useOrderItem.d.ts +33 -43
  49. package/dist/esm/hooks/menu/useOrderItem.js +22 -23
  50. package/dist/esm/hooks/useAddressForm.js +1 -1
  51. package/dist/esm/hooks/useAllergenForm.js +1 -1
  52. package/dist/esm/hooks/useCartGuestForm.js +2 -2
  53. package/dist/esm/hooks/useCheckoutLoginForm.js +1 -1
  54. package/dist/esm/hooks/useCreditCard.js +3 -3
  55. package/dist/esm/hooks/useCreditCardForm.js +3 -3
  56. package/dist/esm/hooks/useCurbside.js +1 -1
  57. package/dist/esm/hooks/useDineInForm.js +1 -1
  58. package/dist/esm/hooks/useDonationForm.js +5 -5
  59. package/dist/esm/hooks/useGiftCardAssignForm.js +1 -1
  60. package/dist/esm/hooks/useGiftCardAssignOtherForm.js +1 -1
  61. package/dist/esm/hooks/useGiftCardForm.js +6 -4
  62. package/dist/esm/hooks/useGiftCardsForm.js +22 -9
  63. package/dist/esm/hooks/useGuestForm.js +1 -1
  64. package/dist/esm/hooks/useLevelUpForm.js +1 -1
  65. package/dist/esm/hooks/useOrderFulfillmentForm.js +3 -3
  66. package/dist/esm/hooks/useOrderRating.js +1 -1
  67. package/dist/esm/hooks/useOrderRatingForm.js +1 -1
  68. package/dist/esm/hooks/useProfileForm.js +3 -3
  69. package/dist/esm/hooks/useResetPasswordForm.js +2 -2
  70. package/dist/esm/hooks/useSendResetForm.js +4 -2
  71. package/dist/esm/hooks/useSignUpForm.js +14 -10
  72. package/dist/esm/hooks/useSignUpGuestForm.js +3 -3
  73. package/dist/esm/hooks/useSigninForm.js +1 -1
  74. package/dist/esm/utils/cart.d.ts +97 -453
  75. package/dist/esm/utils/cart.js +276 -339
  76. package/dist/esm/utils/customer.js +1 -1
  77. package/dist/esm/utils/errors.js +4 -2
  78. package/dist/esm/utils/favorites.d.ts +3 -3
  79. package/dist/esm/utils/favorites.js +11 -4
  80. package/dist/esm/utils/helpers.d.ts +8 -3
  81. package/dist/esm/utils/helpers.js +25 -2
  82. package/dist/esm/utils/index.d.ts +1 -0
  83. package/dist/esm/utils/index.js +1 -0
  84. package/dist/esm/utils/maps.js +1 -1
  85. package/dist/esm/utils/orders.d.ts +3 -3
  86. package/dist/esm/utils/refunds.d.ts +4 -4
  87. package/dist/esm/utils/revenueCenters.d.ts +11 -0
  88. package/dist/esm/utils/revenueCenters.js +115 -0
  89. package/dist/esm/utils/rewards.js +1 -1
  90. package/dist/esm/utils/theme.js +7 -7
  91. package/package.json +2 -4
@@ -1,38 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calcNutrition = exports.makeUpsellItems = exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.calcCartCounts = exports.makeFullAddress = exports.makeOrderAddress = exports.makeFavoritesLookup = exports.makeUniqueDisplayItems = exports.makeDisplayItems = exports.makeDisplayItem = exports.makeDisplayItemGroups = exports.makeCartItemSignature = exports.makeItemSignature = exports.makeItemImageUrl = exports.combineCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.makeOrderItem = exports.calcPrices = exports.makeRevenueCenterMsg = exports.makeNotAcceptingOrdersMsg = exports.makeOrderTypeName = exports.makeServiceTypeName = exports.makeOrderTypeFromParam = exports.convertStringToArray = exports.makeModifierNames = exports.getItemOptions = exports.formatDollars = exports.formatQuantity = exports.addCommas = exports.makeDisplayPrice = exports.displayPrice = void 0;
4
- const constants_1 = require("./constants");
5
- const datetimes_1 = require("./datetimes");
3
+ exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.makeCartItemSignature = exports.makeItemSignature = exports.makeFavoritesLookup = exports.makeUniqueDisplayItems = exports.makeDisplayItems = exports.makeDisplayItem = exports.makeDisplayItemGroups = exports.makeItemImageUrl = exports.combineCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.calcCartCounts = exports.makeOrderItem = exports.checkSoldOut = exports.calcPrices = exports.calcNutrition = exports.makeUpsellItems = exports.makeModifierGroups = exports.hasGroupsBelowMin = exports.makeModifierNames = exports.getItemOptions = void 0;
6
4
  const helpers_1 = require("./helpers");
7
- const displayPrice = (price) => {
8
- return parseFloat(price).toFixed(2);
9
- };
10
- exports.displayPrice = displayPrice;
11
- const makeDisplayPrice = (item) => {
12
- const sizeGroup = item.option_groups && item.option_groups.find(i => i.is_size);
13
- if (sizeGroup) {
14
- const prices = sizeGroup.option_items.map(i => `$${(0, exports.displayPrice)(i.price)}`);
15
- return prices.join(' / ');
16
- }
17
- const { totalPrice } = (0, exports.makeOrderItem)(item);
18
- return totalPrice > 0 ? `$${(0, exports.displayPrice)(`${totalPrice}`)}` : null;
19
- };
20
- exports.makeDisplayPrice = makeDisplayPrice;
21
- const addCommas = (x, d) => {
22
- return x.toFixed(d).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
23
- };
24
- exports.addCommas = addCommas;
25
- const formatQuantity = (n) => {
26
- return (0, exports.addCommas)(parseFloat(n), 0);
27
- };
28
- exports.formatQuantity = formatQuantity;
29
- const formatDollars = (str, space = '', decimals = 2) => {
30
- const floatPrice = parseFloat(str);
31
- return floatPrice < 0
32
- ? `($${(0, exports.addCommas)(Math.abs(floatPrice), decimals)})`
33
- : `$${(0, exports.addCommas)(floatPrice, decimals)}${space}`;
34
- };
35
- exports.formatDollars = formatDollars;
5
+ // TODO: refactor for nested mods
36
6
  const getItemOptions = (item) => {
37
7
  if (!item.groups || !item.groups.length)
38
8
  return [];
@@ -42,281 +12,289 @@ const getItemOptions = (item) => {
42
12
  return options;
43
13
  };
44
14
  exports.getItemOptions = getItemOptions;
15
+ // TODO: refactor for nested mods
45
16
  const makeModifierNames = (item) => {
46
17
  var _a;
47
18
  return (_a = (0, exports.getItemOptions)(item)) === null || _a === void 0 ? void 0 : _a.map(option => option.name).join(', ');
48
19
  };
49
20
  exports.makeModifierNames = makeModifierNames;
50
- const convertStringToArray = (str) => {
51
- return str
52
- ? str
53
- .split(',')
54
- .map(i => i.trim())
55
- .filter(i => i.length)
56
- : [];
57
- };
58
- exports.convertStringToArray = convertStringToArray;
59
- const makeOrderTypeFromParam = (param) => {
60
- switch (param) {
61
- case 'outpost':
62
- return ['OLO', 'PICKUP', true];
63
- case 'pickup':
64
- return ['OLO', 'PICKUP'];
65
- case 'delivery':
66
- return ['OLO', 'DELIVERY'];
67
- case 'catering':
68
- return ['CATERING', 'DELIVERY'];
69
- case 'merch':
70
- return ['MERCH', 'DELIVERY'];
71
- default:
72
- return null;
73
- }
21
+ const hasGroupsBelowMin = (option, groups) => {
22
+ if (!groups || !groups.length)
23
+ return false;
24
+ if (option && option.quantity === 0)
25
+ return false;
26
+ const childGroupsBelow = groups.filter(g => {
27
+ const optionsBelowMin = g.options.filter(o => (0, exports.hasGroupsBelowMin)(o, o.groups));
28
+ return optionsBelowMin.length > 0;
29
+ });
30
+ if (childGroupsBelow.length > 0)
31
+ return true;
32
+ return groups.filter(g => ((g === null || g === void 0 ? void 0 : g.quantity) || 0) < g.min).length > 0;
33
+ };
34
+ exports.hasGroupsBelowMin = hasGroupsBelowMin;
35
+ const makeModifierGroups = (groups) => {
36
+ if (!groups || !groups.length)
37
+ return [[], []];
38
+ const otherGroups = groups.filter(g => !g.isSize);
39
+ if (otherGroups.length)
40
+ return [groups, []];
41
+ const sizeGroup = groups.find(g => g.isSize);
42
+ if (!sizeGroup)
43
+ return [[], []];
44
+ const sizeGroupNested = sizeGroup.options.filter(o => o.groups && o.groups.length);
45
+ if (!sizeGroupNested || !sizeGroupNested.length)
46
+ return [[], []];
47
+ const selectedOption = sizeGroup.options.find(o => o.quantity > 0);
48
+ return selectedOption
49
+ ? [selectedOption.groups, [[sizeGroup.id, selectedOption.id]]]
50
+ : [[], []];
51
+ };
52
+ exports.makeModifierGroups = makeModifierGroups;
53
+ const makeUpsellItems = (itemIds, itemLookup) => {
54
+ return itemIds
55
+ .map(id => itemLookup[id])
56
+ .filter(i => i)
57
+ .map(i => (0, exports.makeOrderItem)(i))
58
+ .filter(i => !i.isSoldOut)
59
+ .filter(i => {
60
+ const belowMin = i.groups.filter(g => !g.isSize && (g.quantity || 0) < g.min);
61
+ return belowMin.length === 0;
62
+ });
74
63
  };
75
- exports.makeOrderTypeFromParam = makeOrderTypeFromParam;
76
- const makeServiceTypeName = (serviceType, isCatering, isOutpost, outpostName) => {
77
- let serviceTypeName = constants_1.serviceTypeNamesMap[serviceType];
78
- if (isCatering) {
79
- serviceTypeName = `Catering ${serviceTypeName}`;
80
- }
81
- else if (isOutpost) {
82
- serviceTypeName = `${outpostName || 'Outpost'} ${serviceTypeName}`;
83
- }
84
- return serviceTypeName;
85
- };
86
- exports.makeServiceTypeName = makeServiceTypeName;
87
- const makeOrderTypeName = (orderType, serviceType) => {
88
- return orderType === 'OLO'
89
- ? constants_1.serviceTypeNamesMap[serviceType]
90
- : (0, helpers_1.capitalize)(orderType);
91
- };
92
- exports.makeOrderTypeName = makeOrderTypeName;
93
- const makeOrderMsg = (tz, serviceType, requestedAt, firstTime, orderTime, waitTime) => {
94
- var _a, _b;
95
- if (!firstTime && !orderTime)
96
- return null;
97
- let readableDate;
98
- if (firstTime) {
99
- const seconds = firstTime.utc ? (0, datetimes_1.isoToDate)(firstTime.utc).getSeconds() : 0;
100
- const estimate = requestedAt !== 'asap' && seconds ? 'at about' : 'at';
101
- readableDate =
102
- requestedAt === 'asap' && firstTime.has_asap
103
- ? `in about ${waitTime} minutes`
104
- : (0, datetimes_1.makeReadableDateStrFromIso)(firstTime.utc, tz, true)
105
- .replace('Today', 'today')
106
- .replace('Tomorrow', 'TOMORROW')
107
- .replace('@', estimate);
108
- }
109
- else {
110
- const orderTimes = (0, datetimes_1.makeOrderTimes)([orderTime], tz);
111
- const { start_time, end_time } = orderTimes[0];
112
- const startTime = (0, datetimes_1.time24ToDate)(start_time);
113
- const startTimeStr = (_a = (0, datetimes_1.formatDateStr)(startTime.toISOString(), 'h:mma')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
114
- const endTime = (0, datetimes_1.time24ToDate)(end_time);
115
- const endTimeStr = (_b = (0, datetimes_1.formatDateStr)(endTime.toISOString(), 'h:mma')) === null || _b === void 0 ? void 0 : _b.toLowerCase();
116
- const todayWeekday = (0, datetimes_1.makeWeekday)();
117
- const weekday = orderTimes[0].weekday === todayWeekday
118
- ? ''
119
- : `${(0, helpers_1.capitalize)(orderTimes[0].weekday)}, ${(0, datetimes_1.fmtDate)(orderTimes[0].date, 'MMMM d')} @ `;
120
- readableDate =
121
- startTimeStr === endTimeStr
122
- ? `${weekday}${startTimeStr}`
123
- : `${weekday}${startTimeStr} to ${endTimeStr}`;
124
- }
125
- const serviceTypeName = constants_1.serviceTypeNamesMap[serviceType];
126
- const orderMsg = `The first available ${serviceTypeName === null || serviceTypeName === void 0 ? void 0 : serviceTypeName.toLowerCase()} time is ${readableDate}`;
127
- return orderMsg;
128
- };
129
- const makeNotAcceptingOrdersMsg = (serviceType) => {
130
- const serviceTypeName = constants_1.serviceTypeNamesMap[serviceType];
131
- if (!serviceTypeName) {
132
- return 'This location is not currently accepting orders.';
133
- }
134
- return `This location is not currently accepting ${serviceTypeName.toLowerCase()} orders. Please try switching to a different order type.`;
64
+ exports.makeUpsellItems = makeUpsellItems;
65
+ const nutritionKeys = [
66
+ 'calories',
67
+ 'cholesterol',
68
+ 'dietary_fiber',
69
+ 'protein',
70
+ 'saturated_fat',
71
+ 'sodium',
72
+ 'sugars',
73
+ 'total_carbs',
74
+ 'total_fat',
75
+ 'trans_fat'
76
+ ];
77
+ const calcNutrition = (item) => {
78
+ const { nutritionalInfo, groups } = item;
79
+ let nutrition = (nutritionalInfo ? Object.assign({}, nutritionalInfo) : {});
80
+ const options = groups.reduce((arr, g) => {
81
+ return [...arr, ...g.options.filter(o => o.quantity > 0)];
82
+ }, []);
83
+ options.forEach(option => {
84
+ const optionNutrition = (0, exports.calcNutrition)(option);
85
+ nutritionKeys.forEach(key => {
86
+ const optionPer = optionNutrition ? optionNutrition[key] || 0 : 0;
87
+ const optionVal = optionPer * option.quantity;
88
+ const itemVal = nutrition[key] || 0;
89
+ nutrition = Object.assign(Object.assign({}, nutrition), { [key]: itemVal + optionVal });
90
+ });
91
+ });
92
+ return nutrition;
135
93
  };
136
- exports.makeNotAcceptingOrdersMsg = makeNotAcceptingOrdersMsg;
137
- const makeRevenueCenterMsg = (revenueCenter, serviceType, requestedAt, statusMessages) => {
138
- var _a;
139
- const settings = revenueCenter.settings || revenueCenter;
140
- const { first_times, order_times, wait_times } = settings;
141
- const tz = datetimes_1.timezoneMap[(_a = revenueCenter === null || revenueCenter === void 0 ? void 0 : revenueCenter.timezone) !== null && _a !== void 0 ? _a : 'US/Central'];
142
- const st = serviceType === 'WALKIN' ? 'PICKUP' : serviceType;
143
- const firstTime = first_times ? first_times[st] : null;
144
- const orderTime = order_times ? order_times[st] : null;
145
- const waitTime = wait_times ? wait_times[st] : null;
146
- const tempClosed = revenueCenter.status === 'CLOSED_TEMPORARILY';
147
- const statusMsg = !tempClosed ? statusMessages[revenueCenter.status] : null;
148
- const orderMsg = !statusMsg && (firstTime || (orderTime && orderTime.length))
149
- ? makeOrderMsg(tz, serviceType, requestedAt, firstTime, orderTime ? orderTime[0] : null, waitTime !== null && waitTime !== void 0 ? waitTime : 0)
94
+ exports.calcNutrition = calcNutrition;
95
+ const calcPrices = (item) => {
96
+ const groups = item.groups.map(g => {
97
+ let groupQuantity = 0;
98
+ const optionsWithPrices = g.options.map((o, index) => {
99
+ return Object.assign(Object.assign({}, (0, exports.calcPrices)(o)), { index });
100
+ });
101
+ const sortedOptions = optionsWithPrices.sort((a, b) => {
102
+ const pricePerA = a.totalPrice && a.quantity ? a.totalPrice / a.quantity : 0;
103
+ const pricePerB = b.totalPrice && b.quantity ? b.totalPrice / b.quantity : 0;
104
+ return pricePerA - pricePerB;
105
+ });
106
+ const pricedOptions = sortedOptions.map(o => {
107
+ const pricePer = o.totalPrice && o.quantity ? o.totalPrice / o.quantity : 0;
108
+ const pointsPer = o.totalPoints && o.quantity ? o.totalPoints / o.quantity : 0;
109
+ const includedRemaining = Math.max(g.included - groupQuantity, 0);
110
+ const priceQuantity = Math.max(o.quantity - includedRemaining, 0);
111
+ const option = Object.assign(Object.assign({}, o), { totalPrice: priceQuantity * pricePer, totalPoints: priceQuantity * pointsPer, totalCals: o.totalCals || 0 });
112
+ groupQuantity += o.quantity || 0;
113
+ return option;
114
+ });
115
+ const options = pricedOptions.sort((a, b) => a.index - b.index);
116
+ return Object.assign(Object.assign({}, g), { quantity: groupQuantity, options });
117
+ });
118
+ const optionsPrice = groups.reduce((t, g) => {
119
+ return t + g.options.reduce((ot, o) => ot + o.totalPrice, 0.0);
120
+ }, 0.0);
121
+ const totalPrice = item.quantity * (item.price + optionsPrice);
122
+ const optionsPoints = groups.reduce((t, g) => {
123
+ return t + g.options.reduce((ot, o) => ot + o.totalPoints, 0);
124
+ }, 0.0);
125
+ const totalPoints = item.points
126
+ ? item.quantity * (item.points + optionsPoints)
150
127
  : null;
151
- let message = orderMsg ||
152
- (statusMsg ? statusMsg.subtitle : (0, exports.makeNotAcceptingOrdersMsg)(serviceType));
153
- let color = orderMsg ? 'success' : 'alert';
154
- if (tempClosed) {
155
- color = 'alert';
156
- message = message.charAt(0).toLowerCase() + message.substring(1);
157
- message = `This location is temporarily closed for technical or operational reasons. Please try back later today, otherwise ${message} if you want to place an order now.`;
158
- }
159
- return { message, color };
128
+ const optionsCals = groups.reduce((t, g) => {
129
+ return t + g.options.reduce((ot, o) => ot + o.totalCals, 0);
130
+ }, 0.0);
131
+ const totalCals = item.cals || item.cals === 0
132
+ ? item.quantity * (item.cals + optionsCals)
133
+ : null;
134
+ return Object.assign(Object.assign({}, item), { groups, totalPrice, totalPoints, totalCals });
135
+ };
136
+ exports.calcPrices = calcPrices;
137
+ const checkSoldOut = (id, suspendUntil, soldOut = []) => {
138
+ if (soldOut.includes(id))
139
+ return true;
140
+ return suspendUntil ? suspendUntil > Date.now() / 1000 : false;
160
141
  };
161
- exports.makeRevenueCenterMsg = makeRevenueCenterMsg;
142
+ exports.checkSoldOut = checkSoldOut;
162
143
  const makeOrderItemGroups = (optionGroups, isEdit, soldOut = []) => {
163
144
  if (!optionGroups)
164
145
  return [];
165
146
  const groups = optionGroups.map(g => {
166
147
  const options = g.option_items.map(o => {
167
- const isSoldOut = soldOut.includes(o.id);
148
+ const isSoldOut = (0, exports.checkSoldOut)(o.id, o.suspend_until, soldOut);
168
149
  const quantity = isSoldOut
169
150
  ? 0
170
151
  : o.opt_is_default && !isEdit
171
152
  ? o.min_quantity || 1
172
153
  : 0;
173
154
  const cals = o.nutritional_info
174
- ? o.nutritional_info.calories
155
+ ? parseInt(o.nutritional_info.calories.toString())
175
156
  : null;
157
+ const groups = makeOrderItemGroups(o.option_groups, isEdit, soldOut);
176
158
  const option = {
177
- id: o.id,
178
- name: o.name,
179
- shortName: o.short_name,
159
+ allergens: (0, helpers_1.convertStringToArray)(o.allergens),
160
+ cals: cals,
180
161
  description: o.description,
162
+ groups: groups,
163
+ id: o.id,
181
164
  imageUrl: o.small_image_url,
182
- allergens: (0, exports.convertStringToArray)(o.allergens),
183
- tags: (0, exports.convertStringToArray)(o.tags),
165
+ increment: o.increment,
184
166
  ingredients: o.ingredients,
185
- nutritionalInfo: o.nutritional_info,
186
- cals: isNaN(cals !== null && cals !== void 0 ? cals : 0) ? null : cals,
187
- price: parseFloat(o.price),
188
- quantity: quantity,
189
167
  isDefault: o.opt_is_default,
190
- increment: o.increment,
168
+ isSoldOut: isSoldOut,
191
169
  max: isSoldOut ? 0 : o.max_quantity,
192
170
  min: o.min_quantity,
193
- isSoldOut: isSoldOut,
194
- points: o.points || 0
171
+ name: o.name,
172
+ nutritionalInfo: o.nutritional_info,
173
+ points: o.points || 0,
174
+ price: parseFloat(o.price),
175
+ quantity: quantity,
176
+ shortDescription: o.short_description,
177
+ shortName: o.short_name,
178
+ slug: o.slug,
179
+ tags: (0, helpers_1.convertStringToArray)(o.tags),
180
+ totalCals: null,
181
+ totalPoints: null,
182
+ totalPrice: null
195
183
  };
196
184
  return option;
197
185
  });
198
186
  const group = {
199
- id: g.id,
200
- name: g.name,
201
187
  description: g.description,
188
+ id: g.id,
202
189
  imageUrl: g.small_image_url,
203
190
  included: g.included_options,
191
+ isPizza: !!g.is_pizza,
192
+ isSize: !!g.is_size,
204
193
  max: g.max_options,
205
194
  min: g.min_options,
206
- isSize: !!g.is_size,
195
+ name: g.name,
207
196
  options: options
208
197
  };
209
198
  return group;
210
199
  });
211
200
  return groups;
212
201
  };
213
- const calcPrices = (item) => {
214
- var _a, _b, _c, _d, _e;
215
- const groups = (_a = item.groups) === null || _a === void 0 ? void 0 : _a.map(g => {
216
- var _a;
217
- let groupQuantity = 0;
218
- const options = (_a = g === null || g === void 0 ? void 0 : g.options) === null || _a === void 0 ? void 0 : _a.map(o => {
219
- var _a, _b, _c, _d, _e;
220
- const includedRemaining = Math.max(((_a = g.included) !== null && _a !== void 0 ? _a : 0) - groupQuantity, 0);
221
- const priceQuantity = Math.max(((_b = o.quantity) !== null && _b !== void 0 ? _b : 0) - includedRemaining, 0);
222
- const option = Object.assign(Object.assign({}, o), { totalPrice: priceQuantity * ((_c = o.price) !== null && _c !== void 0 ? _c : 0), totalPoints: priceQuantity * ((_d = o.points) !== null && _d !== void 0 ? _d : 0), totalCals: o.cals ? ((_e = o.quantity) !== null && _e !== void 0 ? _e : 0) * o.cals : 0 });
223
- groupQuantity += o.quantity || 0;
224
- return option;
225
- });
226
- return Object.assign(Object.assign({}, g), { quantity: groupQuantity, options });
227
- });
228
- const optionsPrice = groups === null || groups === void 0 ? void 0 : groups.reduce((t, g) => {
229
- var _a, _b;
230
- return t + ((_b = (_a = g.options) === null || _a === void 0 ? void 0 : _a.reduce((ot, o) => ot + o.totalPrice, 0.0)) !== null && _b !== void 0 ? _b : 0);
231
- }, 0.0);
232
- const totalPrice = ((_b = item.quantity) !== null && _b !== void 0 ? _b : 0) * (((_c = item.price) !== null && _c !== void 0 ? _c : 0) + (optionsPrice !== null && optionsPrice !== void 0 ? optionsPrice : 0));
233
- const optionsPoints = groups === null || groups === void 0 ? void 0 : groups.reduce((t, g) => {
234
- var _a, _b;
235
- return t + ((_b = (_a = g.options) === null || _a === void 0 ? void 0 : _a.reduce((ot, o) => ot + o.totalPoints, 0)) !== null && _b !== void 0 ? _b : 0);
236
- }, 0.0);
237
- const totalPoints = item.points
238
- ? ((_d = item.quantity) !== null && _d !== void 0 ? _d : 0) * (item.points + (optionsPoints !== null && optionsPoints !== void 0 ? optionsPoints : 0))
239
- : null;
240
- const optionsCals = groups === null || groups === void 0 ? void 0 : groups.reduce((t, g) => {
241
- var _a, _b;
242
- return t + ((_b = (_a = g.options) === null || _a === void 0 ? void 0 : _a.reduce((ot, o) => ot + o.totalCals, 0)) !== null && _b !== void 0 ? _b : 0);
243
- }, 0.0);
244
- const totalCals = item.cals || item.cals === 0
245
- ? ((_e = item.quantity) !== null && _e !== void 0 ? _e : 0) * (item.cals + (optionsCals !== null && optionsCals !== void 0 ? optionsCals : 0))
246
- : null;
247
- return Object.assign(Object.assign({}, item), { groups, totalPrice, totalPoints, totalCals });
248
- };
249
- exports.calcPrices = calcPrices;
250
202
  const makeOrderItem = (item, isEdit, soldOut = [], simpleItem, hasPoints = false) => {
251
203
  const groups = makeOrderItemGroups(item.option_groups, isEdit, soldOut);
252
204
  const cals = item.nutritional_info ? item.nutritional_info.calories : null;
205
+ const isSoldOut = (0, exports.checkSoldOut)(item.id, item.suspend_until, soldOut);
253
206
  const orderItem = {
254
- id: item.id,
255
- name: item.name,
256
- shortName: item.short_name,
257
- category: item.category_name,
207
+ allergens: (0, helpers_1.convertStringToArray)(item.allergens),
208
+ cals: cals,
209
+ cartGuestId: simpleItem ? simpleItem.cart_guest_id || null : null,
210
+ customerId: simpleItem ? simpleItem.customer_id || null : null,
258
211
  description: item.description,
259
- imageUrl: item.large_image_url,
260
- slug: item.slug,
261
- allergens: (0, exports.convertStringToArray)(Array.from(item.allergens).join()),
262
- tags: (0, exports.convertStringToArray)(Array.from(item.tags).join()),
263
- ingredients: item.ingredients,
264
- nutritionalInfo: item.nutritional_info,
265
- cals: isNaN(cals !== null && cals !== void 0 ? cals : 0) ? null : cals,
266
212
  groups: groups,
267
- quantity: item.min_quantity || 1 * item.increment,
268
- price: parseFloat(item.price),
213
+ id: item.id,
214
+ imageUrl: item.large_image_url,
269
215
  increment: item.increment,
216
+ // index: null,
217
+ ingredients: item.ingredients,
218
+ isSoldOut: isSoldOut,
219
+ madeFor: simpleItem ? simpleItem.made_for || null : null,
270
220
  max: item.max_quantity,
271
221
  min: item.min_quantity,
222
+ name: item.name,
223
+ notes: simpleItem ? simpleItem.notes || null : null,
224
+ nutritionalInfo: item.nutritional_info,
272
225
  points: hasPoints ? item.points || null : null,
273
- upsellItems: item.upsell_items || [],
274
- similarItems: item.similar_items || []
226
+ price: parseFloat(item.price),
227
+ quantity: item.min_quantity || 1 * item.increment,
228
+ shortDescription: item.short_description,
229
+ shortName: item.short_name,
230
+ similarItems: item.similar_items,
231
+ slug: item.slug,
232
+ tags: (0, helpers_1.convertStringToArray)(item.tags),
233
+ totalCals: null,
234
+ totalPoints: null,
235
+ totalPrice: null,
236
+ upsellItems: item.upsell_items
275
237
  };
276
- if (simpleItem) {
277
- const { cart_guest_id, customer_id, made_for, notes } = simpleItem;
278
- if (cart_guest_id)
279
- orderItem.cart_guest_id = cart_guest_id;
280
- if (customer_id)
281
- orderItem.customer_id = customer_id;
282
- if (made_for)
283
- orderItem.madeFor = made_for;
284
- if (notes)
285
- orderItem.notes = notes;
286
- }
287
238
  const pricedItem = (0, exports.calcPrices)(orderItem);
288
239
  return pricedItem;
289
240
  };
290
241
  exports.makeOrderItem = makeOrderItem;
291
- const rehydrateOrderItem = (menuItem, simpleCartItem) => {
292
- var _a;
293
- const orderItem = (0, exports.makeOrderItem)(menuItem, true, [], simpleCartItem);
242
+ const calcCartCounts = (cart) => {
243
+ return cart.reduce((obj, item) => {
244
+ const newCount = (obj[item.id.toString()] || 0) + item.quantity;
245
+ return Object.assign(Object.assign({}, obj), { [item.id]: newCount });
246
+ }, {});
247
+ };
248
+ exports.calcCartCounts = calcCartCounts;
249
+ const makeSimpleGroupsLookup = (groups) => {
250
+ if (!groups || !groups.length)
251
+ return null;
252
+ return groups.reduce((grpObj, g) => {
253
+ const options = g.options.reduce((optObj, o) => {
254
+ optObj[o.id] = {
255
+ quantity: o.quantity,
256
+ groupsLookup: makeSimpleGroupsLookup(o.groups)
257
+ };
258
+ return optObj;
259
+ }, {});
260
+ grpObj[g.id] = { options };
261
+ return grpObj;
262
+ }, {});
263
+ };
264
+ const rehydrateGroups = (groups, groupsLookup) => {
265
+ if (!groupsLookup)
266
+ return groups;
267
+ groups.forEach(group => {
268
+ const simpleGroup = groupsLookup[group.id];
269
+ if (simpleGroup) {
270
+ group.options.forEach(option => {
271
+ const simpleOption = simpleGroup.options[option.id];
272
+ if (simpleOption) {
273
+ option.quantity = simpleOption.quantity;
274
+ option.groups = rehydrateGroups(option.groups, simpleOption.groupsLookup);
275
+ }
276
+ });
277
+ }
278
+ });
279
+ return groups;
280
+ };
281
+ const rehydrateOrderItem = (menuItem, simpleCartItem, soldOut = []) => {
282
+ const orderItem = (0, exports.makeOrderItem)(menuItem, true, soldOut, simpleCartItem);
294
283
  orderItem.quantity = simpleCartItem.quantity || 1;
295
- if (simpleCartItem.groups && simpleCartItem.groups.length) {
296
- const groupsLookup = makeGroupsLookup(simpleCartItem);
297
- (_a = orderItem.groups) === null || _a === void 0 ? void 0 : _a.forEach(group => {
298
- var _a;
299
- const simpleGroup = group.id ? groupsLookup[group.id] : null;
300
- if (simpleGroup) {
301
- (_a = group.options) === null || _a === void 0 ? void 0 : _a.forEach(option => {
302
- if (option.id) {
303
- const simpleOption = simpleGroup.options[option.id];
304
- option.quantity = simpleOption ? simpleOption.quantity : 0;
305
- }
306
- });
307
- }
308
- });
284
+ const groupsLookup = makeSimpleGroupsLookup(simpleCartItem.groups);
285
+ if (groupsLookup) {
286
+ orderItem.groups = rehydrateGroups(orderItem.groups, groupsLookup);
309
287
  }
310
288
  const pricedItem = (0, exports.calcPrices)(orderItem);
311
289
  return pricedItem;
312
290
  };
313
291
  exports.rehydrateOrderItem = rehydrateOrderItem;
314
- const rehydrateCart = (menuItems, simpleCartItems) => {
292
+ const rehydrateCart = (menuItems, simpleCartItems, soldOut = []) => {
315
293
  const orderItems = [];
316
294
  simpleCartItems.forEach(item => {
317
295
  const menuItem = menuItems.find(i => i.id === item.id);
318
296
  if (menuItem) {
319
- const orderItem = (0, exports.rehydrateOrderItem)(menuItem, item);
297
+ const orderItem = (0, exports.rehydrateOrderItem)(menuItem, item, soldOut);
320
298
  orderItems.push(orderItem);
321
299
  }
322
300
  });
@@ -325,6 +303,7 @@ const rehydrateCart = (menuItems, simpleCartItems) => {
325
303
  return { cart, cartCounts };
326
304
  };
327
305
  exports.rehydrateCart = rehydrateCart;
306
+ // TODO: maybe refactor
328
307
  const rehydrateDetails = (details) => {
329
308
  return {
330
309
  cart_id: details === null || details === void 0 ? void 0 : details.cart_id,
@@ -335,6 +314,7 @@ const rehydrateDetails = (details) => {
335
314
  tax_exempt_id: details === null || details === void 0 ? void 0 : details.tax_exempt_id
336
315
  };
337
316
  };
317
+ // TODO: maybe refactor
338
318
  const rehydrateCustomer = (customer) => {
339
319
  const newCustomer = {
340
320
  first_name: customer === null || customer === void 0 ? void 0 : customer.first_name,
@@ -348,6 +328,7 @@ const rehydrateCustomer = (customer) => {
348
328
  }
349
329
  return newCustomer;
350
330
  };
331
+ // TODO: maybe refactor
351
332
  const rehydrateAddress = (address) => {
352
333
  if (!address)
353
334
  return {};
@@ -358,15 +339,19 @@ const rehydrateAddress = (address) => {
358
339
  phone: address.phone
359
340
  };
360
341
  };
342
+ // TODO: maybe refactor
361
343
  const rehydrateSurcharges = (surcharges) => {
362
344
  return surcharges === null || surcharges === void 0 ? void 0 : surcharges.filter(i => i.is_optional).map(i => ({ id: i.surcharge_id }));
363
345
  };
346
+ // TODO: maybe refactor
364
347
  const rehydrateDiscounts = (discounts) => {
365
348
  return discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => !i.is_promo_code).map(i => ({ id: i.discount_id || i.id, ext_id: i.ext_id }));
366
349
  };
350
+ // TODO: maybe refactor
367
351
  const rehydratePromoCodes = (discounts) => {
368
352
  return discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => i.is_promo_code).map(i => i.name);
369
353
  };
354
+ // TODO: maybe refactor
370
355
  const rehydrateTenders = (tenders) => {
371
356
  // const giftCards = tenders.filter((i) => i.tender_type === 'GIFT_CARD')
372
357
  const other = tenders === null || tenders === void 0 ? void 0 : tenders.map(i => {
@@ -382,6 +367,7 @@ const rehydrateTenders = (tenders) => {
382
367
  });
383
368
  return other;
384
369
  };
370
+ // TODO: maybe refactor
385
371
  const rehydrateCheckoutForm = (order) => {
386
372
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
387
373
  const form = {
@@ -399,7 +385,7 @@ const rehydrateCheckoutForm = (order) => {
399
385
  exports.rehydrateCheckoutForm = rehydrateCheckoutForm;
400
386
  // group orders
401
387
  const makeGuestLookup = (cartGuests) => {
402
- return cartGuests.reduce((obj, i) => (i.cart_guest_id ? Object.assign(Object.assign({}, obj), { [i.cart_guest_id]: i }) : Object.assign({}, obj)), {});
388
+ return cartGuests.reduce((obj, i) => i.cart_guest_id ? Object.assign(Object.assign({}, obj), { [i.cart_guest_id]: i }) : Object.assign({}, obj), {});
403
389
  };
404
390
  exports.makeGuestLookup = makeGuestLookup;
405
391
  const combineCarts = (cart, guestCart, cartOwner, cartGuests) => {
@@ -424,41 +410,10 @@ const makeItemImageUrl = (images) => {
424
410
  return (imageMap.SMALL_IMAGE || imageMap.LARGE_IMAGE || imageMap.APP_IMAGE || null);
425
411
  };
426
412
  exports.makeItemImageUrl = makeItemImageUrl;
427
- const makeItemSignature = (item) => {
428
- const optionIds = !item.groups
429
- ? []
430
- : item.groups
431
- .reduce((arr, group) => {
432
- var _a;
433
- const ids = (_a = group.options) === null || _a === void 0 ? void 0 : _a.map(o => o.id);
434
- return [...arr, ...(ids !== null && ids !== void 0 ? ids : [])];
435
- }, [])
436
- .sort((a, b) => a - b);
437
- return [item.id, ...optionIds].join('.');
438
- };
439
- exports.makeItemSignature = makeItemSignature;
440
- const makeCartItemSignature = (item) => {
441
- var _a;
442
- const optionIds = ((_a = item.groups) !== null && _a !== void 0 ? _a : [])
443
- .reduce((arr, group) => {
444
- var _a;
445
- const ids = (_a = group === null || group === void 0 ? void 0 : group.options) === null || _a === void 0 ? void 0 : _a.filter(o => { var _a; return ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0) > 0; }).reduce((optionsArr, o) => {
446
- const optionArr = new Array(o.quantity);
447
- optionArr.fill(o.id);
448
- return [...optionsArr, ...optionArr];
449
- }, []);
450
- return [...arr, ...(ids !== null && ids !== void 0 ? ids : [])];
451
- }, [])
452
- .sort((a, b) => a - b);
453
- const itemIds = [item.id, ...optionIds].join('.');
454
- const signature = `${itemIds}.${item.madeFor}.${item.notes}`;
455
- return signature;
456
- };
457
- exports.makeCartItemSignature = makeCartItemSignature;
458
413
  const makeDisplayItemGroups = (optionGroups) => {
459
414
  if (!optionGroups || !optionGroups.length)
460
415
  return [];
461
- return optionGroups.map((g) => {
416
+ return optionGroups.map(g => {
462
417
  var _a;
463
418
  const options = (_a = g.options) === null || _a === void 0 ? void 0 : _a.map(o => (0, exports.makeDisplayItem)(o));
464
419
  return Object.assign(Object.assign({}, g), { options });
@@ -466,29 +421,28 @@ const makeDisplayItemGroups = (optionGroups) => {
466
421
  };
467
422
  exports.makeDisplayItemGroups = makeDisplayItemGroups;
468
423
  const makeDisplayItem = (item, isOption = false) => {
469
- var _a, _b, _c;
424
+ var _a;
470
425
  const cals = item.nutritional_info ? (_a = item.nutritional_info) === null || _a === void 0 ? void 0 : _a.calories : null;
471
426
  let displayItem = {
427
+ allergens: item.allergens,
428
+ cals: cals,
429
+ description: item.description,
430
+ groups: (0, exports.makeDisplayItemGroups)(item.groups),
431
+ imageUrl: (0, exports.makeItemImageUrl)(item.images),
472
432
  id: item.id,
473
433
  name: item.name,
434
+ nutritionalInfo: item.nutritional_info,
435
+ quantity: item.quantity,
436
+ price: item.price,
474
437
  shortDescription: item.short_description,
475
- description: item.description,
476
- imageUrl: (0, exports.makeItemImageUrl)((_b = item.images) !== null && _b !== void 0 ? _b : []),
477
- allergens: item.allergens || [],
478
- tags: item.tags || [],
479
- nutritionalInfo: item.nutritional_info || null,
480
- cals: isNaN(cals !== null && cals !== void 0 ? cals : 0) ? null : cals,
481
- groups: (0, exports.makeDisplayItemGroups)((_c = item.groups) !== null && _c !== void 0 ? _c : []),
482
- quantity: item.quantity || 1,
483
- price: item.price !== undefined ? item.price : undefined,
484
- totalPrice: item.price_total !== undefined ? item.price_total : undefined
438
+ tags: item.tags,
439
+ totalPrice: item.price_total
485
440
  };
486
441
  if (!isOption) {
487
442
  const itemDetails = {
488
443
  madeFor: item.made_for,
489
444
  notes: item.notes,
490
- favoriteId: item.favorite_id,
491
- signature: (0, exports.makeItemSignature)(item)
445
+ signature: (0, exports.makeItemSignature)(displayItem)
492
446
  };
493
447
  displayItem = Object.assign(Object.assign({}, displayItem), itemDetails);
494
448
  }
@@ -522,39 +476,45 @@ const makeFavoritesLookup = (favorites) => {
522
476
  .reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [(0, exports.makeItemSignature)(i.cart)]: i.favorite_id })), {});
523
477
  };
524
478
  exports.makeFavoritesLookup = makeFavoritesLookup;
525
- const makeOrderAddress = (address) => {
526
- const { street, unit, city, state, postal_code } = address || {};
527
- return street
528
- ? `${street}${unit ? `, ${unit}` : ''}`
529
- : postal_code
530
- ? `${postal_code} ${city}, ${state}`
531
- : 'No address provided';
532
- };
533
- exports.makeOrderAddress = makeOrderAddress;
534
- const makeFullAddress = (address) => {
535
- const { street, city, state, postal_code } = address || {};
536
- return `${street ? `${street}, ` : ''}${city}, ${state} ${postal_code}`;
537
- };
538
- exports.makeFullAddress = makeFullAddress;
539
- const calcCartCounts = (cart) => {
540
- return cart.reduce((obj, item) => {
541
- var _a;
542
- const newCount = (obj[(_a = item.id) !== null && _a !== void 0 ? _a : 0] || 0) + item.quantity;
543
- return item.id ? Object.assign(Object.assign({}, obj), { [item.id]: newCount }) : Object.assign({}, obj);
544
- }, {});
479
+ const makeCartItemOptionIds = (groups) => {
480
+ if (!groups || !groups.length)
481
+ return [];
482
+ return groups
483
+ .reduce((arr, group) => {
484
+ const ids = group.options
485
+ .filter(o => o.quantity > 0)
486
+ .reduce((optionsArr, o) => {
487
+ const optionArr = new Array(o.quantity);
488
+ optionArr.fill(o.id);
489
+ const nestedIds = makeCartItemOptionIds(o.groups);
490
+ return [...optionsArr, ...optionArr, ...nestedIds];
491
+ }, []);
492
+ return [...arr, ...ids];
493
+ }, [])
494
+ .sort((a, b) => a - b);
545
495
  };
546
- exports.calcCartCounts = calcCartCounts;
496
+ const makeItemSignature = (item) => {
497
+ const optionIds = makeCartItemOptionIds(item.groups);
498
+ return [item.id, ...optionIds].join('.');
499
+ };
500
+ exports.makeItemSignature = makeItemSignature;
501
+ const makeCartItemSignature = (item) => {
502
+ const optionIds = makeCartItemOptionIds(item.groups);
503
+ const itemIds = [item.id, ...optionIds].join('.');
504
+ const signature = `${itemIds}.${item.madeFor}.${item.notes}`;
505
+ return signature;
506
+ };
507
+ exports.makeCartItemSignature = makeCartItemSignature;
547
508
  const addItem = (cart, item) => {
548
- var _a;
549
509
  if (typeof item.index === 'undefined') {
550
510
  const itemSignature = (0, exports.makeCartItemSignature)(item);
551
511
  const itemSignatures = cart.map(i => (Object.assign({ signature: (0, exports.makeCartItemSignature)(i) }, i)));
552
512
  const match = itemSignatures.find(i => i.signature === itemSignature);
553
- if (match) {
513
+ if (match && match.index) {
554
514
  const quantity = item.quantity + match.quantity;
555
515
  const newItem = Object.assign(Object.assign({}, item), { quantity });
556
516
  const updated = (0, exports.calcPrices)(newItem);
557
- cart[(_a = match.index) !== null && _a !== void 0 ? _a : 0] = Object.assign(Object.assign({}, updated), { index: match.index });
517
+ cart[match.index] = Object.assign(Object.assign({}, updated), { index: match.index });
558
518
  }
559
519
  else {
560
520
  cart.push(Object.assign(Object.assign({}, item), { index: cart.length }));
@@ -587,7 +547,7 @@ const incrementItem = (cart, index) => {
587
547
  newQuantity =
588
548
  item.max === 0 ? newQuantity : Math.min(item.max, newQuantity);
589
549
  const newItem = (0, exports.calcPrices)(Object.assign(Object.assign({}, item), { quantity: newQuantity }));
590
- cart[realIndex !== null && realIndex !== void 0 ? realIndex : 0] = newItem;
550
+ cart[realIndex] = newItem;
591
551
  }
592
552
  }
593
553
  const cartCounts = (0, exports.calcCartCounts)(cart);
@@ -612,18 +572,24 @@ const decrementItem = (cart, index) => {
612
572
  return { cart, cartCounts };
613
573
  };
614
574
  exports.decrementItem = decrementItem;
575
+ const makeSimpleGroups = (groups) => {
576
+ return groups.map(g => {
577
+ const options = g.options
578
+ .filter(o => o.quantity !== 0)
579
+ .map(o => ({
580
+ id: o.id,
581
+ quantity: o.quantity,
582
+ groups: makeSimpleGroups(o.groups || [])
583
+ }));
584
+ return { id: g.id, options: options };
585
+ });
586
+ };
615
587
  const makeSimpleCart = (cart) => {
616
588
  const simpleCart = cart.map(i => {
617
- var _a;
618
- const groups = (_a = i.groups) === null || _a === void 0 ? void 0 : _a.map(g => {
619
- var _a;
620
- const options = (_a = g.options) === null || _a === void 0 ? void 0 : _a.filter(o => o.quantity !== 0).map(o => ({ id: o.id, quantity: o.quantity }));
621
- return { id: g.id, options: options };
622
- });
623
589
  return {
624
590
  id: i.id,
625
591
  quantity: i.quantity,
626
- groups: groups,
592
+ groups: makeSimpleGroups(i.groups),
627
593
  made_for: i.madeFor || '',
628
594
  notes: i.notes || ''
629
595
  };
@@ -632,6 +598,7 @@ const makeSimpleCart = (cart) => {
632
598
  };
633
599
  exports.makeSimpleCart = makeSimpleCart;
634
600
  /* cart validation */
601
+ // TODO: refactor for nested modifiers
635
602
  // convert menu items to order items for validation but only include
636
603
  // items that are already in the cart to save wasted effort
637
604
  const makeItemLookup = (categories, itemIds) => {
@@ -654,6 +621,7 @@ const makeItemLookup = (categories, itemIds) => {
654
621
  });
655
622
  return itemLookup;
656
623
  };
624
+ // TODO: refactor for nested modifiers
657
625
  const makeGroupsLookup = (item) => {
658
626
  var _a;
659
627
  return (_a = item.groups) === null || _a === void 0 ? void 0 : _a.reduce((grpObj, i) => {
@@ -670,6 +638,7 @@ const makeGroupsLookup = (item) => {
670
638
  return grpObj;
671
639
  }, {});
672
640
  };
641
+ // TODO: refactor for nested modifiers
673
642
  const validateCart = (cart, categories, soldOut) => {
674
643
  const itemIds = cart.map(item => item.id);
675
644
  const itemLookup = makeItemLookup(categories, itemIds);
@@ -692,7 +661,8 @@ const validateCart = (cart, categories, soldOut) => {
692
661
  const newRequiredGroups = Object.values(newGroups).filter((i) => i.min > 0);
693
662
  const oldGroupIds = (_a = oldItem.groups) === null || _a === void 0 ? void 0 : _a.map(i => i.id);
694
663
  missingGroups = newRequiredGroups.filter((i) => !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id)));
695
- const newEmptyGroups = Object.values(newGroups).filter((i) => {
664
+ const newEmptyGroups = Object.values(newGroups)
665
+ .filter((i) => {
696
666
  return i.min === 0 && !(oldGroupIds === null || oldGroupIds === void 0 ? void 0 : oldGroupIds.includes(i.id));
697
667
  })
698
668
  .map((i) => (Object.assign(Object.assign({}, i), { options: Object.values(i.options) })));
@@ -849,46 +819,3 @@ const checkAmountRemaining = (total, tenders) => {
849
819
  return Object.is(remaining, -0) ? 0.0 : remaining;
850
820
  };
851
821
  exports.checkAmountRemaining = checkAmountRemaining;
852
- const makeUpsellItems = (itemIds, itemLookup) => {
853
- return itemIds
854
- .map((id) => itemLookup[id])
855
- .filter((i) => i)
856
- .map((i) => (0, exports.makeOrderItem)(i))
857
- .filter((i) => {
858
- var _a;
859
- const belowMin = (_a = i.groups) === null || _a === void 0 ? void 0 : _a.filter((g) => { var _a; return !g.isSize && g.quantity < ((_a = g.min) !== null && _a !== void 0 ? _a : 0); });
860
- return (belowMin === null || belowMin === void 0 ? void 0 : belowMin.length) === 0;
861
- });
862
- };
863
- exports.makeUpsellItems = makeUpsellItems;
864
- const nutritionKeys = [
865
- 'calories',
866
- 'cholesterol',
867
- 'dietary_fiber',
868
- 'protein',
869
- 'saturated_fat',
870
- 'sodium',
871
- 'sugars',
872
- 'total_carbs',
873
- 'total_fat',
874
- 'trans_fat',
875
- ];
876
- const calcNutrition = (item) => {
877
- const { nutritionalInfo, groups } = item;
878
- let nutrition = nutritionalInfo ? Object.assign({}, nutritionalInfo) : {};
879
- const options = groups.reduce((arr, g) => {
880
- var _a, _b;
881
- return [...arr, ...((_b = (_a = g.options) === null || _a === void 0 ? void 0 : _a.filter((o) => { var _a; return ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0) > 0; })) !== null && _b !== void 0 ? _b : [])];
882
- }, []);
883
- options.forEach((o) => {
884
- nutritionKeys === null || nutritionKeys === void 0 ? void 0 : nutritionKeys.forEach((key) => {
885
- const optionVal = o.nutritionalInfo
886
- ? parseInt(o.nutritionalInfo[key]) || 0
887
- : 0;
888
- const itemVal = parseInt(nutrition[key]) || 0;
889
- nutrition = Object.assign(Object.assign({}, nutrition), { [key]: itemVal + optionVal });
890
- });
891
- });
892
- return nutrition;
893
- };
894
- exports.calcNutrition = calcNutrition;