@open-tender/utils 0.4.10 → 0.4.12
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/favorites.d.ts +3 -1
- package/dist/cjs/utils/favorites.js +13 -1
- package/dist/cjs/utils/rewards.d.ts +3 -1
- package/dist/cjs/utils/rewards.js +71 -1
- package/dist/esm/utils/favorites.d.ts +3 -1
- package/dist/esm/utils/favorites.js +10 -0
- package/dist/esm/utils/rewards.d.ts +3 -1
- package/dist/esm/utils/rewards.js +69 -1
- package/package.json +2 -2
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { DisplayItems, Favorites, MenuCategories, MenuItem, MenuItems, SoldOut } from '@open-tender/types';
|
|
1
|
+
import { DisplayItems, Favorites, MenuCategories, MenuItem, MenuItems, Orders, SoldOut } from '@open-tender/types';
|
|
2
2
|
export declare const makeMenuItemLookup: (categories: MenuCategories) => {
|
|
3
3
|
[i: number]: MenuItem;
|
|
4
4
|
};
|
|
5
5
|
export declare const makeFeatured: (categories: MenuCategories) => MenuItem[];
|
|
6
6
|
export declare const makeMenuGroupsLookup: (menuItem: MenuItem) => any;
|
|
7
7
|
export declare const makeRecents: (recents: DisplayItems, itemLookup: Record<string, MenuItem>, soldOut: SoldOut) => MenuItems;
|
|
8
|
+
export declare const makeRecentItems: (categories: MenuCategories, orders: Orders, soldOut: SoldOut) => MenuItems;
|
|
8
9
|
export declare const makeFavorites: (favorites: Favorites, itemLookup: Record<string, MenuItem>, soldOut: SoldOut) => MenuItems;
|
|
10
|
+
export declare const makeFavoriteItems: (categories: MenuCategories, favorites: Favorites, soldOut: SoldOut) => MenuItems;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeFavorites = exports.makeRecents = exports.makeMenuGroupsLookup = exports.makeFeatured = exports.makeMenuItemLookup = void 0;
|
|
3
|
+
exports.makeFavoriteItems = exports.makeFavorites = exports.makeRecentItems = exports.makeRecents = exports.makeMenuGroupsLookup = exports.makeFeatured = exports.makeMenuItemLookup = void 0;
|
|
4
|
+
const cart_1 = require("./cart");
|
|
4
5
|
const makeMenuItemLookup = (categories) => {
|
|
5
6
|
const cats = categories.reduce((arr, cat) => {
|
|
6
7
|
return [...arr, cat, ...(cat.children || [])];
|
|
@@ -84,6 +85,12 @@ const makeRecents = (recents, itemLookup, soldOut) => {
|
|
|
84
85
|
}, []);
|
|
85
86
|
};
|
|
86
87
|
exports.makeRecents = makeRecents;
|
|
88
|
+
const makeRecentItems = (categories, orders, soldOut) => {
|
|
89
|
+
const itemLookup = (0, exports.makeMenuItemLookup)(categories);
|
|
90
|
+
const displayItems = (0, cart_1.makeUniqueDisplayItems)(orders);
|
|
91
|
+
return (0, exports.makeRecents)(displayItems, itemLookup, soldOut);
|
|
92
|
+
};
|
|
93
|
+
exports.makeRecentItems = makeRecentItems;
|
|
87
94
|
const makeFavorites = (favorites, itemLookup, soldOut) => {
|
|
88
95
|
return favorites.reduce((arr, favorite) => {
|
|
89
96
|
var _a, _b;
|
|
@@ -101,3 +108,8 @@ const makeFavorites = (favorites, itemLookup, soldOut) => {
|
|
|
101
108
|
}, []);
|
|
102
109
|
};
|
|
103
110
|
exports.makeFavorites = makeFavorites;
|
|
111
|
+
const makeFavoriteItems = (categories, favorites, soldOut) => {
|
|
112
|
+
const itemLookup = (0, exports.makeMenuItemLookup)(categories);
|
|
113
|
+
return (0, exports.makeFavorites)(favorites, itemLookup, soldOut);
|
|
114
|
+
};
|
|
115
|
+
exports.makeFavoriteItems = makeFavoriteItems;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
1
|
+
import { Discount, DiscountEnhanced, Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
2
2
|
export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
|
|
3
|
+
export declare const makeLimitations: (item: Discount) => string;
|
|
4
|
+
export declare const makeDiscountEnhanced: (item: Discount) => DiscountEnhanced;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeValidDeals = void 0;
|
|
3
|
+
exports.makeDiscountEnhanced = exports.makeLimitations = exports.makeValidDeals = void 0;
|
|
4
4
|
const datetimes_1 = require("./datetimes");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
5
6
|
const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
6
7
|
if (!deals || !deals.length)
|
|
7
8
|
return [];
|
|
@@ -34,3 +35,72 @@ const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
|
34
35
|
return deals;
|
|
35
36
|
};
|
|
36
37
|
exports.makeValidDeals = makeValidDeals;
|
|
38
|
+
const makeDiscountServiceType = (serviceType) => {
|
|
39
|
+
switch (serviceType) {
|
|
40
|
+
case 'WALKIN':
|
|
41
|
+
return 'In-store only';
|
|
42
|
+
case 'PICKUP':
|
|
43
|
+
return 'Pickup only';
|
|
44
|
+
case 'DELIVERY':
|
|
45
|
+
return 'Delivery only';
|
|
46
|
+
default:
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const makeDiscountOrderType = (orderType) => {
|
|
51
|
+
switch (orderType) {
|
|
52
|
+
case 'OLO':
|
|
53
|
+
return null;
|
|
54
|
+
case 'CATERING':
|
|
55
|
+
return 'Catering only';
|
|
56
|
+
case 'MERCH':
|
|
57
|
+
return 'Merch only';
|
|
58
|
+
default:
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const makeChannelType = (channelType) => {
|
|
63
|
+
switch (channelType) {
|
|
64
|
+
case 'APP':
|
|
65
|
+
return 'App Only!';
|
|
66
|
+
case 'ONLINE':
|
|
67
|
+
return 'Online Only!';
|
|
68
|
+
case 'POS':
|
|
69
|
+
return 'At POS Only!';
|
|
70
|
+
case 'KIOSK':
|
|
71
|
+
return 'Kiosk Only!';
|
|
72
|
+
default:
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const makeLimitations = (item) => {
|
|
77
|
+
const { channel_type, order_type, service_type } = item;
|
|
78
|
+
const serviceType = makeDiscountServiceType(service_type);
|
|
79
|
+
const orderType = makeDiscountOrderType(order_type);
|
|
80
|
+
const channelType = channel_type && makeChannelType(channel_type);
|
|
81
|
+
const comma = serviceType && orderType ? ', ' : null;
|
|
82
|
+
const dash = (serviceType || orderType) && channelType ? ' - ' : null;
|
|
83
|
+
if (serviceType || orderType || channelType) {
|
|
84
|
+
return `
|
|
85
|
+
${serviceType}
|
|
86
|
+
${comma}
|
|
87
|
+
${orderType}
|
|
88
|
+
${dash}
|
|
89
|
+
${channelType}
|
|
90
|
+
`;
|
|
91
|
+
}
|
|
92
|
+
return 'Valid on all online & app orders';
|
|
93
|
+
};
|
|
94
|
+
exports.makeLimitations = makeLimitations;
|
|
95
|
+
const makeDiscountEnhanced = (item) => {
|
|
96
|
+
const today = (0, datetimes_1.makeLocalDateStr)(new Date(), 0, 'yyyy-MM-dd');
|
|
97
|
+
const imageMap = (0, helpers_1.makeImageMap)(item.images);
|
|
98
|
+
const imageUrl = imageMap.SMALL_IMAGE || imageMap.APP_IMAGE || imageMap.LARGE_IMAGE || null;
|
|
99
|
+
const todayOnly = item.end_date === today;
|
|
100
|
+
const expiration = item.end_date
|
|
101
|
+
? (0, datetimes_1.formatDateStr)(item.end_date, 'MMM d')
|
|
102
|
+
: null;
|
|
103
|
+
const limitations = (0, exports.makeLimitations)(item);
|
|
104
|
+
return Object.assign(Object.assign({}, item), { imageUrl, expiration, todayOnly, limitations });
|
|
105
|
+
};
|
|
106
|
+
exports.makeDiscountEnhanced = makeDiscountEnhanced;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { DisplayItems, Favorites, MenuCategories, MenuItem, MenuItems, SoldOut } from '@open-tender/types';
|
|
1
|
+
import { DisplayItems, Favorites, MenuCategories, MenuItem, MenuItems, Orders, SoldOut } from '@open-tender/types';
|
|
2
2
|
export declare const makeMenuItemLookup: (categories: MenuCategories) => {
|
|
3
3
|
[i: number]: MenuItem;
|
|
4
4
|
};
|
|
5
5
|
export declare const makeFeatured: (categories: MenuCategories) => MenuItem[];
|
|
6
6
|
export declare const makeMenuGroupsLookup: (menuItem: MenuItem) => any;
|
|
7
7
|
export declare const makeRecents: (recents: DisplayItems, itemLookup: Record<string, MenuItem>, soldOut: SoldOut) => MenuItems;
|
|
8
|
+
export declare const makeRecentItems: (categories: MenuCategories, orders: Orders, soldOut: SoldOut) => MenuItems;
|
|
8
9
|
export declare const makeFavorites: (favorites: Favorites, itemLookup: Record<string, MenuItem>, soldOut: SoldOut) => MenuItems;
|
|
10
|
+
export declare const makeFavoriteItems: (categories: MenuCategories, favorites: Favorites, soldOut: SoldOut) => MenuItems;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { makeUniqueDisplayItems } from './cart';
|
|
1
2
|
export const makeMenuItemLookup = (categories) => {
|
|
2
3
|
const cats = categories.reduce((arr, cat) => {
|
|
3
4
|
return [...arr, cat, ...(cat.children || [])];
|
|
@@ -77,6 +78,11 @@ export const makeRecents = (recents, itemLookup, soldOut) => {
|
|
|
77
78
|
}
|
|
78
79
|
}, []);
|
|
79
80
|
};
|
|
81
|
+
export const makeRecentItems = (categories, orders, soldOut) => {
|
|
82
|
+
const itemLookup = makeMenuItemLookup(categories);
|
|
83
|
+
const displayItems = makeUniqueDisplayItems(orders);
|
|
84
|
+
return makeRecents(displayItems, itemLookup, soldOut);
|
|
85
|
+
};
|
|
80
86
|
export const makeFavorites = (favorites, itemLookup, soldOut) => {
|
|
81
87
|
return favorites.reduce((arr, favorite) => {
|
|
82
88
|
var _a, _b;
|
|
@@ -93,3 +99,7 @@ export const makeFavorites = (favorites, itemLookup, soldOut) => {
|
|
|
93
99
|
}
|
|
94
100
|
}, []);
|
|
95
101
|
};
|
|
102
|
+
export const makeFavoriteItems = (categories, favorites, soldOut) => {
|
|
103
|
+
const itemLookup = makeMenuItemLookup(categories);
|
|
104
|
+
return makeFavorites(favorites, itemLookup, soldOut);
|
|
105
|
+
};
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
1
|
+
import { Discount, DiscountEnhanced, Discounts, OrderType, ServiceType } from '@open-tender/types';
|
|
2
2
|
export declare const makeValidDeals: (deals: Discounts | null, orderType?: OrderType | null, serviceType?: ServiceType | null, revenueCenterId?: number | null) => Discounts;
|
|
3
|
+
export declare const makeLimitations: (item: Discount) => string;
|
|
4
|
+
export declare const makeDiscountEnhanced: (item: Discount) => DiscountEnhanced;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getMinutesfromDate, time24ToMinutes } from './datetimes';
|
|
1
|
+
import { formatDateStr, getMinutesfromDate, makeLocalDateStr, time24ToMinutes } from './datetimes';
|
|
2
|
+
import { makeImageMap } from './helpers';
|
|
2
3
|
export const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
3
4
|
if (!deals || !deals.length)
|
|
4
5
|
return [];
|
|
@@ -30,3 +31,70 @@ export const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) =
|
|
|
30
31
|
});
|
|
31
32
|
return deals;
|
|
32
33
|
};
|
|
34
|
+
const makeDiscountServiceType = (serviceType) => {
|
|
35
|
+
switch (serviceType) {
|
|
36
|
+
case 'WALKIN':
|
|
37
|
+
return 'In-store only';
|
|
38
|
+
case 'PICKUP':
|
|
39
|
+
return 'Pickup only';
|
|
40
|
+
case 'DELIVERY':
|
|
41
|
+
return 'Delivery only';
|
|
42
|
+
default:
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const makeDiscountOrderType = (orderType) => {
|
|
47
|
+
switch (orderType) {
|
|
48
|
+
case 'OLO':
|
|
49
|
+
return null;
|
|
50
|
+
case 'CATERING':
|
|
51
|
+
return 'Catering only';
|
|
52
|
+
case 'MERCH':
|
|
53
|
+
return 'Merch only';
|
|
54
|
+
default:
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const makeChannelType = (channelType) => {
|
|
59
|
+
switch (channelType) {
|
|
60
|
+
case 'APP':
|
|
61
|
+
return 'App Only!';
|
|
62
|
+
case 'ONLINE':
|
|
63
|
+
return 'Online Only!';
|
|
64
|
+
case 'POS':
|
|
65
|
+
return 'At POS Only!';
|
|
66
|
+
case 'KIOSK':
|
|
67
|
+
return 'Kiosk Only!';
|
|
68
|
+
default:
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
export const makeLimitations = (item) => {
|
|
73
|
+
const { channel_type, order_type, service_type } = item;
|
|
74
|
+
const serviceType = makeDiscountServiceType(service_type);
|
|
75
|
+
const orderType = makeDiscountOrderType(order_type);
|
|
76
|
+
const channelType = channel_type && makeChannelType(channel_type);
|
|
77
|
+
const comma = serviceType && orderType ? ', ' : null;
|
|
78
|
+
const dash = (serviceType || orderType) && channelType ? ' - ' : null;
|
|
79
|
+
if (serviceType || orderType || channelType) {
|
|
80
|
+
return `
|
|
81
|
+
${serviceType}
|
|
82
|
+
${comma}
|
|
83
|
+
${orderType}
|
|
84
|
+
${dash}
|
|
85
|
+
${channelType}
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
88
|
+
return 'Valid on all online & app orders';
|
|
89
|
+
};
|
|
90
|
+
export const makeDiscountEnhanced = (item) => {
|
|
91
|
+
const today = makeLocalDateStr(new Date(), 0, 'yyyy-MM-dd');
|
|
92
|
+
const imageMap = makeImageMap(item.images);
|
|
93
|
+
const imageUrl = imageMap.SMALL_IMAGE || imageMap.APP_IMAGE || imageMap.LARGE_IMAGE || null;
|
|
94
|
+
const todayOnly = item.end_date === today;
|
|
95
|
+
const expiration = item.end_date
|
|
96
|
+
? formatDateStr(item.end_date, 'MMM d')
|
|
97
|
+
: null;
|
|
98
|
+
const limitations = makeLimitations(item);
|
|
99
|
+
return Object.assign(Object.assign({}, item), { imageUrl, expiration, todayOnly, limitations });
|
|
100
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.12",
|
|
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,7 @@
|
|
|
36
36
|
"private": false,
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@emotion/react": "^11.10.4",
|
|
39
|
-
"@open-tender/types": "^0.4.
|
|
39
|
+
"@open-tender/types": "^0.4.34",
|
|
40
40
|
"@reduxjs/toolkit": "^1.8.5",
|
|
41
41
|
"@types/google.maps": "^3.53.5",
|
|
42
42
|
"@types/jest": "^29.5.11",
|