@open-tender/utils 0.1.6 → 0.1.8

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.
@@ -1,10 +1,11 @@
1
- import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels } from '@open-tender/types';
1
+ import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, OrderCart, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels, NutritionalInfo } from '@open-tender/types';
2
2
  export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[];
3
3
  export declare const makeModifierNames: (item: CartItem) => 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>) => (CartItem | CartItemOption)[];
7
7
  export declare const calcNutrition: (item: CartItem | CartItemOption) => NutritionalInfoCalcs;
8
+ export declare const calcNutritionalInfo: (item: CartItem | CartItemOption) => NutritionalInfo;
8
9
  export declare const calcPrices: (item: CartItem | CartItemOption) => CartItem | CartItemOption;
9
10
  export declare const checkSoldOut: (id: number, suspendUntil: number | null, soldOut?: number[]) => boolean;
10
11
  export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: SoldOut, simpleItem?: SimpleCartItem, hasPoints?: boolean) => CartItem | CartItemOption;
@@ -32,7 +33,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
32
33
  max: number;
33
34
  min: number;
34
35
  name: string;
35
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
36
+ nutritionalInfo: NutritionalInfo | null;
36
37
  points: number | null;
37
38
  price: number;
38
39
  quantity: number;
@@ -91,7 +92,7 @@ export declare const combineCarts: (cart: Cart, guestCart: SimpleCart, cartOwner
91
92
  max: number;
92
93
  min: number;
93
94
  name: string;
94
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
95
+ nutritionalInfo: NutritionalInfo | null;
95
96
  points: number | null;
96
97
  price: number;
97
98
  quantity: number;
@@ -148,6 +149,13 @@ export declare const makeSimpleCart: (cart: Cart) => {
148
149
  made_for: string;
149
150
  notes: string;
150
151
  }[];
152
+ export declare const makeSimpleCartFromOrder: (cart: OrderCart) => {
153
+ id: number;
154
+ quantity: number;
155
+ groups: SimpleCartGroups;
156
+ made_for: string;
157
+ notes: string;
158
+ }[];
151
159
  export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut) => {
152
160
  newCart: (CartItem | CartItemOption | null)[];
153
161
  errors: {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.calcCartCounts = exports.makeOrderItem = exports.checkSoldOut = exports.calcPrices = exports.calcNutrition = exports.makeUpsellItems = exports.makeModifierGroups = exports.hasGroupsBelowMin = exports.makeModifierNames = exports.getItemOptions = void 0;
3
+ exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCartFromOrder = 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.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;
4
4
  const helpers_1 = require("./helpers");
5
5
  // TODO: refactor for nested mods
6
6
  const getItemOptions = (item) => {
@@ -92,6 +92,12 @@ const calcNutrition = (item) => {
92
92
  return nutrition;
93
93
  };
94
94
  exports.calcNutrition = calcNutrition;
95
+ const calcNutritionalInfo = (item) => {
96
+ const nutrition = (0, exports.calcNutrition)(item);
97
+ const { serving_size = '0.00' } = item.nutritionalInfo || {};
98
+ return Object.assign(Object.assign({}, nutrition), { serving_size });
99
+ };
100
+ exports.calcNutritionalInfo = calcNutritionalInfo;
95
101
  const calcPrices = (item) => {
96
102
  const groups = item.groups.map(g => {
97
103
  let groupQuantity = 0;
@@ -597,6 +603,31 @@ const makeSimpleCart = (cart) => {
597
603
  return simpleCart;
598
604
  };
599
605
  exports.makeSimpleCart = makeSimpleCart;
606
+ const makeSimpleGroupsFromOrder = (groups) => {
607
+ return groups.map(g => {
608
+ const options = g.options
609
+ .filter(o => o.quantity !== 0)
610
+ .map(o => ({
611
+ id: o.id,
612
+ quantity: o.quantity,
613
+ groups: makeSimpleGroupsFromOrder(o.groups || [])
614
+ }));
615
+ return { id: g.id, options: options };
616
+ });
617
+ };
618
+ const makeSimpleCartFromOrder = (cart) => {
619
+ const simpleCart = cart.map(i => {
620
+ return {
621
+ id: i.id,
622
+ quantity: i.quantity,
623
+ groups: makeSimpleGroupsFromOrder(i.groups),
624
+ made_for: i.made_for || '',
625
+ notes: i.notes || ''
626
+ };
627
+ });
628
+ return simpleCart;
629
+ };
630
+ exports.makeSimpleCartFromOrder = makeSimpleCartFromOrder;
600
631
  /* cart validation */
601
632
  // TODO: refactor for nested modifiers
602
633
  // convert menu items to order items for validation but only include
@@ -1,10 +1,11 @@
1
- import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels } from '@open-tender/types';
1
+ import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, OrderCart, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels, NutritionalInfo } from '@open-tender/types';
2
2
  export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[];
3
3
  export declare const makeModifierNames: (item: CartItem) => 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>) => (CartItem | CartItemOption)[];
7
7
  export declare const calcNutrition: (item: CartItem | CartItemOption) => NutritionalInfoCalcs;
8
+ export declare const calcNutritionalInfo: (item: CartItem | CartItemOption) => NutritionalInfo;
8
9
  export declare const calcPrices: (item: CartItem | CartItemOption) => CartItem | CartItemOption;
9
10
  export declare const checkSoldOut: (id: number, suspendUntil: number | null, soldOut?: number[]) => boolean;
10
11
  export declare const makeOrderItem: (item: MenuItem, isEdit?: boolean, soldOut?: SoldOut, simpleItem?: SimpleCartItem, hasPoints?: boolean) => CartItem | CartItemOption;
@@ -32,7 +33,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
32
33
  max: number;
33
34
  min: number;
34
35
  name: string;
35
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
36
+ nutritionalInfo: NutritionalInfo | null;
36
37
  points: number | null;
37
38
  price: number;
38
39
  quantity: number;
@@ -91,7 +92,7 @@ export declare const combineCarts: (cart: Cart, guestCart: SimpleCart, cartOwner
91
92
  max: number;
92
93
  min: number;
93
94
  name: string;
94
- nutritionalInfo: import("@open-tender/types").NutritionalInfo | null;
95
+ nutritionalInfo: NutritionalInfo | null;
95
96
  points: number | null;
96
97
  price: number;
97
98
  quantity: number;
@@ -148,6 +149,13 @@ export declare const makeSimpleCart: (cart: Cart) => {
148
149
  made_for: string;
149
150
  notes: string;
150
151
  }[];
152
+ export declare const makeSimpleCartFromOrder: (cart: OrderCart) => {
153
+ id: number;
154
+ quantity: number;
155
+ groups: SimpleCartGroups;
156
+ made_for: string;
157
+ notes: string;
158
+ }[];
151
159
  export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut) => {
152
160
  newCart: (CartItem | CartItemOption | null)[];
153
161
  errors: {
@@ -83,6 +83,11 @@ export const calcNutrition = (item) => {
83
83
  });
84
84
  return nutrition;
85
85
  };
86
+ export const calcNutritionalInfo = (item) => {
87
+ const nutrition = calcNutrition(item);
88
+ const { serving_size = '0.00' } = item.nutritionalInfo || {};
89
+ return Object.assign(Object.assign({}, nutrition), { serving_size });
90
+ };
86
91
  export const calcPrices = (item) => {
87
92
  const groups = item.groups.map(g => {
88
93
  let groupQuantity = 0;
@@ -566,6 +571,30 @@ export const makeSimpleCart = (cart) => {
566
571
  });
567
572
  return simpleCart;
568
573
  };
574
+ const makeSimpleGroupsFromOrder = (groups) => {
575
+ return groups.map(g => {
576
+ const options = g.options
577
+ .filter(o => o.quantity !== 0)
578
+ .map(o => ({
579
+ id: o.id,
580
+ quantity: o.quantity,
581
+ groups: makeSimpleGroupsFromOrder(o.groups || [])
582
+ }));
583
+ return { id: g.id, options: options };
584
+ });
585
+ };
586
+ export const makeSimpleCartFromOrder = (cart) => {
587
+ const simpleCart = cart.map(i => {
588
+ return {
589
+ id: i.id,
590
+ quantity: i.quantity,
591
+ groups: makeSimpleGroupsFromOrder(i.groups),
592
+ made_for: i.made_for || '',
593
+ notes: i.notes || ''
594
+ };
595
+ });
596
+ return simpleCart;
597
+ };
569
598
  /* cart validation */
570
599
  // TODO: refactor for nested modifiers
571
600
  // convert menu items to order items for validation but only include
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
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",