@open-tender/utils 0.0.17 → 0.0.19

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.
@@ -46,18 +46,18 @@ const useBuilder = (orderItem) => {
46
46
  const groups = (_a = item === null || item === void 0 ? void 0 : item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
47
47
  var _a, _b, _c;
48
48
  if (group.id === groupId) {
49
- const count = (_a = group === null || group === void 0 ? void 0 : group.options) === null || _a === void 0 ? void 0 : _a.filter((o) => o.id !== optionId).reduce((t, o) => t + o.quantity, 0);
49
+ const count = (_a = group === null || group === void 0 ? void 0 : group.options) === null || _a === void 0 ? void 0 : _a.filter((o) => o.id !== optionId).reduce((t, o) => { var _a; return t + ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0); }, 0);
50
50
  if (group.max !== 0 && (count !== null && count !== void 0 ? count : 0) >= ((_b = group.max) !== null && _b !== void 0 ? _b : 0))
51
51
  return group;
52
52
  const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
53
- var _a;
53
+ var _a, _b, _c, _d;
54
54
  if (option.id === optionId) {
55
- let quantity = option.quantity + option.increment;
55
+ let quantity = ((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) + ((_b = option.increment) !== null && _b !== void 0 ? _b : 0);
56
56
  const quantities = [quantity];
57
57
  if (option.max !== 0)
58
- quantities.push(option.max);
58
+ quantities.push(((_c = option.max) !== null && _c !== void 0 ? _c : 0));
59
59
  if (group.max !== 0)
60
- quantities.push(((_a = group.max) !== null && _a !== void 0 ? _a : 0) - (count !== null && count !== void 0 ? count : 0));
60
+ quantities.push(((_d = group.max) !== null && _d !== void 0 ? _d : 0) - (count !== null && count !== void 0 ? count : 0));
61
61
  quantity = Math.min(...quantities);
62
62
  return Object.assign(Object.assign({}, option), { quantity });
63
63
  }
@@ -75,8 +75,9 @@ const useBuilder = (orderItem) => {
75
75
  var _a;
76
76
  if (group.id === groupId) {
77
77
  const options = (_a = group.options) === null || _a === void 0 ? void 0 : _a.map((option) => {
78
+ var _a, _b;
78
79
  if (option.id === optionId) {
79
- const quantity = Math.max(option.quantity - option.increment, 0);
80
+ const quantity = Math.max(((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) - ((_b = option.increment) !== null && _b !== void 0 ? _b : 0), 0);
80
81
  return Object.assign(Object.assign({}, option), { quantity });
81
82
  }
82
83
  return option;
@@ -92,11 +93,11 @@ const useBuilder = (orderItem) => {
92
93
  const groups = (_a = item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
93
94
  var _a, _b, _c;
94
95
  if (group.id === groupId) {
95
- const count = (_a = group.options) === null || _a === void 0 ? void 0 : _a.filter((o) => o.id !== optionId).reduce((t, o) => t + o.quantity, 0);
96
+ const count = (_a = group.options) === null || _a === void 0 ? void 0 : _a.filter((o) => o.id !== optionId).reduce((t, o) => { var _a; return t + ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0); }, 0);
96
97
  if (group.max !== 0 && (count !== null && count !== void 0 ? count : 0) >= ((_b = group.max) !== null && _b !== void 0 ? _b : 0))
97
98
  return group;
98
99
  const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
99
- var _a;
100
+ var _a, _b, _c;
100
101
  const optionGroups = nested || option.groups || [];
101
102
  if (option.id === optionId) {
102
103
  if (`${quantity}` === '') {
@@ -105,11 +106,11 @@ const useBuilder = (orderItem) => {
105
106
  else {
106
107
  const quantities = [quantity];
107
108
  if (option.max !== 0)
108
- quantities.push(option.max);
109
+ quantities.push(((_a = option.max) !== null && _a !== void 0 ? _a : 0));
109
110
  if (group.max !== 0)
110
- quantities.push(((_a = group.max) !== null && _a !== void 0 ? _a : 0) - (count !== null && count !== void 0 ? count : 0));
111
+ quantities.push(((_b = group.max) !== null && _b !== void 0 ? _b : 0) - (count !== null && count !== void 0 ? count : 0));
111
112
  quantity = Math.min(...quantities);
112
- quantity = Math.max(quantity, option.min);
113
+ quantity = Math.max(quantity, ((_c = option.min) !== null && _c !== void 0 ? _c : 0));
113
114
  return Object.assign(Object.assign({}, option), { quantity, groups: optionGroups });
114
115
  }
115
116
  }
@@ -39,7 +39,8 @@ const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenAlerts =
39
39
  : description;
40
40
  const optionNames = favorite
41
41
  ? (_e = (_d = favorite === null || favorite === void 0 ? void 0 : favorite.item) === null || _d === void 0 ? void 0 : _d.groups) === null || _e === void 0 ? void 0 : _e.reduce((arr, group) => {
42
- const names = group.options.map((o) => o.name);
42
+ var _a, _b;
43
+ const names = (_b = (_a = group.options) === null || _a === void 0 ? void 0 : _a.map((o) => o.name)) !== null && _b !== void 0 ? _b : [];
43
44
  return [...arr, ...names];
44
45
  }, []).join(', ')
45
46
  : null;
@@ -4,7 +4,7 @@ export declare const makeDisplayPrice: (item: MenuItem) => string | null;
4
4
  export declare const addCommas: (x: number, d: number) => string;
5
5
  export declare const formatQuantity: (n: string) => string;
6
6
  export declare const formatDollars: (str: string, space?: string, decimals?: number) => string;
7
- export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[] | undefined;
7
+ export declare const getItemOptions: (item: Partial<CartItem>) => Partial<CartItemOption>[] | undefined;
8
8
  export declare const makeModifierNames: (item: CartItem) => string | undefined;
9
9
  export declare const convertStringToArray: (str: string) => string[];
10
10
  export declare const makeOrderTypeFromParam: (param: string) => (string | boolean)[] | null;
@@ -22,25 +22,25 @@ export declare const calcPrices: (item: Partial<CartItem>) => {
22
22
  totalPrice: number;
23
23
  totalPoints: number;
24
24
  totalCals: number;
25
- id: number;
26
- name: string;
27
- shortName: string;
28
- description: string | null;
29
- imageUrl: string | null;
30
- allergens: string[];
31
- tags: string[];
32
- ingredients: string | null;
33
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
34
- cals: number | null;
35
- price: number;
25
+ id?: number | undefined;
26
+ name?: string | undefined;
27
+ shortName?: string | undefined;
28
+ description?: string | null | undefined;
29
+ imageUrl?: string | null | undefined;
30
+ allergens?: string[] | undefined;
31
+ tags?: string[] | undefined;
32
+ ingredients?: string | null | undefined;
33
+ nutritionalInfo?: import("@open-tender/types").NutritionalInfo | null | undefined;
34
+ cals?: number | null | undefined;
35
+ price?: number | undefined;
36
36
  price_total?: number | undefined;
37
- quantity: number;
37
+ quantity?: number | undefined;
38
38
  isDefault?: number | boolean | undefined;
39
- increment: number;
40
- max: number;
41
- min: number;
42
- isSoldOut: boolean;
43
- points: number;
39
+ increment?: number | undefined;
40
+ max?: number | undefined;
41
+ min?: number | undefined;
42
+ isSoldOut?: boolean | undefined;
43
+ points?: number | undefined;
44
44
  groups?: Partial<CartItemGroup>[] | undefined;
45
45
  }[] | undefined;
46
46
  id?: number | undefined;
@@ -103,25 +103,25 @@ export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?:
103
103
  totalPrice: number;
104
104
  totalPoints: number;
105
105
  totalCals: number;
106
- id: number;
107
- name: string;
108
- shortName: string;
109
- description: string | null;
110
- imageUrl: string | null;
111
- allergens: string[];
112
- tags: string[];
113
- ingredients: string | null;
114
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
115
- cals: number | null;
116
- price: number;
106
+ id?: number | undefined;
107
+ name?: string | undefined;
108
+ shortName?: string | undefined;
109
+ description?: string | null | undefined;
110
+ imageUrl?: string | null | undefined;
111
+ allergens?: string[] | undefined;
112
+ tags?: string[] | undefined;
113
+ ingredients?: string | null | undefined;
114
+ nutritionalInfo?: import("@open-tender/types").NutritionalInfo | null | undefined;
115
+ cals?: number | null | undefined;
116
+ price?: number | undefined;
117
117
  price_total?: number | undefined;
118
- quantity: number;
118
+ quantity?: number | undefined;
119
119
  isDefault?: number | boolean | undefined;
120
- increment: number;
121
- max: number;
122
- min: number;
123
- isSoldOut: boolean;
124
- points: number;
120
+ increment?: number | undefined;
121
+ max?: number | undefined;
122
+ min?: number | undefined;
123
+ isSoldOut?: boolean | undefined;
124
+ points?: number | undefined;
125
125
  groups?: Partial<CartItemGroup>[] | undefined;
126
126
  }[] | undefined;
127
127
  id?: number | undefined;
@@ -346,25 +346,25 @@ export declare const validateCart: (cart: OrderCart, categories: MenuCategories,
346
346
  totalPrice: number;
347
347
  totalPoints: number;
348
348
  totalCals: number;
349
- id: number;
350
- name: string;
351
- shortName: string;
352
- description: string | null;
353
- imageUrl: string | null;
354
- allergens: string[];
355
- tags: string[];
356
- ingredients: string | null;
357
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
358
- cals: number | null;
359
- price: number;
349
+ id?: number | undefined;
350
+ name?: string | undefined;
351
+ shortName?: string | undefined;
352
+ description?: string | null | undefined;
353
+ imageUrl?: string | null | undefined;
354
+ allergens?: string[] | undefined;
355
+ tags?: string[] | undefined;
356
+ ingredients?: string | null | undefined;
357
+ nutritionalInfo?: import("@open-tender/types").NutritionalInfo | null | undefined;
358
+ cals?: number | null | undefined;
359
+ price?: number | undefined;
360
360
  price_total?: number | undefined;
361
- quantity: number;
361
+ quantity?: number | undefined;
362
362
  isDefault?: number | boolean | undefined;
363
- increment: number;
364
- max: number;
365
- min: number;
366
- isSoldOut: boolean;
367
- points: number;
363
+ increment?: number | undefined;
364
+ max?: number | undefined;
365
+ min?: number | undefined;
366
+ isSoldOut?: boolean | undefined;
367
+ points?: number | undefined;
368
368
  groups?: Partial<CartItemGroup>[] | undefined;
369
369
  }[] | undefined;
370
370
  id?: number | undefined;
@@ -37,7 +37,7 @@ const getItemOptions = (item) => {
37
37
  if (!item.groups || !item.groups.length)
38
38
  return [];
39
39
  const options = item.groups
40
- .map(group => { var _a; return (_a = group.options) === null || _a === void 0 ? void 0 : _a.filter(option => option.quantity > 0); })
40
+ .map(group => { var _a; return (_a = group.options) === null || _a === void 0 ? void 0 : _a.filter(option => { var _a; return ((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) > 0; }); })
41
41
  .reduce((arr, i) => [...(arr !== null && arr !== void 0 ? arr : []), ...(i !== null && i !== void 0 ? i : [])], []);
42
42
  return options;
43
43
  };
@@ -216,10 +216,10 @@ const calcPrices = (item) => {
216
216
  var _a;
217
217
  let groupQuantity = 0;
218
218
  const options = (_a = g.options) === null || _a === void 0 ? void 0 : _a.map(o => {
219
- var _a, _b;
219
+ var _a, _b, _c, _d, _e;
220
220
  const includedRemaining = Math.max(((_a = g.included) !== null && _a !== void 0 ? _a : 0) - groupQuantity, 0);
221
- const priceQuantity = Math.max(o.quantity - includedRemaining, 0);
222
- const option = Object.assign(Object.assign({}, o), { totalPrice: priceQuantity * o.price, totalPoints: priceQuantity * ((_b = o.points) !== null && _b !== void 0 ? _b : 0), totalCals: o.cals ? o.quantity * o.cals : 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
223
  groupQuantity += o.quantity || 0;
224
224
  return option;
225
225
  });
@@ -299,8 +299,10 @@ const rehydrateOrderItem = (menuItem, simpleCartItem) => {
299
299
  const simpleGroup = group.id ? groupsLookup[group.id] : null;
300
300
  if (simpleGroup) {
301
301
  (_a = group.options) === null || _a === void 0 ? void 0 : _a.forEach(option => {
302
- const simpleOption = simpleGroup.options[option.id];
303
- option.quantity = simpleOption ? simpleOption.quantity : 0;
302
+ if (option.id) {
303
+ const simpleOption = simpleGroup.options[option.id];
304
+ option.quantity = simpleOption ? simpleOption.quantity : 0;
305
+ }
304
306
  });
305
307
  }
306
308
  });
@@ -441,7 +443,7 @@ const makeCartItemSignature = (item) => {
441
443
  : item.groups
442
444
  .reduce((arr, group) => {
443
445
  var _a;
444
- const ids = (_a = group.options) === null || _a === void 0 ? void 0 : _a.filter(o => o.quantity > 0).reduce((optionsArr, o) => {
446
+ const ids = (_a = 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) => {
445
447
  const optionArr = new Array(o.quantity);
446
448
  optionArr.fill(o.id);
447
449
  return [...optionsArr, ...optionArr];
@@ -656,7 +658,9 @@ const makeGroupsLookup = (item) => {
656
658
  return (_a = item.groups) === null || _a === void 0 ? void 0 : _a.reduce((grpObj, i) => {
657
659
  var _a;
658
660
  const options = (_a = i.options) === null || _a === void 0 ? void 0 : _a.reduce((optObj, o) => {
659
- optObj[o.id] = o;
661
+ if (o.id) {
662
+ optObj[o.id] = o;
663
+ }
660
664
  return optObj;
661
665
  }, {});
662
666
  if (i.id) {
@@ -1,4 +1,4 @@
1
- import { AvailableDates, CustomerRevenueCenter, ISOString, Order, GroupOrderTime, CustomerRevenueCenterSettings, ServiceType, Timezone, TimezonePython, Weekday, FirstTime, OrderTime, TimeInterval, ValidTimes, HolidayItem, DateString, TimeObject, DatePickerTimes } from '@open-tender/types';
1
+ import { AvailableDates, CustomerRevenueCenter, ISOString, Order, GroupOrderTime, CustomerRevenueCenterSettings, ServiceType, Timezone, TimezonePython, Weekday, FirstTime, OrderTime, TimeInterval, ValidTimes, HolidayItem, DateString, TimeObject, DatePickerTimes, OrderRevenueCenter } from '@open-tender/types';
2
2
  export declare const timezoneMap: {
3
3
  'US/Eastern': string;
4
4
  'US/Central': string;
@@ -174,7 +174,7 @@ export declare const makeFirstTimes: (revenueCenter: CustomerRevenueCenter, serv
174
174
  export declare const getNextInterval: (requestedAt: ISOString, tz: Timezone | TimezonePython, interval: number) => Date;
175
175
  export declare const adjustRequestedAt: (requestedAt: ISOString | string, tz: Timezone | TimezonePython, interval: number, leadTime: number) => ISOString;
176
176
  export declare const getFirstTime: (settings: CustomerRevenueCenterSettings, serviceType: ServiceType, tz: Timezone | TimezonePython) => OrderTime | FirstTime | null;
177
- export declare const makeGroupOrderTime: (revenueCenter: Partial<CustomerRevenueCenter>, serviceType: ServiceType, requestedAt: ISOString | string) => Partial<GroupOrderTime>;
177
+ export declare const makeGroupOrderTime: (revenueCenter: OrderRevenueCenter, serviceType: ServiceType, requestedAt: ISOString | string) => Partial<GroupOrderTime>;
178
178
  export declare const formatTime: (time: string) => string;
179
179
  export declare const makeGroupOrderTimeStr: (iso: ISOString, tz: Timezone | TimezonePython) => string | null;
180
180
  export declare const getLastInterval: (tz: Timezone | TimezonePython) => Date;
@@ -43,18 +43,18 @@ export const useBuilder = (orderItem) => {
43
43
  const groups = (_a = item === null || item === void 0 ? void 0 : item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
44
44
  var _a, _b, _c;
45
45
  if (group.id === groupId) {
46
- const count = (_a = group === null || group === void 0 ? void 0 : group.options) === null || _a === void 0 ? void 0 : _a.filter((o) => o.id !== optionId).reduce((t, o) => t + o.quantity, 0);
46
+ const count = (_a = group === null || group === void 0 ? void 0 : group.options) === null || _a === void 0 ? void 0 : _a.filter((o) => o.id !== optionId).reduce((t, o) => { var _a; return t + ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0); }, 0);
47
47
  if (group.max !== 0 && (count !== null && count !== void 0 ? count : 0) >= ((_b = group.max) !== null && _b !== void 0 ? _b : 0))
48
48
  return group;
49
49
  const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
50
- var _a;
50
+ var _a, _b, _c, _d;
51
51
  if (option.id === optionId) {
52
- let quantity = option.quantity + option.increment;
52
+ let quantity = ((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) + ((_b = option.increment) !== null && _b !== void 0 ? _b : 0);
53
53
  const quantities = [quantity];
54
54
  if (option.max !== 0)
55
- quantities.push(option.max);
55
+ quantities.push(((_c = option.max) !== null && _c !== void 0 ? _c : 0));
56
56
  if (group.max !== 0)
57
- quantities.push(((_a = group.max) !== null && _a !== void 0 ? _a : 0) - (count !== null && count !== void 0 ? count : 0));
57
+ quantities.push(((_d = group.max) !== null && _d !== void 0 ? _d : 0) - (count !== null && count !== void 0 ? count : 0));
58
58
  quantity = Math.min(...quantities);
59
59
  return Object.assign(Object.assign({}, option), { quantity });
60
60
  }
@@ -72,8 +72,9 @@ export const useBuilder = (orderItem) => {
72
72
  var _a;
73
73
  if (group.id === groupId) {
74
74
  const options = (_a = group.options) === null || _a === void 0 ? void 0 : _a.map((option) => {
75
+ var _a, _b;
75
76
  if (option.id === optionId) {
76
- const quantity = Math.max(option.quantity - option.increment, 0);
77
+ const quantity = Math.max(((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) - ((_b = option.increment) !== null && _b !== void 0 ? _b : 0), 0);
77
78
  return Object.assign(Object.assign({}, option), { quantity });
78
79
  }
79
80
  return option;
@@ -89,11 +90,11 @@ export const useBuilder = (orderItem) => {
89
90
  const groups = (_a = item.groups) === null || _a === void 0 ? void 0 : _a.map((group) => {
90
91
  var _a, _b, _c;
91
92
  if (group.id === groupId) {
92
- const count = (_a = group.options) === null || _a === void 0 ? void 0 : _a.filter((o) => o.id !== optionId).reduce((t, o) => t + o.quantity, 0);
93
+ const count = (_a = group.options) === null || _a === void 0 ? void 0 : _a.filter((o) => o.id !== optionId).reduce((t, o) => { var _a; return t + ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0); }, 0);
93
94
  if (group.max !== 0 && (count !== null && count !== void 0 ? count : 0) >= ((_b = group.max) !== null && _b !== void 0 ? _b : 0))
94
95
  return group;
95
96
  const options = (_c = group.options) === null || _c === void 0 ? void 0 : _c.map((option) => {
96
- var _a;
97
+ var _a, _b, _c;
97
98
  const optionGroups = nested || option.groups || [];
98
99
  if (option.id === optionId) {
99
100
  if (`${quantity}` === '') {
@@ -102,11 +103,11 @@ export const useBuilder = (orderItem) => {
102
103
  else {
103
104
  const quantities = [quantity];
104
105
  if (option.max !== 0)
105
- quantities.push(option.max);
106
+ quantities.push(((_a = option.max) !== null && _a !== void 0 ? _a : 0));
106
107
  if (group.max !== 0)
107
- quantities.push(((_a = group.max) !== null && _a !== void 0 ? _a : 0) - (count !== null && count !== void 0 ? count : 0));
108
+ quantities.push(((_b = group.max) !== null && _b !== void 0 ? _b : 0) - (count !== null && count !== void 0 ? count : 0));
108
109
  quantity = Math.min(...quantities);
109
- quantity = Math.max(quantity, option.min);
110
+ quantity = Math.max(quantity, ((_c = option.min) !== null && _c !== void 0 ? _c : 0));
110
111
  return Object.assign(Object.assign({}, option), { quantity, groups: optionGroups });
111
112
  }
112
113
  }
@@ -36,7 +36,8 @@ export const useOrderItem = (orderItem, favorite = null, soldOut = [], allergenA
36
36
  : description;
37
37
  const optionNames = favorite
38
38
  ? (_e = (_d = favorite === null || favorite === void 0 ? void 0 : favorite.item) === null || _d === void 0 ? void 0 : _d.groups) === null || _e === void 0 ? void 0 : _e.reduce((arr, group) => {
39
- const names = group.options.map((o) => o.name);
39
+ var _a, _b;
40
+ const names = (_b = (_a = group.options) === null || _a === void 0 ? void 0 : _a.map((o) => o.name)) !== null && _b !== void 0 ? _b : [];
40
41
  return [...arr, ...names];
41
42
  }, []).join(', ')
42
43
  : null;
@@ -4,7 +4,7 @@ export declare const makeDisplayPrice: (item: MenuItem) => string | null;
4
4
  export declare const addCommas: (x: number, d: number) => string;
5
5
  export declare const formatQuantity: (n: string) => string;
6
6
  export declare const formatDollars: (str: string, space?: string, decimals?: number) => string;
7
- export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[] | undefined;
7
+ export declare const getItemOptions: (item: Partial<CartItem>) => Partial<CartItemOption>[] | undefined;
8
8
  export declare const makeModifierNames: (item: CartItem) => string | undefined;
9
9
  export declare const convertStringToArray: (str: string) => string[];
10
10
  export declare const makeOrderTypeFromParam: (param: string) => (string | boolean)[] | null;
@@ -22,25 +22,25 @@ export declare const calcPrices: (item: Partial<CartItem>) => {
22
22
  totalPrice: number;
23
23
  totalPoints: number;
24
24
  totalCals: number;
25
- id: number;
26
- name: string;
27
- shortName: string;
28
- description: string | null;
29
- imageUrl: string | null;
30
- allergens: string[];
31
- tags: string[];
32
- ingredients: string | null;
33
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
34
- cals: number | null;
35
- price: number;
25
+ id?: number | undefined;
26
+ name?: string | undefined;
27
+ shortName?: string | undefined;
28
+ description?: string | null | undefined;
29
+ imageUrl?: string | null | undefined;
30
+ allergens?: string[] | undefined;
31
+ tags?: string[] | undefined;
32
+ ingredients?: string | null | undefined;
33
+ nutritionalInfo?: import("@open-tender/types").NutritionalInfo | null | undefined;
34
+ cals?: number | null | undefined;
35
+ price?: number | undefined;
36
36
  price_total?: number | undefined;
37
- quantity: number;
37
+ quantity?: number | undefined;
38
38
  isDefault?: number | boolean | undefined;
39
- increment: number;
40
- max: number;
41
- min: number;
42
- isSoldOut: boolean;
43
- points: number;
39
+ increment?: number | undefined;
40
+ max?: number | undefined;
41
+ min?: number | undefined;
42
+ isSoldOut?: boolean | undefined;
43
+ points?: number | undefined;
44
44
  groups?: Partial<CartItemGroup>[] | undefined;
45
45
  }[] | undefined;
46
46
  id?: number | undefined;
@@ -103,25 +103,25 @@ export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?:
103
103
  totalPrice: number;
104
104
  totalPoints: number;
105
105
  totalCals: number;
106
- id: number;
107
- name: string;
108
- shortName: string;
109
- description: string | null;
110
- imageUrl: string | null;
111
- allergens: string[];
112
- tags: string[];
113
- ingredients: string | null;
114
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
115
- cals: number | null;
116
- price: number;
106
+ id?: number | undefined;
107
+ name?: string | undefined;
108
+ shortName?: string | undefined;
109
+ description?: string | null | undefined;
110
+ imageUrl?: string | null | undefined;
111
+ allergens?: string[] | undefined;
112
+ tags?: string[] | undefined;
113
+ ingredients?: string | null | undefined;
114
+ nutritionalInfo?: import("@open-tender/types").NutritionalInfo | null | undefined;
115
+ cals?: number | null | undefined;
116
+ price?: number | undefined;
117
117
  price_total?: number | undefined;
118
- quantity: number;
118
+ quantity?: number | undefined;
119
119
  isDefault?: number | boolean | undefined;
120
- increment: number;
121
- max: number;
122
- min: number;
123
- isSoldOut: boolean;
124
- points: number;
120
+ increment?: number | undefined;
121
+ max?: number | undefined;
122
+ min?: number | undefined;
123
+ isSoldOut?: boolean | undefined;
124
+ points?: number | undefined;
125
125
  groups?: Partial<CartItemGroup>[] | undefined;
126
126
  }[] | undefined;
127
127
  id?: number | undefined;
@@ -346,25 +346,25 @@ export declare const validateCart: (cart: OrderCart, categories: MenuCategories,
346
346
  totalPrice: number;
347
347
  totalPoints: number;
348
348
  totalCals: number;
349
- id: number;
350
- name: string;
351
- shortName: string;
352
- description: string | null;
353
- imageUrl: string | null;
354
- allergens: string[];
355
- tags: string[];
356
- ingredients: string | null;
357
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
358
- cals: number | null;
359
- price: number;
349
+ id?: number | undefined;
350
+ name?: string | undefined;
351
+ shortName?: string | undefined;
352
+ description?: string | null | undefined;
353
+ imageUrl?: string | null | undefined;
354
+ allergens?: string[] | undefined;
355
+ tags?: string[] | undefined;
356
+ ingredients?: string | null | undefined;
357
+ nutritionalInfo?: import("@open-tender/types").NutritionalInfo | null | undefined;
358
+ cals?: number | null | undefined;
359
+ price?: number | undefined;
360
360
  price_total?: number | undefined;
361
- quantity: number;
361
+ quantity?: number | undefined;
362
362
  isDefault?: number | boolean | undefined;
363
- increment: number;
364
- max: number;
365
- min: number;
366
- isSoldOut: boolean;
367
- points: number;
363
+ increment?: number | undefined;
364
+ max?: number | undefined;
365
+ min?: number | undefined;
366
+ isSoldOut?: boolean | undefined;
367
+ points?: number | undefined;
368
368
  groups?: Partial<CartItemGroup>[] | undefined;
369
369
  }[] | undefined;
370
370
  id?: number | undefined;
@@ -29,7 +29,7 @@ export const getItemOptions = (item) => {
29
29
  if (!item.groups || !item.groups.length)
30
30
  return [];
31
31
  const options = item.groups
32
- .map(group => { var _a; return (_a = group.options) === null || _a === void 0 ? void 0 : _a.filter(option => option.quantity > 0); })
32
+ .map(group => { var _a; return (_a = group.options) === null || _a === void 0 ? void 0 : _a.filter(option => { var _a; return ((_a = option.quantity) !== null && _a !== void 0 ? _a : 0) > 0; }); })
33
33
  .reduce((arr, i) => [...(arr !== null && arr !== void 0 ? arr : []), ...(i !== null && i !== void 0 ? i : [])], []);
34
34
  return options;
35
35
  };
@@ -200,10 +200,10 @@ export const calcPrices = (item) => {
200
200
  var _a;
201
201
  let groupQuantity = 0;
202
202
  const options = (_a = g.options) === null || _a === void 0 ? void 0 : _a.map(o => {
203
- var _a, _b;
203
+ var _a, _b, _c, _d, _e;
204
204
  const includedRemaining = Math.max(((_a = g.included) !== null && _a !== void 0 ? _a : 0) - groupQuantity, 0);
205
- const priceQuantity = Math.max(o.quantity - includedRemaining, 0);
206
- const option = Object.assign(Object.assign({}, o), { totalPrice: priceQuantity * o.price, totalPoints: priceQuantity * ((_b = o.points) !== null && _b !== void 0 ? _b : 0), totalCals: o.cals ? o.quantity * o.cals : 0 });
205
+ const priceQuantity = Math.max(((_b = o.quantity) !== null && _b !== void 0 ? _b : 0) - includedRemaining, 0);
206
+ 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 });
207
207
  groupQuantity += o.quantity || 0;
208
208
  return option;
209
209
  });
@@ -281,8 +281,10 @@ export const rehydrateOrderItem = (menuItem, simpleCartItem) => {
281
281
  const simpleGroup = group.id ? groupsLookup[group.id] : null;
282
282
  if (simpleGroup) {
283
283
  (_a = group.options) === null || _a === void 0 ? void 0 : _a.forEach(option => {
284
- const simpleOption = simpleGroup.options[option.id];
285
- option.quantity = simpleOption ? simpleOption.quantity : 0;
284
+ if (option.id) {
285
+ const simpleOption = simpleGroup.options[option.id];
286
+ option.quantity = simpleOption ? simpleOption.quantity : 0;
287
+ }
286
288
  });
287
289
  }
288
290
  });
@@ -416,7 +418,7 @@ export const makeCartItemSignature = (item) => {
416
418
  : item.groups
417
419
  .reduce((arr, group) => {
418
420
  var _a;
419
- const ids = (_a = group.options) === null || _a === void 0 ? void 0 : _a.filter(o => o.quantity > 0).reduce((optionsArr, o) => {
421
+ const ids = (_a = 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) => {
420
422
  const optionArr = new Array(o.quantity);
421
423
  optionArr.fill(o.id);
422
424
  return [...optionsArr, ...optionArr];
@@ -617,7 +619,9 @@ const makeGroupsLookup = (item) => {
617
619
  return (_a = item.groups) === null || _a === void 0 ? void 0 : _a.reduce((grpObj, i) => {
618
620
  var _a;
619
621
  const options = (_a = i.options) === null || _a === void 0 ? void 0 : _a.reduce((optObj, o) => {
620
- optObj[o.id] = o;
622
+ if (o.id) {
623
+ optObj[o.id] = o;
624
+ }
621
625
  return optObj;
622
626
  }, {});
623
627
  if (i.id) {
@@ -1,4 +1,4 @@
1
- import { AvailableDates, CustomerRevenueCenter, ISOString, Order, GroupOrderTime, CustomerRevenueCenterSettings, ServiceType, Timezone, TimezonePython, Weekday, FirstTime, OrderTime, TimeInterval, ValidTimes, HolidayItem, DateString, TimeObject, DatePickerTimes } from '@open-tender/types';
1
+ import { AvailableDates, CustomerRevenueCenter, ISOString, Order, GroupOrderTime, CustomerRevenueCenterSettings, ServiceType, Timezone, TimezonePython, Weekday, FirstTime, OrderTime, TimeInterval, ValidTimes, HolidayItem, DateString, TimeObject, DatePickerTimes, OrderRevenueCenter } from '@open-tender/types';
2
2
  export declare const timezoneMap: {
3
3
  'US/Eastern': string;
4
4
  'US/Central': string;
@@ -174,7 +174,7 @@ export declare const makeFirstTimes: (revenueCenter: CustomerRevenueCenter, serv
174
174
  export declare const getNextInterval: (requestedAt: ISOString, tz: Timezone | TimezonePython, interval: number) => Date;
175
175
  export declare const adjustRequestedAt: (requestedAt: ISOString | string, tz: Timezone | TimezonePython, interval: number, leadTime: number) => ISOString;
176
176
  export declare const getFirstTime: (settings: CustomerRevenueCenterSettings, serviceType: ServiceType, tz: Timezone | TimezonePython) => OrderTime | FirstTime | null;
177
- export declare const makeGroupOrderTime: (revenueCenter: Partial<CustomerRevenueCenter>, serviceType: ServiceType, requestedAt: ISOString | string) => Partial<GroupOrderTime>;
177
+ export declare const makeGroupOrderTime: (revenueCenter: OrderRevenueCenter, serviceType: ServiceType, requestedAt: ISOString | string) => Partial<GroupOrderTime>;
178
178
  export declare const formatTime: (time: string) => string;
179
179
  export declare const makeGroupOrderTimeStr: (iso: ISOString, tz: Timezone | TimezonePython) => string | null;
180
180
  export declare const getLastInterval: (tz: Timezone | TimezonePython) => Date;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -57,7 +57,7 @@
57
57
  "react": "^18.2.0"
58
58
  },
59
59
  "dependencies": {
60
- "@open-tender/types": "^0.0.65",
60
+ "@open-tender/types": "^0.0.71",
61
61
  "date-fns": "^2.29.3",
62
62
  "date-fns-tz": "^1.3.7",
63
63
  "react-native-responsive-screen": "^1.4.2",