@open-tender/utils 0.4.6 → 0.4.7

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/.DS_Store ADDED
Binary file
@@ -1,9 +1,10 @@
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';
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, ConfigUpsell } 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, config: ConfigUpsell, cartIds: number[], soldOut: number[]) => number[];
7
8
  export declare const calcNutrition: (item: CartItem | CartItemOption) => NutritionalInfoCalcs;
8
9
  export declare const calcNutritionalInfo: (item: CartItem | CartItemOption) => NutritionalInfo;
9
10
  export declare const calcPrices: (item: CartItem | CartItemOption) => CartItem | CartItemOption;
@@ -1,6 +1,6 @@
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.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.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
6
  // TODO: refactor for nested mods (if needed)
@@ -70,6 +70,14 @@ const makeUpsellItems = (itemIds, itemLookup) => {
70
70
  });
71
71
  };
72
72
  exports.makeUpsellItems = makeUpsellItems;
73
+ const makeUpsellItemIds = (item, config, cartIds, soldOut) => {
74
+ var _a;
75
+ const upsellItems = item ? item.upsellItems : null;
76
+ return upsellItems && ((_a = config === null || config === void 0 ? void 0 : config.item) === null || _a === void 0 ? void 0 : _a.show)
77
+ ? upsellItems.filter(id => !cartIds.includes(id) && !soldOut.includes(id))
78
+ : [];
79
+ };
80
+ exports.makeUpsellItemIds = makeUpsellItemIds;
73
81
  const nutritionKeys = [
74
82
  'calories',
75
83
  'cholesterol',
@@ -378,7 +386,7 @@ const rehydrateTenders = (tenders) => {
378
386
  const rehydrateCheckoutForm = (order) => {
379
387
  const form = {
380
388
  details: rehydrateDetails(order.details),
381
- customer: (0, types_1.isOrderCustomer)(order.customer)
389
+ customer: order.customer && (0, types_1.isOrderCustomer)(order.customer)
382
390
  ? rehydrateCustomer(order.customer)
383
391
  : {},
384
392
  address: rehydrateAddress(order.address),
@@ -1,5 +1,5 @@
1
- import { OrderPos, PosOrderCart } from '@open-tender/types';
2
- export declare const makeRefundCartLookup: (cart: PosOrderCart) => {
1
+ import { Order, OrderCart } from '@open-tender/types';
2
+ export declare const makeRefundCartLookup: (cart: OrderCart) => {
3
3
  [key: number]: {
4
4
  quantity?: number | undefined;
5
5
  price_total?: `${number}.${number}` | undefined;
@@ -7,7 +7,7 @@ export declare const makeRefundCartLookup: (cart: PosOrderCart) => {
7
7
  };
8
8
  };
9
9
  export declare const makeAmountsLookup: (items: Array<any>, key?: string) => any;
10
- export declare const makeRefundLookup: (order: OrderPos) => {
10
+ export declare const makeRefundLookup: (order: Order) => {
11
11
  cart: {
12
12
  [key: number]: {
13
13
  quantity?: number | undefined;
@@ -32,4 +32,4 @@ export declare const makeRefundLookup: (order: OrderPos) => {
32
32
  export declare const adjustAmounts: (order: Record<string, any>, lookup: {
33
33
  [key: string]: any;
34
34
  }, list: string, key?: string) => Record<string, any>;
35
- export declare const makeNetOrder: (order: OrderPos, refunds: Array<OrderPos>) => any;
35
+ export declare const makeNetOrder: (order: Order, refunds: Array<Order>) => any;
@@ -24,7 +24,7 @@ const makeRefundLookup = (order) => {
24
24
  const { subtotal, gift_card, surcharge, discount, tax, tip, shipping, total } = totals;
25
25
  return {
26
26
  cart: (0, exports.makeRefundCartLookup)(cart),
27
- gift_cards: (0, exports.makeAmountsLookup)(gift_cards, 'code'),
27
+ gift_cards: gift_cards ? (0, exports.makeAmountsLookup)(gift_cards, 'code') : null,
28
28
  surcharges: (0, exports.makeAmountsLookup)(surcharges),
29
29
  discounts: (0, exports.makeAmountsLookup)(discounts),
30
30
  taxes: (0, exports.makeAmountsLookup)(taxes),
@@ -1,9 +1,10 @@
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';
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, ConfigUpsell } 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, config: ConfigUpsell, cartIds: number[], soldOut: number[]) => number[];
7
8
  export declare const calcNutrition: (item: CartItem | CartItemOption) => NutritionalInfoCalcs;
8
9
  export declare const calcNutritionalInfo: (item: CartItem | CartItemOption) => NutritionalInfo;
9
10
  export declare const calcPrices: (item: CartItem | CartItemOption) => CartItem | CartItemOption;
@@ -62,6 +62,13 @@ export const makeUpsellItems = (itemIds, itemLookup) => {
62
62
  return belowMin.length === 0;
63
63
  });
64
64
  };
65
+ export const makeUpsellItemIds = (item, config, cartIds, soldOut) => {
66
+ var _a;
67
+ const upsellItems = item ? item.upsellItems : null;
68
+ return upsellItems && ((_a = config === null || config === void 0 ? void 0 : config.item) === null || _a === void 0 ? void 0 : _a.show)
69
+ ? upsellItems.filter(id => !cartIds.includes(id) && !soldOut.includes(id))
70
+ : [];
71
+ };
65
72
  const nutritionKeys = [
66
73
  'calories',
67
74
  'cholesterol',
@@ -362,7 +369,7 @@ const rehydrateTenders = (tenders) => {
362
369
  export const rehydrateCheckoutForm = (order) => {
363
370
  const form = {
364
371
  details: rehydrateDetails(order.details),
365
- customer: isOrderCustomer(order.customer)
372
+ customer: order.customer && isOrderCustomer(order.customer)
366
373
  ? rehydrateCustomer(order.customer)
367
374
  : {},
368
375
  address: rehydrateAddress(order.address),
@@ -1,5 +1,5 @@
1
- import { OrderPos, PosOrderCart } from '@open-tender/types';
2
- export declare const makeRefundCartLookup: (cart: PosOrderCart) => {
1
+ import { Order, OrderCart } from '@open-tender/types';
2
+ export declare const makeRefundCartLookup: (cart: OrderCart) => {
3
3
  [key: number]: {
4
4
  quantity?: number | undefined;
5
5
  price_total?: `${number}.${number}` | undefined;
@@ -7,7 +7,7 @@ export declare const makeRefundCartLookup: (cart: PosOrderCart) => {
7
7
  };
8
8
  };
9
9
  export declare const makeAmountsLookup: (items: Array<any>, key?: string) => any;
10
- export declare const makeRefundLookup: (order: OrderPos) => {
10
+ export declare const makeRefundLookup: (order: Order) => {
11
11
  cart: {
12
12
  [key: number]: {
13
13
  quantity?: number | undefined;
@@ -32,4 +32,4 @@ export declare const makeRefundLookup: (order: OrderPos) => {
32
32
  export declare const adjustAmounts: (order: Record<string, any>, lookup: {
33
33
  [key: string]: any;
34
34
  }, list: string, key?: string) => Record<string, any>;
35
- export declare const makeNetOrder: (order: OrderPos, refunds: Array<OrderPos>) => any;
35
+ export declare const makeNetOrder: (order: Order, refunds: Array<Order>) => any;
@@ -19,7 +19,7 @@ export const makeRefundLookup = (order) => {
19
19
  const { subtotal, gift_card, surcharge, discount, tax, tip, shipping, total } = totals;
20
20
  return {
21
21
  cart: makeRefundCartLookup(cart),
22
- gift_cards: makeAmountsLookup(gift_cards, 'code'),
22
+ gift_cards: gift_cards ? makeAmountsLookup(gift_cards, 'code') : null,
23
23
  surcharges: makeAmountsLookup(surcharges),
24
24
  discounts: makeAmountsLookup(discounts),
25
25
  taxes: makeAmountsLookup(taxes),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
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,6 @@
36
36
  "private": false,
37
37
  "devDependencies": {
38
38
  "@emotion/react": "^11.10.4",
39
- "@open-tender/types": "^0.4.8",
40
39
  "@reduxjs/toolkit": "^1.8.5",
41
40
  "@types/google.maps": "^3.53.5",
42
41
  "@types/jest": "^29.5.11",
@@ -58,7 +57,7 @@
58
57
  "typescript": "^4.8.2"
59
58
  },
60
59
  "peerDependencies": {
61
- "@open-tender/types": "^0.4.5",
60
+ "@open-tender/types": "^0.4.22",
62
61
  "@reduxjs/toolkit": "^1.8.5",
63
62
  "react": "^18.2.0"
64
63
  },