@open-tender/utils 0.4.24 → 0.4.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/useMenuItem.d.ts +1 -0
- package/dist/cjs/hooks/useMenuItem.js +2 -1
- package/dist/cjs/hooks/useModifier.d.ts +1 -0
- package/dist/cjs/hooks/useOrderItem.d.ts +1 -0
- package/dist/cjs/utils/cart.d.ts +2 -0
- package/dist/cjs/utils/cart.js +13 -1
- package/dist/cjs/utils/checkout.d.ts +6 -6
- package/dist/esm/hooks/useMenuItem.d.ts +1 -0
- package/dist/esm/hooks/useMenuItem.js +2 -1
- package/dist/esm/hooks/useModifier.d.ts +1 -0
- package/dist/esm/hooks/useOrderItem.d.ts +1 -0
- package/dist/esm/utils/cart.d.ts +2 -0
- package/dist/esm/utils/cart.js +13 -1
- package/dist/esm/utils/checkout.d.ts +6 -6
- package/package.json +2 -2
- package/dist/.DS_Store +0 -0
|
@@ -6,6 +6,7 @@ export declare const useMenuItem: (builtItem: CartItem, auth: Auth | null, looku
|
|
|
6
6
|
displayPrice: string;
|
|
7
7
|
displayCals: number | null;
|
|
8
8
|
totalPoints: number | null;
|
|
9
|
+
totalAllergens: string[];
|
|
9
10
|
auth: Auth | null;
|
|
10
11
|
favoriteId: number | null;
|
|
11
12
|
isIncomplete: boolean;
|
|
@@ -6,7 +6,7 @@ const useMenuItem = (builtItem, auth, lookup, cartId, displaySettings) => {
|
|
|
6
6
|
const signature = (0, utils_1.makeItemSignature)(builtItem);
|
|
7
7
|
const favoriteId = lookup && signature ? lookup[signature] : null;
|
|
8
8
|
const { calories: showCals = false, tags: showTags = false, allergens: showAllergens = false, madeFor: showMadeFor = true, notes: showNotes = true } = displaySettings || {};
|
|
9
|
-
const { description, quantity, price, totalPrice, cals, totalCals, totalPoints, tags, allergens, groups, ingredients } = builtItem;
|
|
9
|
+
const { description, quantity, price, totalPrice, cals, totalCals, totalPoints, tags, allergens, groups, ingredients, totalAllergens } = builtItem;
|
|
10
10
|
const hasTags = showTags && Array.isArray(tags) && tags.length ? true : false;
|
|
11
11
|
const hasAllergens = showAllergens && Array.isArray(allergens) && allergens.length ? true : false;
|
|
12
12
|
const hasTagsAllergens = hasTags || hasAllergens ? true : false;
|
|
@@ -45,6 +45,7 @@ const useMenuItem = (builtItem, auth, lookup, cartId, displaySettings) => {
|
|
|
45
45
|
displayPrice,
|
|
46
46
|
displayCals,
|
|
47
47
|
totalPoints,
|
|
48
|
+
totalAllergens,
|
|
48
49
|
auth,
|
|
49
50
|
favoriteId,
|
|
50
51
|
isIncomplete,
|
|
@@ -43,6 +43,7 @@ export declare const useModifier: (group: CartItemGroup, option: CartItemOption,
|
|
|
43
43
|
shortDescription: string | null;
|
|
44
44
|
shortName: string;
|
|
45
45
|
slug: string;
|
|
46
|
+
totalAllergens: string[];
|
|
46
47
|
totalCals: number | null;
|
|
47
48
|
totalPoints: number | null;
|
|
48
49
|
totalPrice: number | null;
|
package/dist/cjs/utils/cart.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
|
|
|
44
44
|
shortName: string;
|
|
45
45
|
slug: string;
|
|
46
46
|
tags: string[];
|
|
47
|
+
totalAllergens: string[];
|
|
47
48
|
totalCals: number | null;
|
|
48
49
|
totalPoints: number | null;
|
|
49
50
|
totalPrice: number | null;
|
|
@@ -130,6 +131,7 @@ export declare const combineCarts: (cart: Cart, guestCart: Cart, cartOwner: Cart
|
|
|
130
131
|
shortName: string;
|
|
131
132
|
slug: string;
|
|
132
133
|
tags: string[];
|
|
134
|
+
totalAllergens: string[];
|
|
133
135
|
totalCals: number | null;
|
|
134
136
|
totalPoints: number | null;
|
|
135
137
|
totalPrice: number | null;
|
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -178,7 +178,15 @@ const calcPrices = (item) => {
|
|
|
178
178
|
const totalCals = item.cals || item.cals === 0
|
|
179
179
|
? item.quantity * (item.cals + optionsCals)
|
|
180
180
|
: null;
|
|
181
|
-
|
|
181
|
+
const nonSizeGroups = groups ? groups.filter(i => !i.isSize) : null;
|
|
182
|
+
const currentOptions = nonSizeGroups
|
|
183
|
+
? (0, exports.getItemOptions)(Object.assign(Object.assign({}, item), { groups: nonSizeGroups }))
|
|
184
|
+
: [];
|
|
185
|
+
const modifiersAllergens = currentOptions.reduce((t, o) => {
|
|
186
|
+
return [...t, ...o.allergens];
|
|
187
|
+
}, []);
|
|
188
|
+
const totalAllergens = [...new Set(item.allergens.concat(modifiersAllergens))];
|
|
189
|
+
return Object.assign(Object.assign({}, item), { groups, totalPrice, totalPoints, totalCals, totalAllergens });
|
|
182
190
|
};
|
|
183
191
|
exports.calcPrices = calcPrices;
|
|
184
192
|
const checkSoldOut = (id, suspendUntil, soldOut = []) => {
|
|
@@ -221,10 +229,12 @@ const makeOrderItemGroups = (optionGroups, isEdit, soldOut = []) => {
|
|
|
221
229
|
points: o.points || 0,
|
|
222
230
|
price: parseFloat(o.price),
|
|
223
231
|
quantity: quantity,
|
|
232
|
+
shorthand: o.shorthand,
|
|
224
233
|
shortDescription: o.short_description,
|
|
225
234
|
shortName: o.short_name,
|
|
226
235
|
slug: o.slug,
|
|
227
236
|
tags: (0, helpers_1.convertStringToArray)(o.tags),
|
|
237
|
+
totalAllergens: [],
|
|
228
238
|
totalCals: null,
|
|
229
239
|
totalPoints: null,
|
|
230
240
|
totalPrice: null
|
|
@@ -274,11 +284,13 @@ const makeOrderItem = (item, isEdit, soldOut = [], simpleItem, hasPoints = false
|
|
|
274
284
|
points: hasPoints ? item.points || null : null,
|
|
275
285
|
price: parseFloat(item.price),
|
|
276
286
|
quantity: item.min_quantity || 1 * item.increment,
|
|
287
|
+
shorthand: item.shorthand,
|
|
277
288
|
shortDescription: item.short_description,
|
|
278
289
|
shortName: item.short_name,
|
|
279
290
|
similarItems: item.similar_items,
|
|
280
291
|
slug: item.slug,
|
|
281
292
|
tags: (0, helpers_1.convertStringToArray)(item.tags),
|
|
293
|
+
totalAllergens: [],
|
|
282
294
|
totalCals: null,
|
|
283
295
|
totalPoints: null,
|
|
284
296
|
totalPrice: null,
|
|
@@ -16,12 +16,12 @@ export declare const updateTenders: (tenders: CheckoutTenders, total: Money) =>
|
|
|
16
16
|
zip: string;
|
|
17
17
|
} | {
|
|
18
18
|
amount: string;
|
|
19
|
-
card_type
|
|
20
|
-
card_type_name
|
|
19
|
+
card_type?: import("@open-tender/types").CardType | undefined;
|
|
20
|
+
card_type_name?: import("@open-tender/types").CardTypeName | undefined;
|
|
21
21
|
customer_card_id: number;
|
|
22
|
-
is_default
|
|
23
|
-
last4
|
|
24
|
-
masked
|
|
22
|
+
is_default?: boolean | undefined;
|
|
23
|
+
last4?: string | undefined;
|
|
24
|
+
masked?: string | undefined;
|
|
25
25
|
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
26
26
|
tender_type: import("@open-tender/types").TenderType;
|
|
27
27
|
} | {
|
|
@@ -50,4 +50,4 @@ export declare const updateTenders: (tenders: CheckoutTenders, total: Money) =>
|
|
|
50
50
|
})[] | null;
|
|
51
51
|
export declare const makeCreditCardName: (creditCard: CreditCard) => string;
|
|
52
52
|
export declare const makeTenderName: (tender: OrderTender) => string;
|
|
53
|
-
export declare const makeCheckoutTenderName: (tender: CheckoutTender) => string;
|
|
53
|
+
export declare const makeCheckoutTenderName: (tender: CheckoutTender) => string | undefined;
|
|
@@ -6,6 +6,7 @@ export declare const useMenuItem: (builtItem: CartItem, auth: Auth | null, looku
|
|
|
6
6
|
displayPrice: string;
|
|
7
7
|
displayCals: number | null;
|
|
8
8
|
totalPoints: number | null;
|
|
9
|
+
totalAllergens: string[];
|
|
9
10
|
auth: Auth | null;
|
|
10
11
|
favoriteId: number | null;
|
|
11
12
|
isIncomplete: boolean;
|
|
@@ -3,7 +3,7 @@ export const useMenuItem = (builtItem, auth, lookup, cartId, displaySettings) =>
|
|
|
3
3
|
const signature = makeItemSignature(builtItem);
|
|
4
4
|
const favoriteId = lookup && signature ? lookup[signature] : null;
|
|
5
5
|
const { calories: showCals = false, tags: showTags = false, allergens: showAllergens = false, madeFor: showMadeFor = true, notes: showNotes = true } = displaySettings || {};
|
|
6
|
-
const { description, quantity, price, totalPrice, cals, totalCals, totalPoints, tags, allergens, groups, ingredients } = builtItem;
|
|
6
|
+
const { description, quantity, price, totalPrice, cals, totalCals, totalPoints, tags, allergens, groups, ingredients, totalAllergens } = builtItem;
|
|
7
7
|
const hasTags = showTags && Array.isArray(tags) && tags.length ? true : false;
|
|
8
8
|
const hasAllergens = showAllergens && Array.isArray(allergens) && allergens.length ? true : false;
|
|
9
9
|
const hasTagsAllergens = hasTags || hasAllergens ? true : false;
|
|
@@ -42,6 +42,7 @@ export const useMenuItem = (builtItem, auth, lookup, cartId, displaySettings) =>
|
|
|
42
42
|
displayPrice,
|
|
43
43
|
displayCals,
|
|
44
44
|
totalPoints,
|
|
45
|
+
totalAllergens,
|
|
45
46
|
auth,
|
|
46
47
|
favoriteId,
|
|
47
48
|
isIncomplete,
|
|
@@ -43,6 +43,7 @@ export declare const useModifier: (group: CartItemGroup, option: CartItemOption,
|
|
|
43
43
|
shortDescription: string | null;
|
|
44
44
|
shortName: string;
|
|
45
45
|
slug: string;
|
|
46
|
+
totalAllergens: string[];
|
|
46
47
|
totalCals: number | null;
|
|
47
48
|
totalPoints: number | null;
|
|
48
49
|
totalPrice: number | null;
|
package/dist/esm/utils/cart.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
|
|
|
44
44
|
shortName: string;
|
|
45
45
|
slug: string;
|
|
46
46
|
tags: string[];
|
|
47
|
+
totalAllergens: string[];
|
|
47
48
|
totalCals: number | null;
|
|
48
49
|
totalPoints: number | null;
|
|
49
50
|
totalPrice: number | null;
|
|
@@ -130,6 +131,7 @@ export declare const combineCarts: (cart: Cart, guestCart: Cart, cartOwner: Cart
|
|
|
130
131
|
shortName: string;
|
|
131
132
|
slug: string;
|
|
132
133
|
tags: string[];
|
|
134
|
+
totalAllergens: string[];
|
|
133
135
|
totalCals: number | null;
|
|
134
136
|
totalPoints: number | null;
|
|
135
137
|
totalPrice: number | null;
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -165,7 +165,15 @@ export const calcPrices = (item) => {
|
|
|
165
165
|
const totalCals = item.cals || item.cals === 0
|
|
166
166
|
? item.quantity * (item.cals + optionsCals)
|
|
167
167
|
: null;
|
|
168
|
-
|
|
168
|
+
const nonSizeGroups = groups ? groups.filter(i => !i.isSize) : null;
|
|
169
|
+
const currentOptions = nonSizeGroups
|
|
170
|
+
? getItemOptions(Object.assign(Object.assign({}, item), { groups: nonSizeGroups }))
|
|
171
|
+
: [];
|
|
172
|
+
const modifiersAllergens = currentOptions.reduce((t, o) => {
|
|
173
|
+
return [...t, ...o.allergens];
|
|
174
|
+
}, []);
|
|
175
|
+
const totalAllergens = [...new Set(item.allergens.concat(modifiersAllergens))];
|
|
176
|
+
return Object.assign(Object.assign({}, item), { groups, totalPrice, totalPoints, totalCals, totalAllergens });
|
|
169
177
|
};
|
|
170
178
|
export const checkSoldOut = (id, suspendUntil, soldOut = []) => {
|
|
171
179
|
if (soldOut.includes(id))
|
|
@@ -206,10 +214,12 @@ const makeOrderItemGroups = (optionGroups, isEdit, soldOut = []) => {
|
|
|
206
214
|
points: o.points || 0,
|
|
207
215
|
price: parseFloat(o.price),
|
|
208
216
|
quantity: quantity,
|
|
217
|
+
shorthand: o.shorthand,
|
|
209
218
|
shortDescription: o.short_description,
|
|
210
219
|
shortName: o.short_name,
|
|
211
220
|
slug: o.slug,
|
|
212
221
|
tags: convertStringToArray(o.tags),
|
|
222
|
+
totalAllergens: [],
|
|
213
223
|
totalCals: null,
|
|
214
224
|
totalPoints: null,
|
|
215
225
|
totalPrice: null
|
|
@@ -259,11 +269,13 @@ export const makeOrderItem = (item, isEdit, soldOut = [], simpleItem, hasPoints
|
|
|
259
269
|
points: hasPoints ? item.points || null : null,
|
|
260
270
|
price: parseFloat(item.price),
|
|
261
271
|
quantity: item.min_quantity || 1 * item.increment,
|
|
272
|
+
shorthand: item.shorthand,
|
|
262
273
|
shortDescription: item.short_description,
|
|
263
274
|
shortName: item.short_name,
|
|
264
275
|
similarItems: item.similar_items,
|
|
265
276
|
slug: item.slug,
|
|
266
277
|
tags: convertStringToArray(item.tags),
|
|
278
|
+
totalAllergens: [],
|
|
267
279
|
totalCals: null,
|
|
268
280
|
totalPoints: null,
|
|
269
281
|
totalPrice: null,
|
|
@@ -16,12 +16,12 @@ export declare const updateTenders: (tenders: CheckoutTenders, total: Money) =>
|
|
|
16
16
|
zip: string;
|
|
17
17
|
} | {
|
|
18
18
|
amount: string;
|
|
19
|
-
card_type
|
|
20
|
-
card_type_name
|
|
19
|
+
card_type?: import("@open-tender/types").CardType | undefined;
|
|
20
|
+
card_type_name?: import("@open-tender/types").CardTypeName | undefined;
|
|
21
21
|
customer_card_id: number;
|
|
22
|
-
is_default
|
|
23
|
-
last4
|
|
24
|
-
masked
|
|
22
|
+
is_default?: boolean | undefined;
|
|
23
|
+
last4?: string | undefined;
|
|
24
|
+
masked?: string | undefined;
|
|
25
25
|
tender_status?: import("@open-tender/types").TenderStatus | undefined;
|
|
26
26
|
tender_type: import("@open-tender/types").TenderType;
|
|
27
27
|
} | {
|
|
@@ -50,4 +50,4 @@ export declare const updateTenders: (tenders: CheckoutTenders, total: Money) =>
|
|
|
50
50
|
})[] | null;
|
|
51
51
|
export declare const makeCreditCardName: (creditCard: CreditCard) => string;
|
|
52
52
|
export declare const makeTenderName: (tender: OrderTender) => string;
|
|
53
|
-
export declare const makeCheckoutTenderName: (tender: CheckoutTender) => string;
|
|
53
|
+
export declare const makeCheckoutTenderName: (tender: CheckoutTender) => string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.26",
|
|
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",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"private": false,
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@emotion/react": "^11.10.4",
|
|
39
|
-
"@open-tender/types": "^0.4.
|
|
39
|
+
"@open-tender/types": "^0.4.47",
|
|
40
40
|
"@reduxjs/toolkit": "^1.8.5",
|
|
41
41
|
"@types/google.maps": "^3.53.5",
|
|
42
42
|
"@types/jest": "^29.5.11",
|
package/dist/.DS_Store
DELETED
|
Binary file
|