@open-tender/utils 0.4.7 → 0.4.9
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/utils/cart.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images, CartErrors, BaseItem, FavoritesLookup
|
|
1
|
+
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images, CartErrors, BaseItem, FavoritesLookup } from '@open-tender/types';
|
|
2
2
|
export declare const getItemOptions: <T extends BaseItem>(item: T) => BaseItem[];
|
|
3
3
|
export declare const makeModifierNames: <T extends BaseItem>(item: T) => string;
|
|
4
4
|
export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
|
|
5
5
|
export declare const makeModifierGroups: (groups: CartItemGroups) => [CartItemGroups, CartLevels];
|
|
6
6
|
export declare const makeUpsellItems: (itemIds: number[], itemLookup: Record<string, MenuItem>) => (CartItemOption | CartItem)[];
|
|
7
|
-
export declare const makeUpsellItemIds: (item: CartItem,
|
|
7
|
+
export declare const makeUpsellItemIds: (item: CartItem, cartIds: number[], soldOut: number[]) => number[];
|
|
8
|
+
export declare const makeUpsellItemsForCart: (categories: MenuCategories, cartIds: number[], soldOut: number[]) => (CartItemOption | CartItem)[];
|
|
8
9
|
export declare const calcNutrition: (item: CartItem | CartItemOption) => NutritionalInfoCalcs;
|
|
9
10
|
export declare const calcNutritionalInfo: (item: CartItem | CartItemOption) => NutritionalInfo;
|
|
10
11
|
export declare const calcPrices: (item: CartItem | CartItemOption) => CartItem | CartItemOption;
|
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeDeviceType = 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.compareCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.calcCartCounts = exports.makeOrderItem = exports.checkSoldOut = exports.calcPrices = exports.calcNutritionalInfo = exports.calcNutrition = exports.makeUpsellItemIds = exports.makeUpsellItems = exports.makeModifierGroups = exports.hasGroupsBelowMin = exports.makeModifierNames = exports.getItemOptions = void 0;
|
|
3
|
+
exports.makeDeviceType = 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.compareCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.calcCartCounts = exports.makeOrderItem = exports.checkSoldOut = exports.calcPrices = exports.calcNutritionalInfo = exports.calcNutrition = exports.makeUpsellItemsForCart = exports.makeUpsellItemIds = exports.makeUpsellItems = exports.makeModifierGroups = exports.hasGroupsBelowMin = exports.makeModifierNames = exports.getItemOptions = void 0;
|
|
4
4
|
const types_1 = require("@open-tender/types");
|
|
5
5
|
const helpers_1 = require("./helpers");
|
|
6
|
+
const favorites_1 = require("./favorites");
|
|
6
7
|
// TODO: refactor for nested mods (if needed)
|
|
7
8
|
const getItemOptions = (item) => {
|
|
8
9
|
if (!item.groups.length)
|
|
@@ -70,14 +71,22 @@ const makeUpsellItems = (itemIds, itemLookup) => {
|
|
|
70
71
|
});
|
|
71
72
|
};
|
|
72
73
|
exports.makeUpsellItems = makeUpsellItems;
|
|
73
|
-
const makeUpsellItemIds = (item,
|
|
74
|
-
var _a;
|
|
74
|
+
const makeUpsellItemIds = (item, cartIds, soldOut) => {
|
|
75
75
|
const upsellItems = item ? item.upsellItems : null;
|
|
76
|
-
return upsellItems
|
|
76
|
+
return upsellItems
|
|
77
77
|
? upsellItems.filter(id => !cartIds.includes(id) && !soldOut.includes(id))
|
|
78
78
|
: [];
|
|
79
79
|
};
|
|
80
80
|
exports.makeUpsellItemIds = makeUpsellItemIds;
|
|
81
|
+
const makeUpsellItemsForCart = (categories, cartIds, soldOut) => {
|
|
82
|
+
const itemLookup = (0, favorites_1.makeMenuItemLookup)(categories);
|
|
83
|
+
const menuItems = cartIds.map(id => itemLookup[id]);
|
|
84
|
+
const upsellItemIds = menuItems.reduce((arr, i) => [...arr, ...i.upsell_items], []);
|
|
85
|
+
const uniqueIds = Array.from(new Set(upsellItemIds));
|
|
86
|
+
const itemIds = uniqueIds.filter(id => !cartIds.includes(id) && !soldOut.includes(id));
|
|
87
|
+
return (0, exports.makeUpsellItems)(itemIds, itemLookup);
|
|
88
|
+
};
|
|
89
|
+
exports.makeUpsellItemsForCart = makeUpsellItemsForCart;
|
|
81
90
|
const nutritionKeys = [
|
|
82
91
|
'calories',
|
|
83
92
|
'cholesterol',
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DisplayItems, Favorites, MenuCategories, MenuItem, MenuItems, SoldOut } from '@open-tender/types';
|
|
2
|
-
export declare const makeMenuItemLookup: (categories: MenuCategories) =>
|
|
2
|
+
export declare const makeMenuItemLookup: (categories: MenuCategories) => {
|
|
3
|
+
[i: number]: MenuItem;
|
|
4
|
+
};
|
|
3
5
|
export declare const makeFeatured: (categories: MenuCategories) => MenuItem[];
|
|
4
6
|
export declare const makeMenuGroupsLookup: (menuItem: MenuItem) => any;
|
|
5
7
|
export declare const makeRecents: (recents: DisplayItems, itemLookup: Record<string, MenuItem>, soldOut: SoldOut) => MenuItems;
|
package/dist/esm/utils/cart.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images, CartErrors, BaseItem, FavoritesLookup
|
|
1
|
+
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images, CartErrors, BaseItem, FavoritesLookup } from '@open-tender/types';
|
|
2
2
|
export declare const getItemOptions: <T extends BaseItem>(item: T) => BaseItem[];
|
|
3
3
|
export declare const makeModifierNames: <T extends BaseItem>(item: T) => string;
|
|
4
4
|
export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
|
|
5
5
|
export declare const makeModifierGroups: (groups: CartItemGroups) => [CartItemGroups, CartLevels];
|
|
6
6
|
export declare const makeUpsellItems: (itemIds: number[], itemLookup: Record<string, MenuItem>) => (CartItemOption | CartItem)[];
|
|
7
|
-
export declare const makeUpsellItemIds: (item: CartItem,
|
|
7
|
+
export declare const makeUpsellItemIds: (item: CartItem, cartIds: number[], soldOut: number[]) => number[];
|
|
8
|
+
export declare const makeUpsellItemsForCart: (categories: MenuCategories, cartIds: number[], soldOut: number[]) => (CartItemOption | CartItem)[];
|
|
8
9
|
export declare const calcNutrition: (item: CartItem | CartItemOption) => NutritionalInfoCalcs;
|
|
9
10
|
export declare const calcNutritionalInfo: (item: CartItem | CartItemOption) => NutritionalInfo;
|
|
10
11
|
export declare const calcPrices: (item: CartItem | CartItemOption) => CartItem | CartItemOption;
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isCreditTender, isHouseAccountTender, isOrderCustomer } from '@open-tender/types';
|
|
2
2
|
import { convertStringToArray } from './helpers';
|
|
3
|
+
import { makeMenuItemLookup } from './favorites';
|
|
3
4
|
// TODO: refactor for nested mods (if needed)
|
|
4
5
|
export const getItemOptions = (item) => {
|
|
5
6
|
if (!item.groups.length)
|
|
@@ -62,13 +63,20 @@ export const makeUpsellItems = (itemIds, itemLookup) => {
|
|
|
62
63
|
return belowMin.length === 0;
|
|
63
64
|
});
|
|
64
65
|
};
|
|
65
|
-
export const makeUpsellItemIds = (item,
|
|
66
|
-
var _a;
|
|
66
|
+
export const makeUpsellItemIds = (item, cartIds, soldOut) => {
|
|
67
67
|
const upsellItems = item ? item.upsellItems : null;
|
|
68
|
-
return upsellItems
|
|
68
|
+
return upsellItems
|
|
69
69
|
? upsellItems.filter(id => !cartIds.includes(id) && !soldOut.includes(id))
|
|
70
70
|
: [];
|
|
71
71
|
};
|
|
72
|
+
export const makeUpsellItemsForCart = (categories, cartIds, soldOut) => {
|
|
73
|
+
const itemLookup = makeMenuItemLookup(categories);
|
|
74
|
+
const menuItems = cartIds.map(id => itemLookup[id]);
|
|
75
|
+
const upsellItemIds = menuItems.reduce((arr, i) => [...arr, ...i.upsell_items], []);
|
|
76
|
+
const uniqueIds = Array.from(new Set(upsellItemIds));
|
|
77
|
+
const itemIds = uniqueIds.filter(id => !cartIds.includes(id) && !soldOut.includes(id));
|
|
78
|
+
return makeUpsellItems(itemIds, itemLookup);
|
|
79
|
+
};
|
|
72
80
|
const nutritionKeys = [
|
|
73
81
|
'calories',
|
|
74
82
|
'cholesterol',
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DisplayItems, Favorites, MenuCategories, MenuItem, MenuItems, SoldOut } from '@open-tender/types';
|
|
2
|
-
export declare const makeMenuItemLookup: (categories: MenuCategories) =>
|
|
2
|
+
export declare const makeMenuItemLookup: (categories: MenuCategories) => {
|
|
3
|
+
[i: number]: MenuItem;
|
|
4
|
+
};
|
|
3
5
|
export declare const makeFeatured: (categories: MenuCategories) => MenuItem[];
|
|
4
6
|
export declare const makeMenuGroupsLookup: (menuItem: MenuItem) => any;
|
|
5
7
|
export declare const makeRecents: (recents: DisplayItems, itemLookup: Record<string, MenuItem>, soldOut: SoldOut) => MenuItems;
|
package/package.json
CHANGED
package/dist/.DS_Store
DELETED
|
Binary file
|