@open-tender/utils 0.0.26 → 0.0.28
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/cart.d.ts +1 -0
- package/dist/cjs/utils/cart.js +32 -1
- package/dist/cjs/utils/customer.d.ts +1 -0
- package/dist/cjs/utils/customer.js +14 -3
- package/dist/esm/utils/cart.d.ts +1 -0
- package/dist/esm/utils/cart.js +30 -0
- package/dist/esm/utils/customer.d.ts +1 -0
- package/dist/esm/utils/customer.js +13 -2
- package/package.json +2 -3
package/dist/cjs/utils/cart.d.ts
CHANGED
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.makeUpsellItems = exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.calcCartCounts = exports.makeFullAddress = exports.makeOrderAddress = exports.makeFavoritesLookup = exports.makeUniqueDisplayItems = exports.makeDisplayItems = exports.makeDisplayItem = exports.makeDisplayItemGroups = exports.makeCartItemSignature = exports.makeItemSignature = exports.makeItemImageUrl = exports.combineCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.makeOrderItem = exports.calcPrices = exports.makeRevenueCenterMsg = exports.makeNotAcceptingOrdersMsg = exports.makeOrderTypeName = exports.makeServiceTypeName = exports.makeOrderTypeFromParam = exports.convertStringToArray = exports.makeModifierNames = exports.getItemOptions = exports.formatDollars = exports.formatQuantity = exports.addCommas = exports.makeDisplayPrice = exports.displayPrice = void 0;
|
|
3
|
+
exports.calcNutrition = exports.makeUpsellItems = exports.checkAmountRemaining = exports.prepareOrder = exports.getDefaultTip = exports.validateCart = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.calcCartCounts = exports.makeFullAddress = exports.makeOrderAddress = exports.makeFavoritesLookup = exports.makeUniqueDisplayItems = exports.makeDisplayItems = exports.makeDisplayItem = exports.makeDisplayItemGroups = exports.makeCartItemSignature = exports.makeItemSignature = exports.makeItemImageUrl = exports.combineCarts = exports.makeGuestLookup = exports.rehydrateCheckoutForm = exports.rehydrateCart = exports.rehydrateOrderItem = exports.makeOrderItem = exports.calcPrices = exports.makeRevenueCenterMsg = exports.makeNotAcceptingOrdersMsg = exports.makeOrderTypeName = exports.makeServiceTypeName = exports.makeOrderTypeFromParam = exports.convertStringToArray = exports.makeModifierNames = exports.getItemOptions = exports.formatDollars = exports.formatQuantity = exports.addCommas = exports.makeDisplayPrice = exports.displayPrice = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
const datetimes_1 = require("./datetimes");
|
|
6
6
|
const helpers_1 = require("./helpers");
|
|
@@ -860,3 +860,34 @@ const makeUpsellItems = (itemIds, itemLookup) => {
|
|
|
860
860
|
});
|
|
861
861
|
};
|
|
862
862
|
exports.makeUpsellItems = makeUpsellItems;
|
|
863
|
+
const nutritionKeys = [
|
|
864
|
+
'calories',
|
|
865
|
+
'cholesterol',
|
|
866
|
+
'dietary_fiber',
|
|
867
|
+
'protein',
|
|
868
|
+
'saturated_fat',
|
|
869
|
+
'sodium',
|
|
870
|
+
'sugars',
|
|
871
|
+
'total_carbs',
|
|
872
|
+
'total_fat',
|
|
873
|
+
'trans_fat',
|
|
874
|
+
];
|
|
875
|
+
const calcNutrition = (item) => {
|
|
876
|
+
const { nutritionalInfo, groups } = item;
|
|
877
|
+
let nutrition = nutritionalInfo ? Object.assign({}, nutritionalInfo) : {};
|
|
878
|
+
const options = groups.reduce((arr, g) => {
|
|
879
|
+
var _a, _b;
|
|
880
|
+
return [...arr, ...((_b = (_a = g.options) === null || _a === void 0 ? void 0 : _a.filter((o) => { var _a; return ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0) > 0; })) !== null && _b !== void 0 ? _b : [])];
|
|
881
|
+
}, []);
|
|
882
|
+
options.forEach((o) => {
|
|
883
|
+
nutritionKeys === null || nutritionKeys === void 0 ? void 0 : nutritionKeys.forEach((key) => {
|
|
884
|
+
const optionVal = o.nutritionalInfo
|
|
885
|
+
? parseInt(o.nutritionalInfo[key]) || 0
|
|
886
|
+
: 0;
|
|
887
|
+
const itemVal = parseInt(nutrition[key]) || 0;
|
|
888
|
+
nutrition = Object.assign(Object.assign({}, nutrition), { [key]: itemVal + optionVal });
|
|
889
|
+
});
|
|
890
|
+
});
|
|
891
|
+
return nutrition;
|
|
892
|
+
};
|
|
893
|
+
exports.calcNutrition = calcNutrition;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Customer, Order, Orders } from '@open-tender/types';
|
|
2
|
+
export declare const profileFields: string[];
|
|
2
3
|
export declare const makeCustomerProfile: (customer: Partial<Customer>) => Partial<Customer>;
|
|
3
4
|
export declare const getLastOrder: (orders: Orders) => Order | null;
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLastOrder = exports.makeCustomerProfile = void 0;
|
|
3
|
+
exports.getLastOrder = exports.makeCustomerProfile = exports.profileFields = void 0;
|
|
4
4
|
const date_fns_1 = require("date-fns");
|
|
5
|
-
const ts_transformer_keys_1 = require("ts-transformer-keys");
|
|
6
5
|
const helpers_1 = require("./helpers");
|
|
6
|
+
exports.profileFields = [
|
|
7
|
+
'customer_id',
|
|
8
|
+
'first_name',
|
|
9
|
+
'last_name',
|
|
10
|
+
'email',
|
|
11
|
+
'phone',
|
|
12
|
+
'company',
|
|
13
|
+
'birth_date',
|
|
14
|
+
'gender',
|
|
15
|
+
'is_verified',
|
|
16
|
+
'is_notification_set',
|
|
17
|
+
];
|
|
7
18
|
const makeCustomerProfile = (customer) => {
|
|
8
|
-
return
|
|
19
|
+
return exports.profileFields.reduce((obj, field) => (Object.assign(Object.assign({}, obj), { [field]: field === 'birth_date'
|
|
9
20
|
? (0, helpers_1.dashesToSlashes)(customer[field])
|
|
10
21
|
: customer[field] })), {});
|
|
11
22
|
};
|
package/dist/esm/utils/cart.d.ts
CHANGED
package/dist/esm/utils/cart.js
CHANGED
|
@@ -816,3 +816,33 @@ export const makeUpsellItems = (itemIds, itemLookup) => {
|
|
|
816
816
|
return (belowMin === null || belowMin === void 0 ? void 0 : belowMin.length) === 0;
|
|
817
817
|
});
|
|
818
818
|
};
|
|
819
|
+
const nutritionKeys = [
|
|
820
|
+
'calories',
|
|
821
|
+
'cholesterol',
|
|
822
|
+
'dietary_fiber',
|
|
823
|
+
'protein',
|
|
824
|
+
'saturated_fat',
|
|
825
|
+
'sodium',
|
|
826
|
+
'sugars',
|
|
827
|
+
'total_carbs',
|
|
828
|
+
'total_fat',
|
|
829
|
+
'trans_fat',
|
|
830
|
+
];
|
|
831
|
+
export const calcNutrition = (item) => {
|
|
832
|
+
const { nutritionalInfo, groups } = item;
|
|
833
|
+
let nutrition = nutritionalInfo ? Object.assign({}, nutritionalInfo) : {};
|
|
834
|
+
const options = groups.reduce((arr, g) => {
|
|
835
|
+
var _a, _b;
|
|
836
|
+
return [...arr, ...((_b = (_a = g.options) === null || _a === void 0 ? void 0 : _a.filter((o) => { var _a; return ((_a = o.quantity) !== null && _a !== void 0 ? _a : 0) > 0; })) !== null && _b !== void 0 ? _b : [])];
|
|
837
|
+
}, []);
|
|
838
|
+
options.forEach((o) => {
|
|
839
|
+
nutritionKeys === null || nutritionKeys === void 0 ? void 0 : nutritionKeys.forEach((key) => {
|
|
840
|
+
const optionVal = o.nutritionalInfo
|
|
841
|
+
? parseInt(o.nutritionalInfo[key]) || 0
|
|
842
|
+
: 0;
|
|
843
|
+
const itemVal = parseInt(nutrition[key]) || 0;
|
|
844
|
+
nutrition = Object.assign(Object.assign({}, nutrition), { [key]: itemVal + optionVal });
|
|
845
|
+
});
|
|
846
|
+
});
|
|
847
|
+
return nutrition;
|
|
848
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Customer, Order, Orders } from '@open-tender/types';
|
|
2
|
+
export declare const profileFields: string[];
|
|
2
3
|
export declare const makeCustomerProfile: (customer: Partial<Customer>) => Partial<Customer>;
|
|
3
4
|
export declare const getLastOrder: (orders: Orders) => Order | null;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { parseISO } from 'date-fns';
|
|
2
|
-
import { keys } from 'ts-transformer-keys';
|
|
3
2
|
import { dashesToSlashes } from './helpers';
|
|
3
|
+
export const profileFields = [
|
|
4
|
+
'customer_id',
|
|
5
|
+
'first_name',
|
|
6
|
+
'last_name',
|
|
7
|
+
'email',
|
|
8
|
+
'phone',
|
|
9
|
+
'company',
|
|
10
|
+
'birth_date',
|
|
11
|
+
'gender',
|
|
12
|
+
'is_verified',
|
|
13
|
+
'is_notification_set',
|
|
14
|
+
];
|
|
4
15
|
export const makeCustomerProfile = (customer) => {
|
|
5
|
-
return
|
|
16
|
+
return profileFields.reduce((obj, field) => (Object.assign(Object.assign({}, obj), { [field]: field === 'birth_date'
|
|
6
17
|
? dashesToSlashes(customer[field])
|
|
7
18
|
: customer[field] })), {});
|
|
8
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
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",
|
|
@@ -60,7 +60,6 @@
|
|
|
60
60
|
"@open-tender/types": "^0.0.79",
|
|
61
61
|
"date-fns": "^2.29.3",
|
|
62
62
|
"date-fns-tz": "^1.3.7",
|
|
63
|
-
"react-native-responsive-screen": "^1.4.2"
|
|
64
|
-
"ts-transformer-keys": "^0.4.3"
|
|
63
|
+
"react-native-responsive-screen": "^1.4.2"
|
|
65
64
|
}
|
|
66
65
|
}
|