@open-tender/utils 0.4.8 → 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.
@@ -5,6 +5,7 @@ export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups:
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
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;
@@ -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)
@@ -77,6 +78,15 @@ const makeUpsellItemIds = (item, cartIds, soldOut) => {
77
78
  : [];
78
79
  };
79
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;
80
90
  const nutritionKeys = [
81
91
  'calories',
82
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) => any;
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;
@@ -5,6 +5,7 @@ export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups:
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
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;
@@ -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)
@@ -68,6 +69,14 @@ export const makeUpsellItemIds = (item, cartIds, soldOut) => {
68
69
  ? upsellItems.filter(id => !cartIds.includes(id) && !soldOut.includes(id))
69
70
  : [];
70
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
+ };
71
80
  const nutritionKeys = [
72
81
  'calories',
73
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) => any;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
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",
package/dist/.DS_Store DELETED
Binary file