@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,135 @@
|
|
|
1
|
+
import { isEmpty } from './helpers';
|
|
2
|
+
export const handleRespError = (err) => {
|
|
3
|
+
const error = typeof err === 'string' ? { detail: err } : err;
|
|
4
|
+
let { detail } = error || {};
|
|
5
|
+
const { title = 'Something went wrong', params } = error || {};
|
|
6
|
+
const messages = params ? Object.entries(params || {}) : [];
|
|
7
|
+
const errors = !params
|
|
8
|
+
? {}
|
|
9
|
+
: Object.entries(params || {}).reduce((obj, [key, msg]) => {
|
|
10
|
+
const [, attribute, index, field] = key.split('.');
|
|
11
|
+
if (!index)
|
|
12
|
+
return Object.assign(Object.assign({}, obj), { [attribute]: msg });
|
|
13
|
+
const error = { index: JSON.parse(index)[0], [field]: msg };
|
|
14
|
+
const errors = obj[attribute] ? [...obj[attribute], error] : [error];
|
|
15
|
+
return Object.assign(Object.assign({}, obj), { [attribute]: errors });
|
|
16
|
+
}, {});
|
|
17
|
+
if (detail && detail.includes('parameters') && messages.length) {
|
|
18
|
+
detail = messages[0][1];
|
|
19
|
+
}
|
|
20
|
+
return { title, detail, messages, errors, err };
|
|
21
|
+
};
|
|
22
|
+
export const processError = (msg) => {
|
|
23
|
+
if (!msg)
|
|
24
|
+
return errMessages.unknown;
|
|
25
|
+
if (msg.includes('is a required property')) {
|
|
26
|
+
return errMessages.requiredField;
|
|
27
|
+
}
|
|
28
|
+
else if (msg.includes("'' is too short")) {
|
|
29
|
+
return errMessages.requiredField;
|
|
30
|
+
}
|
|
31
|
+
else if (msg.includes("not a 'email'")) {
|
|
32
|
+
return errMessages.invalidEmail;
|
|
33
|
+
}
|
|
34
|
+
else if (msg.includes("not a 'phone'")) {
|
|
35
|
+
return errMessages.invalidPhone;
|
|
36
|
+
}
|
|
37
|
+
else if (msg.includes("not a 'optional-phone'")) {
|
|
38
|
+
return errMessages.invalidPhone;
|
|
39
|
+
}
|
|
40
|
+
else if (msg.includes('invalid token')) {
|
|
41
|
+
return errMessages.invalidToken;
|
|
42
|
+
}
|
|
43
|
+
else if (msg.includes("not a 'user-password'")) {
|
|
44
|
+
return errMessages.invalidPassword;
|
|
45
|
+
}
|
|
46
|
+
return msg;
|
|
47
|
+
};
|
|
48
|
+
export const handleFormErrors = (params) => {
|
|
49
|
+
return Object.entries(params).reduce((obj, error) => {
|
|
50
|
+
const [field, msg] = error;
|
|
51
|
+
const message = processError(msg);
|
|
52
|
+
return Object.assign(Object.assign({}, obj), { [field.replace('$.', '')]: message });
|
|
53
|
+
}, {});
|
|
54
|
+
};
|
|
55
|
+
export const makeFormErrors = (error) => {
|
|
56
|
+
let errors = {};
|
|
57
|
+
if (error === null || error === void 0 ? void 0 : error.params) {
|
|
58
|
+
errors = handleFormErrors(error.params);
|
|
59
|
+
errors.form = error.detail;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
errors.form = (error === null || error === void 0 ? void 0 : error.detail) || (error === null || error === void 0 ? void 0 : error.message) || "";
|
|
63
|
+
}
|
|
64
|
+
return errors;
|
|
65
|
+
};
|
|
66
|
+
export const handleCheckoutErrors = (errors, asMessages = true) => {
|
|
67
|
+
const { detail, params, message } = errors || {};
|
|
68
|
+
if (!params || isEmpty(params))
|
|
69
|
+
return { form: detail || message };
|
|
70
|
+
const errObj = Object.entries(params).reduce((obj, error) => {
|
|
71
|
+
const [key, value] = error;
|
|
72
|
+
const err = asMessages ? value.message : value;
|
|
73
|
+
const [, entity, index, field] = key.split('.');
|
|
74
|
+
const existingEntity = obj[entity] || {};
|
|
75
|
+
if (!index) {
|
|
76
|
+
return Object.assign(Object.assign({}, obj), { [entity]: err });
|
|
77
|
+
}
|
|
78
|
+
else if (!field) {
|
|
79
|
+
const newEntity = Object.assign(Object.assign({}, existingEntity), { [index]: err });
|
|
80
|
+
return Object.assign(Object.assign({}, obj), { [entity]: newEntity });
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
if (existingEntity) {
|
|
84
|
+
const existingIndex = existingEntity[index] || {};
|
|
85
|
+
const newIndex = Object.assign(Object.assign({}, existingIndex), { [field]: err });
|
|
86
|
+
const newEntity = Object.assign(Object.assign({}, existingEntity), { [index]: newIndex });
|
|
87
|
+
return Object.assign(Object.assign({}, obj), { [entity]: newEntity });
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: { [field]: err } } });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// const newEntity = obj[entity]
|
|
94
|
+
// ? { ...obj[entity], [index]: err }
|
|
95
|
+
// : index
|
|
96
|
+
// ? { [index]: err }
|
|
97
|
+
// : err
|
|
98
|
+
// return { ...obj, [entity]: newEntity }
|
|
99
|
+
}, { form: 'There are one or more errors below' });
|
|
100
|
+
return errObj;
|
|
101
|
+
};
|
|
102
|
+
export const errMessages = {
|
|
103
|
+
unknown: 'Unknown error. Please contact Open Tender support.',
|
|
104
|
+
forbidden: 'Your account does not have access to this page. Please contact your brand admin to request access.',
|
|
105
|
+
expiredToken: 'Reset token has expired. Please head back to the login form and try again.',
|
|
106
|
+
notAllowed: "This operation isn't allowed for this entity",
|
|
107
|
+
duplicates: 'One or more fields are already in use. Please choose different values.',
|
|
108
|
+
errorsBelow: 'There are one or more errors below.',
|
|
109
|
+
emptyField: 'This field cannot be empty',
|
|
110
|
+
invalidAmount: 'Invalid amount',
|
|
111
|
+
invalidEmail: 'Invalid email address',
|
|
112
|
+
invalidEmails: 'One or more email addresses are invaiid',
|
|
113
|
+
notInteger: 'Must be an integer',
|
|
114
|
+
positiveInteger: 'Must be a positive integer',
|
|
115
|
+
invalidTime: 'Enter in HH:MM AM|PM format (e.g. 9:40 AM)',
|
|
116
|
+
invalidDate: 'Enter in YYYY-MM-DD format or leave blank',
|
|
117
|
+
invalidNumber: 'Enter as a number with or without decimals',
|
|
118
|
+
invalidHex: 'Enter as a hexidecimal color code',
|
|
119
|
+
invalidZip: 'Enter a valid 5 digit zip code',
|
|
120
|
+
invalidPhone: 'Invalid phone number',
|
|
121
|
+
invalidPassword: 'Invalid password. Passwords must be at least 8 characters and include only letters and numbers and any of these special characters: !@#$%^&_-+=<>.',
|
|
122
|
+
invalidToken: 'Password reset token is invalid or expired. Please resubmit your password reset request via the login form.',
|
|
123
|
+
requiredField: 'This field is required',
|
|
124
|
+
invalidFilename: 'Invalid filename. Please rename the file and try again.',
|
|
125
|
+
notExist: 'The requested entity does not exist.',
|
|
126
|
+
serverError: 'Unknown error. Please contact Open Tender support.',
|
|
127
|
+
invalidHours: 'One or more invalid times submitted. Please see below.',
|
|
128
|
+
revenueCenterClosed: 'This location is closed or otherwise not able to accept orders at the selected time. Please try changing your order time.',
|
|
129
|
+
serviceTypeNotAvailable: 'This location does not offer the selected service type at this time. Please switch to another service type.',
|
|
130
|
+
notInZone: 'Selected address not in the delivery zone for this revenue center',
|
|
131
|
+
missingAddress: 'An address is required for delivery orders. Please add one.',
|
|
132
|
+
orderNotFound: "Sorry, but we couldn't find an order matching that ID. Please try again.",
|
|
133
|
+
distanceSurcharge: "Distance-based surcharges can't be applied to orders with requested times in the past. Please adjust your requested delivery time.",
|
|
134
|
+
missingAddressDeliveryZone: "Please add an address for this revenue center or the revenue center's parent store before setting a delivery zone"
|
|
135
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { GuestData } from '@open-tender/types';
|
|
2
|
+
export declare const isString: (str: any) => boolean;
|
|
3
|
+
export declare const isObject: (obj: any) => boolean;
|
|
4
|
+
export declare const isEmpty: (obj?: Record<string | number, unknown> | null) => boolean;
|
|
5
|
+
export declare const isNum: (s: string) => boolean;
|
|
6
|
+
export declare const contains: (arr: Array<any>, values: Array<any>) => boolean;
|
|
7
|
+
export declare const slugify: (text: string) => string;
|
|
8
|
+
export declare const stripTags: (s: string) => string;
|
|
9
|
+
export declare const serialize: (obj: Record<string | number, string | number | boolean>) => string;
|
|
10
|
+
export declare const capitalize: (s: string) => string;
|
|
11
|
+
export declare const cleanPhone: (phone: string) => string;
|
|
12
|
+
export declare const makePhone: (phone: string) => string;
|
|
13
|
+
export declare const validatePhone: (phone: string) => boolean;
|
|
14
|
+
export declare const makeBirthDate: (birthDate: string) => string;
|
|
15
|
+
export declare const slashesToDashes: (birthDate: string) => string | null;
|
|
16
|
+
export declare const dashesToSlashes: (birthDate?: string | null) => string | null;
|
|
17
|
+
export declare const validateEmail: (email: string) => boolean;
|
|
18
|
+
export declare const checkEmpty: (data: Record<string | number, unknown>) => boolean;
|
|
19
|
+
export declare const checkGuestData: (data: GuestData, email: string) => {
|
|
20
|
+
guestData: {
|
|
21
|
+
first_name: string;
|
|
22
|
+
last_name: string;
|
|
23
|
+
phone: string;
|
|
24
|
+
email: string;
|
|
25
|
+
};
|
|
26
|
+
guestIncomplete: boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare const makeRandomNumberString: () => string;
|
|
29
|
+
export declare const getWidth: () => number;
|
|
30
|
+
export declare const getHeight: () => number;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export const isString = (str) => {
|
|
2
|
+
return typeof str === 'string';
|
|
3
|
+
};
|
|
4
|
+
export const isObject = (obj) => {
|
|
5
|
+
return typeof obj === 'object' && obj !== null;
|
|
6
|
+
};
|
|
7
|
+
export const isEmpty = (obj) => {
|
|
8
|
+
return (!obj || (obj.constructor === Object && Object.entries(obj).length === 0));
|
|
9
|
+
};
|
|
10
|
+
export const isNum = (s) => /^\d+$/.test(s);
|
|
11
|
+
export const contains = (arr, values) => {
|
|
12
|
+
return values.filter(i => arr.includes(i)).length > 0;
|
|
13
|
+
};
|
|
14
|
+
// https://gist.github.com/mathewbyrne/1280286
|
|
15
|
+
export const slugify = (text) => {
|
|
16
|
+
return text
|
|
17
|
+
.toString()
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.replace('_', '-') // replace _ with -
|
|
20
|
+
.replace(/\s+/g, '-') // Replace spaces with -
|
|
21
|
+
.replace(/[^\w-]+/g, '') // Remove all non-word chars
|
|
22
|
+
.replace(/--+/g, '-') // Replace multiple - with single -
|
|
23
|
+
.replace(/^-+/, '') // Trim - from start of text
|
|
24
|
+
.replace(/-+$/, ''); // Trim - from end of text
|
|
25
|
+
};
|
|
26
|
+
export const stripTags = (s) => s.replace(/(<([^>]+)>)/gi, '').replace('&', '&');
|
|
27
|
+
export const serialize = (obj) => {
|
|
28
|
+
const str = [];
|
|
29
|
+
for (const p in obj)
|
|
30
|
+
if (Object.prototype.hasOwnProperty.call(obj, p)) {
|
|
31
|
+
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
|
|
32
|
+
}
|
|
33
|
+
return str.join('&');
|
|
34
|
+
};
|
|
35
|
+
export const capitalize = (s) => {
|
|
36
|
+
if (!s || !s.length)
|
|
37
|
+
return '';
|
|
38
|
+
return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
|
|
39
|
+
};
|
|
40
|
+
export const cleanPhone = (phone) => {
|
|
41
|
+
if (!phone)
|
|
42
|
+
return '';
|
|
43
|
+
let p = phone.replace(/\D/g, '');
|
|
44
|
+
if (p.length > 11)
|
|
45
|
+
return phone;
|
|
46
|
+
p = p.length === 11 && p[0] === '1' ? p.slice(1, 11) : p;
|
|
47
|
+
p =
|
|
48
|
+
p.length === 10 ? `${p.slice(0, 3)}-${p.slice(3, 6)}-${p.slice(6, 10)}` : p;
|
|
49
|
+
return p;
|
|
50
|
+
};
|
|
51
|
+
export const makePhone = (phone) => {
|
|
52
|
+
if (!phone)
|
|
53
|
+
return '';
|
|
54
|
+
const p = phone.replace(/\D/g, '');
|
|
55
|
+
if (p.length > 6) {
|
|
56
|
+
return `${p.slice(0, 3)}-${p.slice(3, 6)}-${p.slice(6, 10)}`;
|
|
57
|
+
}
|
|
58
|
+
else if (p.length > 3) {
|
|
59
|
+
return `${p.slice(0, 3)}-${p.slice(3, 6)}`;
|
|
60
|
+
}
|
|
61
|
+
return p;
|
|
62
|
+
};
|
|
63
|
+
export const validatePhone = (phone) => {
|
|
64
|
+
var _a;
|
|
65
|
+
if (!phone)
|
|
66
|
+
return false;
|
|
67
|
+
return ((_a = phone.match(/\d/g)) === null || _a === void 0 ? void 0 : _a.length) === 10;
|
|
68
|
+
};
|
|
69
|
+
export const makeBirthDate = (birthDate) => {
|
|
70
|
+
if (!birthDate)
|
|
71
|
+
return '';
|
|
72
|
+
const b = birthDate.replace(/\D/g, '');
|
|
73
|
+
if (b.length > 4) {
|
|
74
|
+
return `${b.slice(0, 2)}/${b.slice(2, 4)}/${b.slice(4, 8)}`;
|
|
75
|
+
}
|
|
76
|
+
else if (b.length > 2) {
|
|
77
|
+
return `${b.slice(0, 2)}/${b.slice(2, 4)}`;
|
|
78
|
+
}
|
|
79
|
+
return b;
|
|
80
|
+
};
|
|
81
|
+
export const slashesToDashes = (birthDate) => {
|
|
82
|
+
if (!birthDate)
|
|
83
|
+
return null;
|
|
84
|
+
const parts = birthDate.split('/');
|
|
85
|
+
return `${parts[2] || ''}-${parts[0] || ''}-${parts[1] || ''}`;
|
|
86
|
+
};
|
|
87
|
+
export const dashesToSlashes = (birthDate) => {
|
|
88
|
+
if (!birthDate)
|
|
89
|
+
return null;
|
|
90
|
+
const parts = birthDate.split('-');
|
|
91
|
+
return `${parts[1] || ''}/${parts[2] || ''}/${parts[0] || ''}`;
|
|
92
|
+
};
|
|
93
|
+
export const validateEmail = (email) => {
|
|
94
|
+
const re =
|
|
95
|
+
// eslint-disable-next-line no-useless-escape
|
|
96
|
+
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
97
|
+
return re.test(email);
|
|
98
|
+
};
|
|
99
|
+
export const checkEmpty = (data) => {
|
|
100
|
+
if (isEmpty(data))
|
|
101
|
+
return true;
|
|
102
|
+
return Object.values(data).filter(i => !i).length > 0;
|
|
103
|
+
};
|
|
104
|
+
export const checkGuestData = (data, email) => {
|
|
105
|
+
const { first_name, last_name, phone } = data;
|
|
106
|
+
const guestData = { first_name, last_name, phone, email };
|
|
107
|
+
const validPhone = validatePhone(phone) ? phone : null;
|
|
108
|
+
const guestIncomplete = checkEmpty(Object.assign(Object.assign({}, guestData), { phone: validPhone }));
|
|
109
|
+
return { guestData, guestIncomplete };
|
|
110
|
+
};
|
|
111
|
+
export const makeRandomNumberString = () => Math.floor(Math.random() * 1000000000).toString();
|
|
112
|
+
export const getWidth = () => {
|
|
113
|
+
return Math.max(document.body.scrollWidth, document.documentElement.scrollWidth, document.body.offsetWidth, document.documentElement.offsetWidth, document.documentElement.clientWidth);
|
|
114
|
+
};
|
|
115
|
+
export const getHeight = () => {
|
|
116
|
+
return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.documentElement.clientHeight);
|
|
117
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './cards';
|
|
2
|
+
export * from './cart';
|
|
3
|
+
export * from './checkout';
|
|
4
|
+
export * from './constants';
|
|
5
|
+
export * from './customer';
|
|
6
|
+
export * from './datetimes';
|
|
7
|
+
export * from './errors';
|
|
8
|
+
export * from './helpers';
|
|
9
|
+
export * from './keypad';
|
|
10
|
+
export * from './maps';
|
|
11
|
+
export * from './refunds';
|
|
12
|
+
export * from './rewards';
|
|
13
|
+
export * from './version';
|
|
14
|
+
export * from './orders';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './cards';
|
|
2
|
+
export * from './cart';
|
|
3
|
+
export * from './checkout';
|
|
4
|
+
export * from './constants';
|
|
5
|
+
export * from './customer';
|
|
6
|
+
export * from './datetimes';
|
|
7
|
+
export * from './errors';
|
|
8
|
+
export * from './helpers';
|
|
9
|
+
export * from './keypad';
|
|
10
|
+
export * from './maps';
|
|
11
|
+
export * from './refunds';
|
|
12
|
+
export * from './rewards';
|
|
13
|
+
export * from './version';
|
|
14
|
+
export * from './orders';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const centsToDollars: (cents: number) => string;
|
|
2
|
+
export declare const buttonsKeypad: string[][];
|
|
3
|
+
export declare const buttonsNumpad: string[][];
|
|
4
|
+
export declare const buttonsDollars: string[][];
|
|
5
|
+
export declare const buttonsCheckout: string[][];
|
|
6
|
+
export declare const reduceKeypad: (value: string, key: string) => string;
|
|
7
|
+
export declare const reduceNumpad: (value: string, key: string, clear: boolean) => string;
|
|
8
|
+
export declare const reduceDollars: (value: string, key: string, clear: boolean) => string;
|
|
9
|
+
export declare const reduceCheckout: (value: string, key: string, clear: boolean) => string;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export const centsToDollars = (cents) => (cents / 100).toFixed(2);
|
|
2
|
+
export const buttonsKeypad = [
|
|
3
|
+
'1234567890'.split(''),
|
|
4
|
+
'qwertyuiop'.split(''),
|
|
5
|
+
'asdfghjkl'.split(''),
|
|
6
|
+
['Clr', ...'zxcvbnm'.split(''), 'Del']
|
|
7
|
+
];
|
|
8
|
+
export const buttonsNumpad = [
|
|
9
|
+
'123'.split(''),
|
|
10
|
+
'456'.split(''),
|
|
11
|
+
'789'.split(''),
|
|
12
|
+
['Clr', '0', 'Del']
|
|
13
|
+
];
|
|
14
|
+
export const buttonsDollars = [
|
|
15
|
+
'123'.split(''),
|
|
16
|
+
'456'.split(''),
|
|
17
|
+
'789'.split(''),
|
|
18
|
+
['Clr', '0', '00']
|
|
19
|
+
];
|
|
20
|
+
export const buttonsCheckout = [
|
|
21
|
+
['1', '2', '3', '$5'],
|
|
22
|
+
['4', '5', '6', '$10'],
|
|
23
|
+
['7', '8', '9', '$20'],
|
|
24
|
+
['Clr', '0', '00', 'Next $']
|
|
25
|
+
];
|
|
26
|
+
export const reduceKeypad = (value, key) => {
|
|
27
|
+
switch (key) {
|
|
28
|
+
case 'Clear':
|
|
29
|
+
case 'Clr':
|
|
30
|
+
return '';
|
|
31
|
+
case 'Delete':
|
|
32
|
+
case 'Del':
|
|
33
|
+
return value.slice(0, -1);
|
|
34
|
+
case 'Space':
|
|
35
|
+
return value + ' ';
|
|
36
|
+
default:
|
|
37
|
+
return value + key;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const reduceNumpad = (value, key, clear) => {
|
|
41
|
+
const current = clear ? '' : value;
|
|
42
|
+
switch (key) {
|
|
43
|
+
case 'Clear':
|
|
44
|
+
case 'Clr':
|
|
45
|
+
return '';
|
|
46
|
+
case 'Delete':
|
|
47
|
+
case 'Del':
|
|
48
|
+
return value.slice(0, -1);
|
|
49
|
+
default:
|
|
50
|
+
return current + key;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export const reduceDollars = (value, key, clear) => {
|
|
54
|
+
const current = clear ? '' : value;
|
|
55
|
+
switch (key) {
|
|
56
|
+
case 'Clear':
|
|
57
|
+
case 'Clr':
|
|
58
|
+
return '0.00';
|
|
59
|
+
default: {
|
|
60
|
+
const val = parseInt(current.replace('.', '') + key);
|
|
61
|
+
return centsToDollars(val);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
export const reduceCheckout = (value, key, clear) => {
|
|
66
|
+
const current = !key.toString().includes('$') && clear ? '' : value;
|
|
67
|
+
switch (key) {
|
|
68
|
+
case 'Clear':
|
|
69
|
+
case 'Clr':
|
|
70
|
+
return '0.00';
|
|
71
|
+
case 'Next $': {
|
|
72
|
+
const [dollars] = current.split('.');
|
|
73
|
+
const val = (parseInt(dollars) + 1) * 100;
|
|
74
|
+
return centsToDollars(val);
|
|
75
|
+
}
|
|
76
|
+
case '$5':
|
|
77
|
+
case '$10':
|
|
78
|
+
case '$20': {
|
|
79
|
+
const keyValue = parseInt(key.replace('$', '')) * 100;
|
|
80
|
+
const [dollars, cents] = current.split('.').map(n => parseInt(n));
|
|
81
|
+
let val;
|
|
82
|
+
if (cents > 0 || dollars % 10 > 0) {
|
|
83
|
+
val =
|
|
84
|
+
Math.floor(parseInt(current.replace('.', '')) / keyValue) * keyValue +
|
|
85
|
+
keyValue;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
val = dollars * 100 + keyValue;
|
|
89
|
+
}
|
|
90
|
+
return centsToDollars(val);
|
|
91
|
+
}
|
|
92
|
+
default: {
|
|
93
|
+
const val = parseInt(current.replace('.', '') + key);
|
|
94
|
+
return centsToDollars(val);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { Address, CustomerRevenueCenter, CustomerRevenueCenters, ServiceType } from '@open-tender/types';
|
|
2
|
+
export interface Point {
|
|
3
|
+
lat: number;
|
|
4
|
+
lng: number;
|
|
5
|
+
}
|
|
6
|
+
export interface GooglePlaceAddressComponent {
|
|
7
|
+
types: Array<string | 'postal_code' | 'street_number' | 'route' | 'locality' | 'sublocality_level_1' | 'administrative_area_level_1'>;
|
|
8
|
+
long_name?: string;
|
|
9
|
+
short_name?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare enum GooglePlaceBusinessStatus {
|
|
12
|
+
OPERATIONAL = "OPERATIONAL",
|
|
13
|
+
CLOSED_TEMPORARILY = "CLOSED_TEMPORARILY",
|
|
14
|
+
CLOSED_PERMANENTLY = "CLOSED_PERMANENTLY"
|
|
15
|
+
}
|
|
16
|
+
export interface GooglePlaceAdressGeometry {
|
|
17
|
+
location: Point;
|
|
18
|
+
viewport: Record<string, Point>;
|
|
19
|
+
}
|
|
20
|
+
export interface GooglePlace {
|
|
21
|
+
address_components: Array<GooglePlaceAddressComponent>;
|
|
22
|
+
business_status?: GooglePlaceBusinessStatus;
|
|
23
|
+
formatted_address: string;
|
|
24
|
+
formatted_phone_number: string;
|
|
25
|
+
geometry: GooglePlaceAdressGeometry;
|
|
26
|
+
permanently_closed?: boolean;
|
|
27
|
+
html_attributions?: Array<string>;
|
|
28
|
+
name: string;
|
|
29
|
+
}
|
|
30
|
+
export interface AddressName {
|
|
31
|
+
long_name: string;
|
|
32
|
+
short_name: string;
|
|
33
|
+
}
|
|
34
|
+
export interface GooglePlaceComponent {
|
|
35
|
+
street_number: AddressName;
|
|
36
|
+
route: AddressName;
|
|
37
|
+
locality: AddressName;
|
|
38
|
+
sublocality_level_1: AddressName;
|
|
39
|
+
administrative_area_level_1: AddressName;
|
|
40
|
+
postal_code: AddressName;
|
|
41
|
+
}
|
|
42
|
+
export declare const makeAddress: (place: GooglePlace) => {
|
|
43
|
+
street: string;
|
|
44
|
+
city: string;
|
|
45
|
+
state: string;
|
|
46
|
+
postal_code: string;
|
|
47
|
+
lat: number | null;
|
|
48
|
+
lng: number | null;
|
|
49
|
+
formatted_address: string;
|
|
50
|
+
};
|
|
51
|
+
export declare const getDistance: (pointA: Point, pointB: Point, inMiles?: boolean) => number;
|
|
52
|
+
export declare const inZone: (address: Point, polygon: number[][]) => boolean;
|
|
53
|
+
export declare const addDistance: (revenueCenters: CustomerRevenueCenters, address: Point) => CustomerRevenueCenters;
|
|
54
|
+
export declare const sortRevenueCenters: (revenueCenters: CustomerRevenueCenters, isDelivery?: boolean) => CustomerRevenueCenter[];
|
|
55
|
+
export declare const calcMinDistance: (revenueCenters: CustomerRevenueCenters, maxDistance?: number) => number;
|
|
56
|
+
export declare const checkServiceType: (revenueCenter: CustomerRevenueCenter, serviceType: ServiceType) => boolean;
|
|
57
|
+
export declare const makePickupRevenueCenters: (revenueCenters: Array<CustomerRevenueCenter>, maxDistance?: number) => CustomerRevenueCenter[];
|
|
58
|
+
export declare const makeWalkinRevenueCenters: (revenueCenters: Array<CustomerRevenueCenter>, maxDistance?: number) => CustomerRevenueCenter[];
|
|
59
|
+
export declare const makeDeliveryRevenueCenters: (revenueCenters: Array<CustomerRevenueCenter>) => CustomerRevenueCenter[];
|
|
60
|
+
export declare const makePickupMesssaging: (address: Address, geoLatLng: any, count: number, minDistance: number, maxDistance?: number, messages?: {
|
|
61
|
+
PICKUP: {
|
|
62
|
+
default: {
|
|
63
|
+
title: string;
|
|
64
|
+
msg: string;
|
|
65
|
+
};
|
|
66
|
+
address: {
|
|
67
|
+
title: string;
|
|
68
|
+
msg: string;
|
|
69
|
+
};
|
|
70
|
+
addressFar: {
|
|
71
|
+
title: string;
|
|
72
|
+
msg: string;
|
|
73
|
+
};
|
|
74
|
+
geo: {
|
|
75
|
+
title: string;
|
|
76
|
+
msg: string;
|
|
77
|
+
};
|
|
78
|
+
geoFar: {
|
|
79
|
+
title: string;
|
|
80
|
+
msg: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
DELIVERY: {
|
|
84
|
+
default: {
|
|
85
|
+
title: string;
|
|
86
|
+
msg: string;
|
|
87
|
+
error: null;
|
|
88
|
+
};
|
|
89
|
+
noStreet: {
|
|
90
|
+
title: string;
|
|
91
|
+
msg: string;
|
|
92
|
+
error: string;
|
|
93
|
+
};
|
|
94
|
+
hasDelivery: {
|
|
95
|
+
title: string;
|
|
96
|
+
msg: string;
|
|
97
|
+
error: null;
|
|
98
|
+
};
|
|
99
|
+
noDelivery: {
|
|
100
|
+
title: string;
|
|
101
|
+
msg: string;
|
|
102
|
+
error: null;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
}) => {
|
|
106
|
+
title: string;
|
|
107
|
+
msg: string;
|
|
108
|
+
};
|
|
109
|
+
export declare const makeWalkinMessaging: (address: Address, geoLatLng: any, count: number, minDistance: number, maxDistance?: number, messages?: {
|
|
110
|
+
PICKUP: {
|
|
111
|
+
default: {
|
|
112
|
+
title: string;
|
|
113
|
+
msg: string;
|
|
114
|
+
};
|
|
115
|
+
address: {
|
|
116
|
+
title: string;
|
|
117
|
+
msg: string;
|
|
118
|
+
};
|
|
119
|
+
addressFar: {
|
|
120
|
+
title: string;
|
|
121
|
+
msg: string;
|
|
122
|
+
};
|
|
123
|
+
geo: {
|
|
124
|
+
title: string;
|
|
125
|
+
msg: string;
|
|
126
|
+
};
|
|
127
|
+
geoFar: {
|
|
128
|
+
title: string;
|
|
129
|
+
msg: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
DELIVERY: {
|
|
133
|
+
default: {
|
|
134
|
+
title: string;
|
|
135
|
+
msg: string;
|
|
136
|
+
error: null;
|
|
137
|
+
};
|
|
138
|
+
noStreet: {
|
|
139
|
+
title: string;
|
|
140
|
+
msg: string;
|
|
141
|
+
error: string;
|
|
142
|
+
};
|
|
143
|
+
hasDelivery: {
|
|
144
|
+
title: string;
|
|
145
|
+
msg: string;
|
|
146
|
+
error: null;
|
|
147
|
+
};
|
|
148
|
+
noDelivery: {
|
|
149
|
+
title: string;
|
|
150
|
+
msg: string;
|
|
151
|
+
error: null;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
}) => {
|
|
155
|
+
title: string;
|
|
156
|
+
msg: string;
|
|
157
|
+
};
|
|
158
|
+
export declare const makeDeliveryMesssaging: (address: Address, count: number, messages?: {
|
|
159
|
+
PICKUP: {
|
|
160
|
+
default: {
|
|
161
|
+
title: string;
|
|
162
|
+
msg: string;
|
|
163
|
+
};
|
|
164
|
+
address: {
|
|
165
|
+
title: string;
|
|
166
|
+
msg: string;
|
|
167
|
+
};
|
|
168
|
+
addressFar: {
|
|
169
|
+
title: string;
|
|
170
|
+
msg: string;
|
|
171
|
+
};
|
|
172
|
+
geo: {
|
|
173
|
+
title: string;
|
|
174
|
+
msg: string;
|
|
175
|
+
};
|
|
176
|
+
geoFar: {
|
|
177
|
+
title: string;
|
|
178
|
+
msg: string;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
DELIVERY: {
|
|
182
|
+
default: {
|
|
183
|
+
title: string;
|
|
184
|
+
msg: string;
|
|
185
|
+
error: null;
|
|
186
|
+
};
|
|
187
|
+
noStreet: {
|
|
188
|
+
title: string;
|
|
189
|
+
msg: string;
|
|
190
|
+
error: string;
|
|
191
|
+
};
|
|
192
|
+
hasDelivery: {
|
|
193
|
+
title: string;
|
|
194
|
+
msg: string;
|
|
195
|
+
error: null;
|
|
196
|
+
};
|
|
197
|
+
noDelivery: {
|
|
198
|
+
title: string;
|
|
199
|
+
msg: string;
|
|
200
|
+
error: null;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
}) => {
|
|
204
|
+
title: string;
|
|
205
|
+
msg: string;
|
|
206
|
+
error: null;
|
|
207
|
+
} | {
|
|
208
|
+
title: string;
|
|
209
|
+
msg: string;
|
|
210
|
+
error: string;
|
|
211
|
+
};
|
|
212
|
+
export declare const makeDisplayedRevenueCenters: (revenueCenters: Array<CustomerRevenueCenter>, serviceType: ServiceType, address: Address, geoLatLng: any, maxDistance: number) => {
|
|
213
|
+
title: string;
|
|
214
|
+
msg: string;
|
|
215
|
+
error: string | null;
|
|
216
|
+
displayed: CustomerRevenueCenter[];
|
|
217
|
+
};
|
|
218
|
+
export declare const LOCATIONS_MESSAGES: {
|
|
219
|
+
PICKUP: {
|
|
220
|
+
default: {
|
|
221
|
+
title: string;
|
|
222
|
+
msg: string;
|
|
223
|
+
};
|
|
224
|
+
address: {
|
|
225
|
+
title: string;
|
|
226
|
+
msg: string;
|
|
227
|
+
};
|
|
228
|
+
addressFar: {
|
|
229
|
+
title: string;
|
|
230
|
+
msg: string;
|
|
231
|
+
};
|
|
232
|
+
geo: {
|
|
233
|
+
title: string;
|
|
234
|
+
msg: string;
|
|
235
|
+
};
|
|
236
|
+
geoFar: {
|
|
237
|
+
title: string;
|
|
238
|
+
msg: string;
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
DELIVERY: {
|
|
242
|
+
default: {
|
|
243
|
+
title: string;
|
|
244
|
+
msg: string;
|
|
245
|
+
error: null;
|
|
246
|
+
};
|
|
247
|
+
noStreet: {
|
|
248
|
+
title: string;
|
|
249
|
+
msg: string;
|
|
250
|
+
error: string;
|
|
251
|
+
};
|
|
252
|
+
hasDelivery: {
|
|
253
|
+
title: string;
|
|
254
|
+
msg: string;
|
|
255
|
+
error: null;
|
|
256
|
+
};
|
|
257
|
+
noDelivery: {
|
|
258
|
+
title: string;
|
|
259
|
+
msg: string;
|
|
260
|
+
error: null;
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
export declare const renameLocation: (str: unknown, names: Array<string>) => unknown;
|