@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,63 @@
|
|
|
1
|
+
import { formatDollars, formatQuantity } from './cart';
|
|
2
|
+
import { loyaltyType } from './constants';
|
|
3
|
+
import { getMinutesfromDate, time24ToMinutes } from './datetimes';
|
|
4
|
+
export const makeValidDeals = (deals, orderType, serviceType, revenueCenterId) => {
|
|
5
|
+
if (!deals || !deals.length)
|
|
6
|
+
return [];
|
|
7
|
+
if (orderType) {
|
|
8
|
+
deals = deals.filter(i => !i.order_type || i.order_type === orderType);
|
|
9
|
+
}
|
|
10
|
+
if (serviceType) {
|
|
11
|
+
deals = deals.filter(i => !i.service_type || i.service_type === serviceType);
|
|
12
|
+
}
|
|
13
|
+
if (revenueCenterId) {
|
|
14
|
+
deals = deals.filter(i => {
|
|
15
|
+
var _a;
|
|
16
|
+
return !((_a = i.revenue_centers) === null || _a === void 0 ? void 0 : _a.length) ||
|
|
17
|
+
i.revenue_centers
|
|
18
|
+
.map(r => r.revenue_center_id)
|
|
19
|
+
.includes(revenueCenterId);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const minutes = getMinutesfromDate(new Date());
|
|
23
|
+
deals = deals.filter(i => {
|
|
24
|
+
if (!i.dayparts.length)
|
|
25
|
+
return true;
|
|
26
|
+
const validDayparts = i.dayparts.filter(d => {
|
|
27
|
+
const start = time24ToMinutes(d.start_time);
|
|
28
|
+
const end = time24ToMinutes(d.end_time);
|
|
29
|
+
return start <= minutes && minutes <= end;
|
|
30
|
+
});
|
|
31
|
+
return validDayparts.length > 0;
|
|
32
|
+
});
|
|
33
|
+
return deals;
|
|
34
|
+
};
|
|
35
|
+
export const makeStatus = (tiers, status, points) => {
|
|
36
|
+
if (!tiers)
|
|
37
|
+
return null;
|
|
38
|
+
const highest = parseFloat(tiers[tiers.length - 1].threshold);
|
|
39
|
+
const total = highest * 1.2;
|
|
40
|
+
const progress = Math.min((parseFloat(status.progress) / total) * 100, 100);
|
|
41
|
+
const progressTiers = tiers.map(i => (Object.assign(Object.assign({}, i), { points, percentage: (parseFloat(i.threshold) / total) * 100, color: `#${i.hex_code}`, value: !points
|
|
42
|
+
? `${formatDollars(i.threshold, '', 0)}`
|
|
43
|
+
: `${formatQuantity(i.threshold)}` })));
|
|
44
|
+
const daysMsg = status.days === 7300 ? 'all-time' : `last ${status.days} days`;
|
|
45
|
+
const progressAmt = !points
|
|
46
|
+
? formatDollars(status.progress, '', 0)
|
|
47
|
+
: formatQuantity(status.progress);
|
|
48
|
+
const progressMsg = !points
|
|
49
|
+
? `${progressAmt} spent ${daysMsg}`
|
|
50
|
+
: `${progressAmt} ${points.name.toLowerCase()} earned ${daysMsg}`;
|
|
51
|
+
return { progress, progressMsg, tiers: progressTiers };
|
|
52
|
+
};
|
|
53
|
+
export const makeProgress = (loyalty_type, spend, redemption) => {
|
|
54
|
+
var _a;
|
|
55
|
+
if (!spend || !redemption || !loyalty_type)
|
|
56
|
+
return null;
|
|
57
|
+
const currentSpend = parseFloat((_a = spend.current) !== null && _a !== void 0 ? _a : '0');
|
|
58
|
+
const threshold = parseFloat(redemption.threshold);
|
|
59
|
+
const progress = loyalty_type === loyaltyType.CREDIT
|
|
60
|
+
? (currentSpend / threshold) * 100
|
|
61
|
+
: null;
|
|
62
|
+
return progress;
|
|
63
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// https://dev.to/flexdinesh/cache-busting-a-react-app-22lk
|
|
2
|
+
// https://github.com/flexdinesh/cache-busting-example/blob/master/src/App.js
|
|
3
|
+
let global;
|
|
4
|
+
// version from response - first param, local version second param
|
|
5
|
+
const semverGreaterThan = (latest, current) => {
|
|
6
|
+
if (!latest || !current)
|
|
7
|
+
return false;
|
|
8
|
+
const versionsA = latest.split(/\./g);
|
|
9
|
+
const versionsB = current.split(/\./g);
|
|
10
|
+
while (versionsA.length || versionsB.length) {
|
|
11
|
+
const a = Number(versionsA.shift());
|
|
12
|
+
const b = Number(versionsB.shift());
|
|
13
|
+
// eslint-disable-next-line no-continue
|
|
14
|
+
if (a === b)
|
|
15
|
+
continue;
|
|
16
|
+
// eslint-disable-next-line no-restricted-globals
|
|
17
|
+
return a > b || isNaN(b);
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
21
|
+
export const maybeRefreshVersion = (open) => {
|
|
22
|
+
fetch('/meta.json', { cache: 'no-store' })
|
|
23
|
+
.then(response => response.json())
|
|
24
|
+
.then(meta => {
|
|
25
|
+
const latest = meta.version;
|
|
26
|
+
const current = global.appVersion;
|
|
27
|
+
// console.log(latest, current)
|
|
28
|
+
const shouldForceRefresh = semverGreaterThan(latest, current);
|
|
29
|
+
if (shouldForceRefresh) {
|
|
30
|
+
open({ type: 'version', args: { latest, current, preventClose: true } });
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
.catch(err => console.log(err));
|
|
34
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@open-tender/utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/esm/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "rm -rf ./dist/ && yarn build:esm && yarn build:cjs",
|
|
13
|
+
"build:esm": "tsc",
|
|
14
|
+
"build:cjs": "tsc --module commonjs --outDir dist/cjs",
|
|
15
|
+
"lint": "eslint \"{**/*,*}.{js,ts,jsx,tsx}\"",
|
|
16
|
+
"prettier": "prettier --write \"{src,tests,example/src}/**/*.{js,ts,jsx,tsx}\""
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/open-tender/open-tender-utils",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/open-tender/open-tender-utils/issues"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"url": "https://github.com/open-tender/open-tender-utils.git",
|
|
24
|
+
"type": "git"
|
|
25
|
+
},
|
|
26
|
+
"author": "JC Harrington <jc@opentender.io>",
|
|
27
|
+
"keywords": [
|
|
28
|
+
"open-tender",
|
|
29
|
+
"react",
|
|
30
|
+
"redux",
|
|
31
|
+
"ecommerce",
|
|
32
|
+
"restaurants"
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"private": false,
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@babel/core": "^7.19.1",
|
|
38
|
+
"@emotion/react": "^11.10.4",
|
|
39
|
+
"@reduxjs/toolkit": "^1.8.5",
|
|
40
|
+
"@types/react": "^18.0.18",
|
|
41
|
+
"@types/react-dom": "^18.0.6",
|
|
42
|
+
"@types/uuid": "^8.3.4",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
44
|
+
"@typescript-eslint/parser": "^5.36.2",
|
|
45
|
+
"eslint": "^8.23.0",
|
|
46
|
+
"eslint-config-prettier": "^8.5.0",
|
|
47
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
48
|
+
"eslint-plugin-react": "^7.31.7",
|
|
49
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
50
|
+
"prettier": "^2.7.1",
|
|
51
|
+
"react": "^18.2.0",
|
|
52
|
+
"react-redux": "^8.0.2",
|
|
53
|
+
"typescript": "^4.8.2"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@reduxjs/toolkit": "^1.8.5",
|
|
57
|
+
"react": "^18.2.0"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@open-tender/types": "^0.0.30",
|
|
61
|
+
"date-fns": "^2.29.3",
|
|
62
|
+
"date-fns-tz": "^1.3.7",
|
|
63
|
+
"ts-transformer-keys": "^0.4.3"
|
|
64
|
+
}
|
|
65
|
+
}
|