@open-tender/utils 0.4.6 → 0.4.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.
- package/dist/.DS_Store +0 -0
- package/dist/cjs/utils/cart.d.ts +1 -0
- package/dist/cjs/utils/cart.js +9 -2
- package/dist/cjs/utils/refunds.d.ts +4 -4
- package/dist/cjs/utils/refunds.js +1 -1
- package/dist/esm/utils/cart.d.ts +1 -0
- package/dist/esm/utils/cart.js +7 -1
- package/dist/esm/utils/refunds.d.ts +4 -4
- package/dist/esm/utils/refunds.js +1 -1
- package/package.json +2 -3
package/dist/.DS_Store
ADDED
|
Binary file
|
package/dist/cjs/utils/cart.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ 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, 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;
|
package/dist/cjs/utils/cart.js
CHANGED
|
@@ -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,13 @@ const makeUpsellItems = (itemIds, itemLookup) => {
|
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
72
|
exports.makeUpsellItems = makeUpsellItems;
|
|
73
|
+
const makeUpsellItemIds = (item, cartIds, soldOut) => {
|
|
74
|
+
const upsellItems = item ? item.upsellItems : null;
|
|
75
|
+
return upsellItems
|
|
76
|
+
? upsellItems.filter(id => !cartIds.includes(id) && !soldOut.includes(id))
|
|
77
|
+
: [];
|
|
78
|
+
};
|
|
79
|
+
exports.makeUpsellItemIds = makeUpsellItemIds;
|
|
73
80
|
const nutritionKeys = [
|
|
74
81
|
'calories',
|
|
75
82
|
'cholesterol',
|
|
@@ -378,7 +385,7 @@ const rehydrateTenders = (tenders) => {
|
|
|
378
385
|
const rehydrateCheckoutForm = (order) => {
|
|
379
386
|
const form = {
|
|
380
387
|
details: rehydrateDetails(order.details),
|
|
381
|
-
customer: (0, types_1.isOrderCustomer)(order.customer)
|
|
388
|
+
customer: order.customer && (0, types_1.isOrderCustomer)(order.customer)
|
|
382
389
|
? rehydrateCustomer(order.customer)
|
|
383
390
|
: {},
|
|
384
391
|
address: rehydrateAddress(order.address),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const makeRefundCartLookup: (cart:
|
|
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:
|
|
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:
|
|
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),
|
package/dist/esm/utils/cart.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ 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, 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;
|
package/dist/esm/utils/cart.js
CHANGED
|
@@ -62,6 +62,12 @@ export const makeUpsellItems = (itemIds, itemLookup) => {
|
|
|
62
62
|
return belowMin.length === 0;
|
|
63
63
|
});
|
|
64
64
|
};
|
|
65
|
+
export const makeUpsellItemIds = (item, cartIds, soldOut) => {
|
|
66
|
+
const upsellItems = item ? item.upsellItems : null;
|
|
67
|
+
return upsellItems
|
|
68
|
+
? upsellItems.filter(id => !cartIds.includes(id) && !soldOut.includes(id))
|
|
69
|
+
: [];
|
|
70
|
+
};
|
|
65
71
|
const nutritionKeys = [
|
|
66
72
|
'calories',
|
|
67
73
|
'cholesterol',
|
|
@@ -362,7 +368,7 @@ const rehydrateTenders = (tenders) => {
|
|
|
362
368
|
export const rehydrateCheckoutForm = (order) => {
|
|
363
369
|
const form = {
|
|
364
370
|
details: rehydrateDetails(order.details),
|
|
365
|
-
customer: isOrderCustomer(order.customer)
|
|
371
|
+
customer: order.customer && isOrderCustomer(order.customer)
|
|
366
372
|
? rehydrateCustomer(order.customer)
|
|
367
373
|
: {},
|
|
368
374
|
address: rehydrateAddress(order.address),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const makeRefundCartLookup: (cart:
|
|
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:
|
|
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:
|
|
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.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -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.
|
|
60
|
+
"@open-tender/types": "^0.4.22",
|
|
62
61
|
"@reduxjs/toolkit": "^1.8.5",
|
|
63
62
|
"react": "^18.2.0"
|
|
64
63
|
},
|