@open-tender/utils 0.0.1
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/LICENSE.md +21 -0
- package/README.md +3 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/utils/cards.d.ts +20 -0
- package/dist/cjs/utils/cards.js +153 -0
- package/dist/cjs/utils/cart.d.ts +422 -0
- package/dist/cjs/utils/cart.js +848 -0
- package/dist/cjs/utils/checkout.d.ts +23 -0
- package/dist/cjs/utils/checkout.js +108 -0
- package/dist/cjs/utils/constants.d.ts +52 -0
- package/dist/cjs/utils/constants.js +58 -0
- package/dist/cjs/utils/customer.d.ts +3 -0
- package/dist/cjs/utils/customer.js +23 -0
- package/dist/cjs/utils/datetimes.d.ts +174 -0
- package/dist/cjs/utils/datetimes.js +704 -0
- package/dist/cjs/utils/errors.d.ts +48 -0
- package/dist/cjs/utils/errors.js +143 -0
- package/dist/cjs/utils/helpers.d.ts +30 -0
- package/dist/cjs/utils/helpers.js +141 -0
- package/dist/cjs/utils/index.d.ts +14 -0
- package/dist/cjs/utils/index.js +17 -0
- package/dist/cjs/utils/keypad.d.ts +9 -0
- package/dist/cjs/utils/keypad.js +105 -0
- package/dist/cjs/utils/maps.d.ts +264 -0
- package/dist/cjs/utils/maps.js +287 -0
- package/dist/cjs/utils/orders.d.ts +40 -0
- package/dist/cjs/utils/orders.js +191 -0
- package/dist/cjs/utils/refunds.d.ts +35 -0
- package/dist/cjs/utils/refunds.js +98 -0
- package/dist/cjs/utils/rewards.d.ts +18 -0
- package/dist/cjs/utils/rewards.js +69 -0
- package/dist/cjs/utils/version.d.ts +4 -0
- package/dist/cjs/utils/version.js +38 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/utils/cards.d.ts +20 -0
- package/dist/esm/utils/cards.js +144 -0
- package/dist/esm/utils/cart.d.ts +422 -0
- package/dist/esm/utils/cart.js +805 -0
- package/dist/esm/utils/checkout.d.ts +23 -0
- package/dist/esm/utils/checkout.js +100 -0
- package/dist/esm/utils/constants.d.ts +52 -0
- package/dist/esm/utils/constants.js +55 -0
- package/dist/esm/utils/customer.d.ts +3 -0
- package/dist/esm/utils/customer.js +18 -0
- package/dist/esm/utils/datetimes.d.ts +174 -0
- package/dist/esm/utils/datetimes.js +631 -0
- package/dist/esm/utils/errors.d.ts +48 -0
- package/dist/esm/utils/errors.js +135 -0
- package/dist/esm/utils/helpers.d.ts +30 -0
- package/dist/esm/utils/helpers.js +117 -0
- package/dist/esm/utils/index.d.ts +14 -0
- package/dist/esm/utils/index.js +14 -0
- package/dist/esm/utils/keypad.d.ts +9 -0
- package/dist/esm/utils/keypad.js +97 -0
- package/dist/esm/utils/maps.d.ts +264 -0
- package/dist/esm/utils/maps.js +269 -0
- package/dist/esm/utils/orders.d.ts +40 -0
- package/dist/esm/utils/orders.js +171 -0
- package/dist/esm/utils/refunds.d.ts +35 -0
- package/dist/esm/utils/refunds.js +90 -0
- package/dist/esm/utils/rewards.d.ts +18 -0
- package/dist/esm/utils/rewards.js +63 -0
- package/dist/esm/utils/version.d.ts +4 -0
- package/dist/esm/utils/version.js +34 -0
- package/package.json +65 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeColor = exports.displayCounts = exports.makeDisplayCounts = exports.makeTicketGroups = exports.makeItemTypesMap = exports.makeItemTypeSettings = exports.makeCartLookup = exports.makeTicketCounts = exports.makeOrderBucketsCounts = exports.makeOrderBuckets = exports.makeOrdersCounts = exports.isCompleted = exports.notCompleted = exports.isDone = exports.notDone = exports.makeTenderTypeName = exports.makeChannelName = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
const datetimes_1 = require("./datetimes");
|
|
7
|
+
const makeChannelName = (channel) => {
|
|
8
|
+
switch (channel.type) {
|
|
9
|
+
case 'ONLINE':
|
|
10
|
+
return 'Web';
|
|
11
|
+
case 'APP':
|
|
12
|
+
return 'App';
|
|
13
|
+
case 'PORTAL':
|
|
14
|
+
return channel.ext_name;
|
|
15
|
+
default:
|
|
16
|
+
return channel.type;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.makeChannelName = makeChannelName;
|
|
20
|
+
const makeTenderTypeName = (tenderType) => {
|
|
21
|
+
const name = constants_1.tenderTypeNamesMap[tenderType];
|
|
22
|
+
return name || (0, helpers_1.capitalize)(tenderType.replace('_', ' '));
|
|
23
|
+
};
|
|
24
|
+
exports.makeTenderTypeName = makeTenderTypeName;
|
|
25
|
+
const notDone = (prep_status) => {
|
|
26
|
+
const notDoneStates = [constants_1.prepStatus.TODO, constants_1.prepStatus.IN_PROGRESS];
|
|
27
|
+
return notDoneStates.includes(prep_status);
|
|
28
|
+
};
|
|
29
|
+
exports.notDone = notDone;
|
|
30
|
+
const isDone = (prep_status) => {
|
|
31
|
+
const doneStates = [
|
|
32
|
+
constants_1.prepStatus.DONE,
|
|
33
|
+
constants_1.prepStatus.COMPLETED,
|
|
34
|
+
constants_1.prepStatus.FULFILLED
|
|
35
|
+
];
|
|
36
|
+
return doneStates.includes(prep_status);
|
|
37
|
+
};
|
|
38
|
+
exports.isDone = isDone;
|
|
39
|
+
const notCompleted = (prep_status) => {
|
|
40
|
+
const notCompletedStates = [
|
|
41
|
+
constants_1.prepStatus.TODO,
|
|
42
|
+
constants_1.prepStatus.IN_PROGRESS,
|
|
43
|
+
constants_1.prepStatus.DONE
|
|
44
|
+
];
|
|
45
|
+
return notCompletedStates.includes(prep_status);
|
|
46
|
+
};
|
|
47
|
+
exports.notCompleted = notCompleted;
|
|
48
|
+
const isCompleted = (prep_status) => {
|
|
49
|
+
const completeStates = [constants_1.prepStatus.COMPLETED, constants_1.prepStatus.FULFILLED];
|
|
50
|
+
return completeStates.includes(prep_status);
|
|
51
|
+
};
|
|
52
|
+
exports.isCompleted = isCompleted;
|
|
53
|
+
const updateCounts = (counts, ticketCounts) => {
|
|
54
|
+
// console.log('BEFORE', counts, ticketCounts)
|
|
55
|
+
const updated = Object.entries(counts).reduce((obj, [key, count]) => {
|
|
56
|
+
return Object.assign(Object.assign({}, obj), { [key]: count + (ticketCounts[key] || 0) });
|
|
57
|
+
}, {});
|
|
58
|
+
updated.Orders = counts.Orders + 1;
|
|
59
|
+
// console.log('AFTER', updated)
|
|
60
|
+
return updated;
|
|
61
|
+
};
|
|
62
|
+
const makeOrdersCounts = (itemTypes = [], orders = []) => {
|
|
63
|
+
const itemTypeCounts = itemTypes
|
|
64
|
+
.filter(i => i.is_default)
|
|
65
|
+
.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: 0 })), {});
|
|
66
|
+
let current = Object.assign({ Orders: 0 }, itemTypeCounts);
|
|
67
|
+
let qa = Object.assign({ Orders: 0 }, itemTypeCounts);
|
|
68
|
+
let future = Object.assign({ Orders: 0 }, itemTypeCounts);
|
|
69
|
+
const openOrders = orders.filter(i => (0, exports.notCompleted)(i.prep_status));
|
|
70
|
+
openOrders.forEach(order => {
|
|
71
|
+
var _a;
|
|
72
|
+
const tz = datetimes_1.timezoneMap[order.timezone];
|
|
73
|
+
const fireDate = (0, datetimes_1.isoToDate)(order.fire_at, tz);
|
|
74
|
+
const currentDate = (0, datetimes_1.currentLocalDate)(tz);
|
|
75
|
+
const isDone = order.prep_status === constants_1.prepStatus.DONE;
|
|
76
|
+
const isCurrent = fireDate < currentDate;
|
|
77
|
+
const ticketCounts = (_a = order.tickets) === null || _a === void 0 ? void 0 : _a.reduce((obj, ticket) => {
|
|
78
|
+
const count = obj[ticket.item_type_name] || 0;
|
|
79
|
+
return Object.assign(Object.assign({}, obj), { [ticket.item_type_name]: count + ticket.item_nos.length });
|
|
80
|
+
}, {});
|
|
81
|
+
if (isDone) {
|
|
82
|
+
qa = updateCounts(qa, ticketCounts);
|
|
83
|
+
}
|
|
84
|
+
else if (isCurrent) {
|
|
85
|
+
current = updateCounts(current, ticketCounts);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
future = updateCounts(future, ticketCounts);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return { current, future, qa };
|
|
92
|
+
};
|
|
93
|
+
exports.makeOrdersCounts = makeOrdersCounts;
|
|
94
|
+
const makeOrderBuckets = (orders, tz, prepStates = []) => {
|
|
95
|
+
const intervals = (0, datetimes_1.makeIntervals)(tz);
|
|
96
|
+
const withOrders = intervals.map(i => {
|
|
97
|
+
const inBucket = orders.filter(order => {
|
|
98
|
+
const incomplete = prepStates.includes(order.prep_status);
|
|
99
|
+
const readyAt = (0, datetimes_1.isoToDate)(order.ready_at, tz);
|
|
100
|
+
return incomplete && i.start < readyAt && readyAt <= i.end;
|
|
101
|
+
});
|
|
102
|
+
return Object.assign(Object.assign({}, i), { orders: inBucket });
|
|
103
|
+
});
|
|
104
|
+
return withOrders;
|
|
105
|
+
};
|
|
106
|
+
exports.makeOrderBuckets = makeOrderBuckets;
|
|
107
|
+
const makeOrderBucketsCounts = (itemTypes = [], orders = []) => {
|
|
108
|
+
const itemTypeCounts = itemTypes
|
|
109
|
+
.filter(i => i.is_default)
|
|
110
|
+
.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.name]: 0 })), {});
|
|
111
|
+
let counts = Object.assign({ Orders: 0 }, itemTypeCounts);
|
|
112
|
+
orders.forEach(order => {
|
|
113
|
+
var _a;
|
|
114
|
+
const ticketCounts = (_a = order.tickets) === null || _a === void 0 ? void 0 : _a.reduce((obj, ticket) => {
|
|
115
|
+
const count = obj[ticket.item_type_name] || 0;
|
|
116
|
+
return Object.assign(Object.assign({}, obj), { [ticket.item_type_name]: count + ticket.item_nos.length });
|
|
117
|
+
}, {});
|
|
118
|
+
counts = updateCounts(counts, ticketCounts);
|
|
119
|
+
});
|
|
120
|
+
return counts;
|
|
121
|
+
};
|
|
122
|
+
exports.makeOrderBucketsCounts = makeOrderBucketsCounts;
|
|
123
|
+
const makeTicketCounts = (tickets) => {
|
|
124
|
+
return tickets.reduce((obj, i) => {
|
|
125
|
+
const count = obj[i.item_type_id] || 0;
|
|
126
|
+
return Object.assign(Object.assign({}, obj), { [i.item_type_id]: count + i.item_nos.length });
|
|
127
|
+
}, {});
|
|
128
|
+
};
|
|
129
|
+
exports.makeTicketCounts = makeTicketCounts;
|
|
130
|
+
const makeCartLookup = (cart) => {
|
|
131
|
+
return cart.reduce((obj, i) => (i.item_no ? Object.assign(Object.assign({}, obj), { [i.item_no]: i }) : Object.assign({}, obj)), {});
|
|
132
|
+
};
|
|
133
|
+
exports.makeCartLookup = makeCartLookup;
|
|
134
|
+
const makeItemTypeSettings = (itemType) => {
|
|
135
|
+
const { is_default, is_grouped, is_hidden_assembly, is_hidden_qa, print_on_completed } = itemType || {};
|
|
136
|
+
return {
|
|
137
|
+
is_default,
|
|
138
|
+
is_grouped,
|
|
139
|
+
is_hidden_assembly,
|
|
140
|
+
is_hidden_qa,
|
|
141
|
+
print_on_completed
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
exports.makeItemTypeSettings = makeItemTypeSettings;
|
|
145
|
+
const makeItemTypesMap = (itemTypes) => {
|
|
146
|
+
return itemTypes
|
|
147
|
+
? itemTypes.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i.item_type_id]: i })), {})
|
|
148
|
+
: {};
|
|
149
|
+
};
|
|
150
|
+
exports.makeItemTypesMap = makeItemTypesMap;
|
|
151
|
+
const makeTicketGroups = (tickets, cart, itemTypes, isAssembly) => {
|
|
152
|
+
const lookup = (0, exports.makeCartLookup)(cart);
|
|
153
|
+
const grouped = tickets.reduce((obj, i) => {
|
|
154
|
+
const items = i.item_nos.map(n => lookup[n]);
|
|
155
|
+
const settings = (0, exports.makeItemTypeSettings)(itemTypes[i.item_type_id]);
|
|
156
|
+
const hideTicket = isAssembly && settings.is_hidden_assembly;
|
|
157
|
+
const ticket = Object.assign(Object.assign(Object.assign({}, i), { items }), settings);
|
|
158
|
+
const group = obj[i.item_type_id] || [];
|
|
159
|
+
const newGroup = hideTicket ? group : [...group, ticket];
|
|
160
|
+
return Object.assign(Object.assign({}, obj), { [i.item_type_id]: newGroup });
|
|
161
|
+
}, {});
|
|
162
|
+
return Object.values(grouped);
|
|
163
|
+
};
|
|
164
|
+
exports.makeTicketGroups = makeTicketGroups;
|
|
165
|
+
const makeDisplayCounts = (counts) => {
|
|
166
|
+
if (!counts)
|
|
167
|
+
return '';
|
|
168
|
+
return Object.entries(counts).map(([, value]) => value);
|
|
169
|
+
};
|
|
170
|
+
exports.makeDisplayCounts = makeDisplayCounts;
|
|
171
|
+
const displayCounts = (counts) => {
|
|
172
|
+
if (!counts)
|
|
173
|
+
return '';
|
|
174
|
+
const countStr = Object.entries(counts)
|
|
175
|
+
// .map(([key, value]) => `${value}-${key.charAt(0)}`)
|
|
176
|
+
.map(([, value]) => `${value}`)
|
|
177
|
+
.join('/');
|
|
178
|
+
return ` (${countStr})`;
|
|
179
|
+
};
|
|
180
|
+
exports.displayCounts = displayCounts;
|
|
181
|
+
const makeColor = (settings, minutes) => {
|
|
182
|
+
const { warning_minutes, alert_minutes } = settings || {};
|
|
183
|
+
if (!warning_minutes && !alert_minutes)
|
|
184
|
+
return '';
|
|
185
|
+
return minutes < warning_minutes
|
|
186
|
+
? 'warning'
|
|
187
|
+
: minutes < alert_minutes
|
|
188
|
+
? 'alert'
|
|
189
|
+
: 'text';
|
|
190
|
+
};
|
|
191
|
+
exports.makeColor = makeColor;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Order, OrderCart } from '@open-tender/types';
|
|
2
|
+
export declare const makeRefundCartLookup: (cart: OrderCart) => {
|
|
3
|
+
[key: number]: {
|
|
4
|
+
quantity?: number | undefined;
|
|
5
|
+
price_total?: `${number}.${number}` | undefined;
|
|
6
|
+
price?: string | undefined;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const makeAmountsLookup: (items: Array<any>, key?: string) => any;
|
|
10
|
+
export declare const makeRefundLookup: (order: Order) => {
|
|
11
|
+
cart: {
|
|
12
|
+
[key: number]: {
|
|
13
|
+
quantity?: number | undefined;
|
|
14
|
+
price_total?: `${number}.${number}` | undefined;
|
|
15
|
+
price?: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
gift_cards: any;
|
|
19
|
+
surcharges: any;
|
|
20
|
+
discounts: any;
|
|
21
|
+
taxes: any;
|
|
22
|
+
tenders: any;
|
|
23
|
+
subtotal: `${number}.${number}`;
|
|
24
|
+
gift_card: `${number}.${number}`;
|
|
25
|
+
surcharge: `${number}.${number}`;
|
|
26
|
+
discount: `-${number}.${number}`;
|
|
27
|
+
tax: `${number}.${number}`;
|
|
28
|
+
tip: `${number}.${number}`;
|
|
29
|
+
shipping: `${number}.${number}`;
|
|
30
|
+
total: `${number}.${number}`;
|
|
31
|
+
};
|
|
32
|
+
export declare const adjustAmounts: (order: Record<string, any>, lookup: {
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}, list: string, key?: string) => Record<string, any>;
|
|
35
|
+
export declare const makeNetOrder: (order: Order, refunds: Array<Order>) => any;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeNetOrder = exports.adjustAmounts = exports.makeRefundLookup = exports.makeAmountsLookup = exports.makeRefundCartLookup = void 0;
|
|
4
|
+
const makeRefundCartLookup = (cart) => {
|
|
5
|
+
const lookup = {};
|
|
6
|
+
cart.forEach(item => {
|
|
7
|
+
var _a;
|
|
8
|
+
const { line_no, quantity, price_total } = item;
|
|
9
|
+
lookup[line_no !== null && line_no !== void 0 ? line_no : 0] = { quantity, price_total };
|
|
10
|
+
(_a = item === null || item === void 0 ? void 0 : item.groups) === null || _a === void 0 ? void 0 : _a.forEach(group => group.options.forEach(option => {
|
|
11
|
+
const { line_no, quantity, price } = option;
|
|
12
|
+
lookup[line_no !== null && line_no !== void 0 ? line_no : 0] = { quantity, price };
|
|
13
|
+
}));
|
|
14
|
+
});
|
|
15
|
+
return lookup;
|
|
16
|
+
};
|
|
17
|
+
exports.makeRefundCartLookup = makeRefundCartLookup;
|
|
18
|
+
const makeAmountsLookup = (items, key = 'id') => {
|
|
19
|
+
return items.reduce((obj, i) => (Object.assign(Object.assign({}, obj), { [i[key]]: i.amount })), {});
|
|
20
|
+
};
|
|
21
|
+
exports.makeAmountsLookup = makeAmountsLookup;
|
|
22
|
+
const makeRefundLookup = (order) => {
|
|
23
|
+
const { cart, gift_cards, surcharges, discounts, taxes, totals, tenders } = order;
|
|
24
|
+
const { subtotal, gift_card, surcharge, discount, tax, tip, shipping, total } = totals;
|
|
25
|
+
return {
|
|
26
|
+
cart: (0, exports.makeRefundCartLookup)(cart),
|
|
27
|
+
gift_cards: (0, exports.makeAmountsLookup)(gift_cards, 'code'),
|
|
28
|
+
surcharges: (0, exports.makeAmountsLookup)(surcharges),
|
|
29
|
+
discounts: (0, exports.makeAmountsLookup)(discounts),
|
|
30
|
+
taxes: (0, exports.makeAmountsLookup)(taxes),
|
|
31
|
+
tenders: (0, exports.makeAmountsLookup)(tenders, 'tender_index'),
|
|
32
|
+
subtotal,
|
|
33
|
+
gift_card,
|
|
34
|
+
surcharge,
|
|
35
|
+
discount,
|
|
36
|
+
tax,
|
|
37
|
+
tip,
|
|
38
|
+
shipping,
|
|
39
|
+
total
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.makeRefundLookup = makeRefundLookup;
|
|
43
|
+
const adjustAmount = (amount, refundAmount) => {
|
|
44
|
+
return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2);
|
|
45
|
+
};
|
|
46
|
+
const adjustAmounts = (order, lookup, list, key = 'id') => {
|
|
47
|
+
if (!order[list])
|
|
48
|
+
return order;
|
|
49
|
+
order[list].forEach((i) => {
|
|
50
|
+
const amount = lookup[list][i[key]];
|
|
51
|
+
if (amount)
|
|
52
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
53
|
+
});
|
|
54
|
+
return order;
|
|
55
|
+
};
|
|
56
|
+
exports.adjustAmounts = adjustAmounts;
|
|
57
|
+
const amounts = [
|
|
58
|
+
'subtotal',
|
|
59
|
+
'gift_card',
|
|
60
|
+
'surcharge',
|
|
61
|
+
'discount',
|
|
62
|
+
'tax',
|
|
63
|
+
'tip',
|
|
64
|
+
'shipping',
|
|
65
|
+
'total'
|
|
66
|
+
];
|
|
67
|
+
const makeNetOrder = (order, refunds) => {
|
|
68
|
+
if (!refunds || !refunds.length)
|
|
69
|
+
return order;
|
|
70
|
+
let copy = JSON.parse(JSON.stringify(order));
|
|
71
|
+
refunds.forEach(refund => {
|
|
72
|
+
const lookup = (0, exports.makeRefundLookup)(refund);
|
|
73
|
+
copy.cart.forEach((i) => {
|
|
74
|
+
var _a, _b, _c, _d;
|
|
75
|
+
const item = lookup.cart[(_a = i.line_no) !== null && _a !== void 0 ? _a : 0];
|
|
76
|
+
if (item) {
|
|
77
|
+
i.quantity -= (_b = item.quantity) !== null && _b !== void 0 ? _b : 0;
|
|
78
|
+
i.price_total = adjustAmount(i.price_total, (_c = item.price_total) !== null && _c !== void 0 ? _c : '0.0');
|
|
79
|
+
}
|
|
80
|
+
if (i.quantity === 0) {
|
|
81
|
+
(_d = i.groups) === null || _d === void 0 ? void 0 : _d.forEach(group => group.options.forEach(option => {
|
|
82
|
+
option.quantity = 0;
|
|
83
|
+
option.price_total = '0.00';
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
copy = (0, exports.adjustAmounts)(copy, lookup, 'gift_cards', 'code');
|
|
88
|
+
copy = (0, exports.adjustAmounts)(copy, lookup, 'surcharges');
|
|
89
|
+
copy = (0, exports.adjustAmounts)(copy, lookup, 'discounts');
|
|
90
|
+
copy = (0, exports.adjustAmounts)(copy, lookup, 'taxes');
|
|
91
|
+
copy = (0, exports.adjustAmounts)(copy, lookup, 'tenders', 'tender_index');
|
|
92
|
+
amounts.forEach(i => {
|
|
93
|
+
copy.totals[i] = adjustAmount(copy.totals[i], lookup[i]);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
return copy;
|
|
97
|
+
};
|
|
98
|
+
exports.makeNetOrder = makeNetOrder;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Deals, LoyaltyPoints, LoyaltyRedemption, LoyaltySpend, LoyaltyStatus, LoyaltyTier, LoyaltyType, OrderType, ServiceType } from '@open-tender/types';
|
|
2
|
+
export declare const makeValidDeals: (deals: Deals, orderType: OrderType, serviceType: ServiceType, revenueCenterId: number) => Deals;
|
|
3
|
+
export declare const makeStatus: (tiers: Array<LoyaltyTier>, status: LoyaltyStatus, points: LoyaltyPoints) => {
|
|
4
|
+
progress: number;
|
|
5
|
+
progressMsg: string;
|
|
6
|
+
tiers: {
|
|
7
|
+
points: LoyaltyPoints;
|
|
8
|
+
percentage: number;
|
|
9
|
+
color: string;
|
|
10
|
+
value: string;
|
|
11
|
+
description: string;
|
|
12
|
+
hex_code: string;
|
|
13
|
+
name: string;
|
|
14
|
+
threshold: string;
|
|
15
|
+
discount: import("@open-tender/types").LoyaltyDiscount;
|
|
16
|
+
}[];
|
|
17
|
+
} | null;
|
|
18
|
+
export declare const makeProgress: (loyalty_type: LoyaltyType, spend: LoyaltySpend, redemption: LoyaltyRedemption) => number | null;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeProgress = exports.makeStatus = exports.makeValidDeals = void 0;
|
|
4
|
+
const cart_1 = require("./cart");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const datetimes_1 = require("./datetimes");
|
|
7
|
+
const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
8
|
+
if (!deals || !deals.length)
|
|
9
|
+
return [];
|
|
10
|
+
if (orderType) {
|
|
11
|
+
deals = deals.filter(i => !i.order_type || i.order_type === orderType);
|
|
12
|
+
}
|
|
13
|
+
if (serviceType) {
|
|
14
|
+
deals = deals.filter(i => !i.service_type || i.service_type === serviceType);
|
|
15
|
+
}
|
|
16
|
+
if (revenueCenterId) {
|
|
17
|
+
deals = deals.filter(i => {
|
|
18
|
+
var _a;
|
|
19
|
+
return !((_a = i.revenue_centers) === null || _a === void 0 ? void 0 : _a.length) ||
|
|
20
|
+
i.revenue_centers
|
|
21
|
+
.map(r => r.revenue_center_id)
|
|
22
|
+
.includes(revenueCenterId);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const minutes = (0, datetimes_1.getMinutesfromDate)(new Date());
|
|
26
|
+
deals = deals.filter(i => {
|
|
27
|
+
if (!i.dayparts.length)
|
|
28
|
+
return true;
|
|
29
|
+
const validDayparts = i.dayparts.filter(d => {
|
|
30
|
+
const start = (0, datetimes_1.time24ToMinutes)(d.start_time);
|
|
31
|
+
const end = (0, datetimes_1.time24ToMinutes)(d.end_time);
|
|
32
|
+
return start <= minutes && minutes <= end;
|
|
33
|
+
});
|
|
34
|
+
return validDayparts.length > 0;
|
|
35
|
+
});
|
|
36
|
+
return deals;
|
|
37
|
+
};
|
|
38
|
+
exports.makeValidDeals = makeValidDeals;
|
|
39
|
+
const makeStatus = (tiers, status, points) => {
|
|
40
|
+
if (!tiers)
|
|
41
|
+
return null;
|
|
42
|
+
const highest = parseFloat(tiers[tiers.length - 1].threshold);
|
|
43
|
+
const total = highest * 1.2;
|
|
44
|
+
const progress = Math.min((parseFloat(status.progress) / total) * 100, 100);
|
|
45
|
+
const progressTiers = tiers.map(i => (Object.assign(Object.assign({}, i), { points, percentage: (parseFloat(i.threshold) / total) * 100, color: `#${i.hex_code}`, value: !points
|
|
46
|
+
? `${(0, cart_1.formatDollars)(i.threshold, '', 0)}`
|
|
47
|
+
: `${(0, cart_1.formatQuantity)(i.threshold)}` })));
|
|
48
|
+
const daysMsg = status.days === 7300 ? 'all-time' : `last ${status.days} days`;
|
|
49
|
+
const progressAmt = !points
|
|
50
|
+
? (0, cart_1.formatDollars)(status.progress, '', 0)
|
|
51
|
+
: (0, cart_1.formatQuantity)(status.progress);
|
|
52
|
+
const progressMsg = !points
|
|
53
|
+
? `${progressAmt} spent ${daysMsg}`
|
|
54
|
+
: `${progressAmt} ${points.name.toLowerCase()} earned ${daysMsg}`;
|
|
55
|
+
return { progress, progressMsg, tiers: progressTiers };
|
|
56
|
+
};
|
|
57
|
+
exports.makeStatus = makeStatus;
|
|
58
|
+
const makeProgress = (loyalty_type, spend, redemption) => {
|
|
59
|
+
var _a;
|
|
60
|
+
if (!spend || !redemption || !loyalty_type)
|
|
61
|
+
return null;
|
|
62
|
+
const currentSpend = parseFloat((_a = spend.current) !== null && _a !== void 0 ? _a : '0');
|
|
63
|
+
const threshold = parseFloat(redemption.threshold);
|
|
64
|
+
const progress = loyalty_type === constants_1.loyaltyType.CREDIT
|
|
65
|
+
? (currentSpend / threshold) * 100
|
|
66
|
+
: null;
|
|
67
|
+
return progress;
|
|
68
|
+
};
|
|
69
|
+
exports.makeProgress = makeProgress;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maybeRefreshVersion = void 0;
|
|
4
|
+
// https://dev.to/flexdinesh/cache-busting-a-react-app-22lk
|
|
5
|
+
// https://github.com/flexdinesh/cache-busting-example/blob/master/src/App.js
|
|
6
|
+
let global;
|
|
7
|
+
// version from response - first param, local version second param
|
|
8
|
+
const semverGreaterThan = (latest, current) => {
|
|
9
|
+
if (!latest || !current)
|
|
10
|
+
return false;
|
|
11
|
+
const versionsA = latest.split(/\./g);
|
|
12
|
+
const versionsB = current.split(/\./g);
|
|
13
|
+
while (versionsA.length || versionsB.length) {
|
|
14
|
+
const a = Number(versionsA.shift());
|
|
15
|
+
const b = Number(versionsB.shift());
|
|
16
|
+
// eslint-disable-next-line no-continue
|
|
17
|
+
if (a === b)
|
|
18
|
+
continue;
|
|
19
|
+
// eslint-disable-next-line no-restricted-globals
|
|
20
|
+
return a > b || isNaN(b);
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
const maybeRefreshVersion = (open) => {
|
|
25
|
+
fetch('/meta.json', { cache: 'no-store' })
|
|
26
|
+
.then(response => response.json())
|
|
27
|
+
.then(meta => {
|
|
28
|
+
const latest = meta.version;
|
|
29
|
+
const current = global.appVersion;
|
|
30
|
+
// console.log(latest, current)
|
|
31
|
+
const shouldForceRefresh = semverGreaterThan(latest, current);
|
|
32
|
+
if (shouldForceRefresh) {
|
|
33
|
+
open({ type: 'version', args: { latest, current, preventClose: true } });
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
.catch(err => console.log(err));
|
|
37
|
+
};
|
|
38
|
+
exports.maybeRefreshVersion = maybeRefreshVersion;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CardType, CreditCardData, ValidatedCreditCard } from '@open-tender/types';
|
|
2
|
+
export declare const cardNames: {
|
|
3
|
+
VISA: string;
|
|
4
|
+
MC: string;
|
|
5
|
+
DISC: string;
|
|
6
|
+
AMEX: string;
|
|
7
|
+
OTHER: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const cardNumbersRegex: {
|
|
10
|
+
VISA: string;
|
|
11
|
+
MC: string;
|
|
12
|
+
DISC: string;
|
|
13
|
+
AMEX: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const getCardType: (cardNumber: string) => CardType;
|
|
16
|
+
export declare const makeNumeric: (str: string) => string;
|
|
17
|
+
export declare const makeAcctNumber: (str: string, cardType: CardType) => string;
|
|
18
|
+
export declare const formatCardField: (field: keyof CreditCardData, value: string) => string;
|
|
19
|
+
export declare const formatCard: (card: CreditCardData) => [CreditCardData | null, CardType | null];
|
|
20
|
+
export declare const validateCreditCard: (card: CreditCardData, cardType: CardType) => ValidatedCreditCard;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { isNum, isEmpty } from './helpers';
|
|
2
|
+
export const cardNames = {
|
|
3
|
+
VISA: 'Visa',
|
|
4
|
+
MC: 'Mastercard',
|
|
5
|
+
DISC: 'Discover',
|
|
6
|
+
AMEX: 'American Express',
|
|
7
|
+
OTHER: 'Other Credit Card'
|
|
8
|
+
};
|
|
9
|
+
// https://github.com/jasminmif/react-interactive-paycard
|
|
10
|
+
export const cardNumbersRegex = {
|
|
11
|
+
VISA: '^4',
|
|
12
|
+
MC: '^5[1-5]',
|
|
13
|
+
DISC: '^6011',
|
|
14
|
+
AMEX: '^(34|37)'
|
|
15
|
+
// unionpay: '^62',
|
|
16
|
+
// troy: '^9792'
|
|
17
|
+
};
|
|
18
|
+
export const getCardType = (cardNumber) => {
|
|
19
|
+
const number = cardNumber;
|
|
20
|
+
let re;
|
|
21
|
+
for (const [card, pattern] of Object.entries(cardNumbersRegex)) {
|
|
22
|
+
re = new RegExp(pattern);
|
|
23
|
+
if (number.match(re) !== null) {
|
|
24
|
+
return card;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return 'OTHER'; // default type
|
|
28
|
+
};
|
|
29
|
+
const chunks = [
|
|
30
|
+
[0, 4],
|
|
31
|
+
[4, 8],
|
|
32
|
+
[8, 12],
|
|
33
|
+
[12, 16]
|
|
34
|
+
];
|
|
35
|
+
const amexChunks = [
|
|
36
|
+
[0, 4],
|
|
37
|
+
[4, 10],
|
|
38
|
+
[10, 15]
|
|
39
|
+
];
|
|
40
|
+
export const makeNumeric = (str) => {
|
|
41
|
+
const strMatches = str.match(/\d+/g); // limit to numerical input, returns an array
|
|
42
|
+
if (!strMatches)
|
|
43
|
+
return '';
|
|
44
|
+
return strMatches.join('').replace(/\s/g, '');
|
|
45
|
+
};
|
|
46
|
+
export const makeAcctNumber = (str, cardType) => {
|
|
47
|
+
const strMatches = str.match(/\d+/g); // limit to numerical input, returns an array
|
|
48
|
+
if (!strMatches)
|
|
49
|
+
return '';
|
|
50
|
+
str = strMatches.join('').replace(/\s/g, '');
|
|
51
|
+
if (cardType === 'AMEX') {
|
|
52
|
+
return amexChunks
|
|
53
|
+
.map(([start, end]) => str.slice(start, end))
|
|
54
|
+
.filter(i => i.length)
|
|
55
|
+
.join(' ')
|
|
56
|
+
.slice(0, 18);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return chunks
|
|
60
|
+
.map(([start, end]) => str.slice(start, end))
|
|
61
|
+
.filter(i => i.length)
|
|
62
|
+
.join(' ')
|
|
63
|
+
.slice(0, 19);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
export const formatCardField = (field, value) => {
|
|
67
|
+
const cleanValue = makeNumeric(value);
|
|
68
|
+
switch (field) {
|
|
69
|
+
case 'acct': {
|
|
70
|
+
const currentType = getCardType(value.replace(/\s/g, ''));
|
|
71
|
+
return makeAcctNumber(value, currentType);
|
|
72
|
+
}
|
|
73
|
+
case 'exp': {
|
|
74
|
+
value = cleanValue.slice(0, 4);
|
|
75
|
+
if (value.length > 2) {
|
|
76
|
+
value = `${value.slice(0, 2)} / ${value.slice(2, 4)}`;
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
case 'cvv':
|
|
81
|
+
return cleanValue.slice(0, 4);
|
|
82
|
+
case 'zip':
|
|
83
|
+
return cleanValue.slice(0, 5);
|
|
84
|
+
default:
|
|
85
|
+
return cleanValue;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
export const formatCard = (card) => {
|
|
89
|
+
if (!card)
|
|
90
|
+
return [null, null];
|
|
91
|
+
const creditCardType = getCardType(card.acct.replace(/\s/g, ''));
|
|
92
|
+
const creditCard = {
|
|
93
|
+
acct: formatCardField('acct', card.acct),
|
|
94
|
+
exp: formatCardField('exp', card.exp),
|
|
95
|
+
cvv: formatCardField('cvv', card.cvv),
|
|
96
|
+
zip: formatCardField('zip', card.zip),
|
|
97
|
+
save: card.save || true
|
|
98
|
+
};
|
|
99
|
+
return [creditCard, creditCardType];
|
|
100
|
+
};
|
|
101
|
+
export const validateCreditCard = (card, cardType) => {
|
|
102
|
+
const errors = {};
|
|
103
|
+
let { acct, exp, cvv, zip } = card;
|
|
104
|
+
const acctLength = cardType === 'AMEX' ? 15 : 16;
|
|
105
|
+
acct = acct ? acct.replace(/\s/g, '') : '';
|
|
106
|
+
if (acct.length !== acctLength) {
|
|
107
|
+
errors.acct = `Card number must be ${acctLength} digits`;
|
|
108
|
+
}
|
|
109
|
+
else if (!isNum(acct)) {
|
|
110
|
+
errors.acct = 'Card number must be only numbers';
|
|
111
|
+
}
|
|
112
|
+
exp = (exp ? exp.replace(/\s/g, '') : '').replace('/', '').padStart(4, '0');
|
|
113
|
+
const expMonth = parseInt(exp.slice(0, 2));
|
|
114
|
+
const expYear = parseInt(exp.slice(2, 4));
|
|
115
|
+
if (!isNum(exp) || exp.length !== 4) {
|
|
116
|
+
errors.exp = 'Expiration must be 4 digits in MMYY format';
|
|
117
|
+
}
|
|
118
|
+
else if (expMonth < 1 || expMonth > 12) {
|
|
119
|
+
errors.exp = 'Expiration month must be number between 1 and 12';
|
|
120
|
+
}
|
|
121
|
+
else if (expYear < 20) {
|
|
122
|
+
errors.exp = 'Expiration year must be 2020 or later';
|
|
123
|
+
}
|
|
124
|
+
const cvvLength = cardType === 'AMEX' ? 4 : 3;
|
|
125
|
+
cvv = cvv ? cvv.replace(/\s/g, '') : '';
|
|
126
|
+
if (cvv.length !== cvvLength) {
|
|
127
|
+
errors.cvv = `CVV must be ${cvvLength} digits for this card type`;
|
|
128
|
+
}
|
|
129
|
+
else if (!isNum(cvv)) {
|
|
130
|
+
errors.cvv = 'CVV must be only numbers';
|
|
131
|
+
}
|
|
132
|
+
zip = zip ? zip.replace(/\s/g, '') : '';
|
|
133
|
+
if (zip.length !== 5) {
|
|
134
|
+
errors.zip = 'Zip code must be 5 digits';
|
|
135
|
+
}
|
|
136
|
+
else if (!isNum(zip)) {
|
|
137
|
+
errors.zip = 'Zip code must be only numbers';
|
|
138
|
+
}
|
|
139
|
+
if (!isEmpty(errors)) {
|
|
140
|
+
return { card, errors };
|
|
141
|
+
}
|
|
142
|
+
card = Object.assign(Object.assign({}, card), { acct, exp, cvv, zip });
|
|
143
|
+
return { card, errors: null };
|
|
144
|
+
};
|