@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,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;
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renameLocation = exports.LOCATIONS_MESSAGES = exports.makeDisplayedRevenueCenters = exports.makeDeliveryMesssaging = exports.makeWalkinMessaging = exports.makePickupMesssaging = exports.makeDeliveryRevenueCenters = exports.makeWalkinRevenueCenters = exports.makePickupRevenueCenters = exports.checkServiceType = exports.calcMinDistance = exports.sortRevenueCenters = exports.addDistance = exports.inZone = exports.getDistance = exports.makeAddress = exports.GooglePlaceBusinessStatus = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
var GooglePlaceBusinessStatus;
|
|
7
|
+
(function (GooglePlaceBusinessStatus) {
|
|
8
|
+
GooglePlaceBusinessStatus["OPERATIONAL"] = "OPERATIONAL";
|
|
9
|
+
GooglePlaceBusinessStatus["CLOSED_TEMPORARILY"] = "CLOSED_TEMPORARILY";
|
|
10
|
+
GooglePlaceBusinessStatus["CLOSED_PERMANENTLY"] = "CLOSED_PERMANENTLY";
|
|
11
|
+
})(GooglePlaceBusinessStatus = exports.GooglePlaceBusinessStatus || (exports.GooglePlaceBusinessStatus = {}));
|
|
12
|
+
// seee example Google Maps Place at bottom of file
|
|
13
|
+
const makeComponents = (components) => {
|
|
14
|
+
return components.reduce((obj, i) => {
|
|
15
|
+
return Object.assign(Object.assign({}, obj), { [i.types[0]]: { long_name: i.long_name, short_name: i.short_name } });
|
|
16
|
+
}, {});
|
|
17
|
+
};
|
|
18
|
+
const makeAddress = (place) => {
|
|
19
|
+
const { address_components, formatted_address, geometry } = place;
|
|
20
|
+
const components = makeComponents(address_components);
|
|
21
|
+
const { street_number, route, locality: city, sublocality_level_1: subcity, administrative_area_level_1: state, postal_code: postalCode } = components;
|
|
22
|
+
const streetNumber = street_number ? street_number.short_name : '';
|
|
23
|
+
const street = route ? route.long_name : '';
|
|
24
|
+
const addressCity = city || subcity;
|
|
25
|
+
return {
|
|
26
|
+
street: `${streetNumber} ${street}`.trim(),
|
|
27
|
+
city: addressCity ? addressCity.long_name : '',
|
|
28
|
+
state: state ? state.short_name : '',
|
|
29
|
+
postal_code: postalCode ? postalCode.short_name : '',
|
|
30
|
+
lat: geometry.location.lat || null,
|
|
31
|
+
lng: geometry.location.lng || null,
|
|
32
|
+
formatted_address
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.makeAddress = makeAddress;
|
|
36
|
+
const RADIUS_MILES = 3959; // radius of the earth in miles
|
|
37
|
+
const RADIUS_KM = 6371; // radius of the earth in kilometers
|
|
38
|
+
// https://stackoverflow.com/questions/18883601/function-to-calculate-distance-between-two-coordinates
|
|
39
|
+
const getDistance = (pointA, pointB, inMiles = true) => {
|
|
40
|
+
const { lat: lat1, lng: lng1 } = pointA;
|
|
41
|
+
const { lat: lat2, lng: lng2 } = pointB;
|
|
42
|
+
const R = inMiles ? RADIUS_MILES : RADIUS_KM;
|
|
43
|
+
const dLat = deg2rad(lat2 - lat1); // see deg2rad below
|
|
44
|
+
const dLng = deg2rad(lng2 - lng1);
|
|
45
|
+
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
46
|
+
Math.cos(deg2rad(lat1)) *
|
|
47
|
+
Math.cos(deg2rad(lat2)) *
|
|
48
|
+
Math.sin(dLng / 2) *
|
|
49
|
+
Math.sin(dLng / 2);
|
|
50
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
51
|
+
const d = R * c;
|
|
52
|
+
return d;
|
|
53
|
+
};
|
|
54
|
+
exports.getDistance = getDistance;
|
|
55
|
+
const deg2rad = (deg) => {
|
|
56
|
+
return deg * (Math.PI / 180);
|
|
57
|
+
};
|
|
58
|
+
// ray-casting algorithm based on
|
|
59
|
+
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
|
60
|
+
const pointInPolygon = (point, vs) => {
|
|
61
|
+
const x = point[0], y = point[1];
|
|
62
|
+
let inside = false;
|
|
63
|
+
for (let i = 0, j = vs.length - 1; i < vs.length; j = i++) {
|
|
64
|
+
const xi = vs[i][0], yi = vs[i][1];
|
|
65
|
+
const xj = vs[j][0], yj = vs[j][1];
|
|
66
|
+
const intersect = yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
|
|
67
|
+
if (intersect)
|
|
68
|
+
inside = !inside;
|
|
69
|
+
}
|
|
70
|
+
return inside;
|
|
71
|
+
};
|
|
72
|
+
const inZone = (address, polygon) => {
|
|
73
|
+
const point = [address.lat, address.lng];
|
|
74
|
+
return pointInPolygon(point, polygon);
|
|
75
|
+
};
|
|
76
|
+
exports.inZone = inZone;
|
|
77
|
+
const addDistance = (revenueCenters, address) => {
|
|
78
|
+
if (!address)
|
|
79
|
+
return revenueCenters;
|
|
80
|
+
const withDistance = revenueCenters.map(i => {
|
|
81
|
+
const latLng = i.address.lat
|
|
82
|
+
? { lat: i.address.lat, lng: i.address.lng }
|
|
83
|
+
: null;
|
|
84
|
+
i.distance = latLng ? (0, exports.getDistance)(address, latLng) : 1000;
|
|
85
|
+
const { coordinates, priority } = i.delivery_zone;
|
|
86
|
+
i.inZone = coordinates ? (0, exports.inZone)(address, coordinates) : false;
|
|
87
|
+
i.priority = priority;
|
|
88
|
+
return i;
|
|
89
|
+
});
|
|
90
|
+
return withDistance;
|
|
91
|
+
};
|
|
92
|
+
exports.addDistance = addDistance;
|
|
93
|
+
const sortRevenueCenters = (revenueCenters, isDelivery = false) => {
|
|
94
|
+
if (!isDelivery) {
|
|
95
|
+
return [...revenueCenters].sort((a, b) => { var _a, _b; return ((_a = a.distance) !== null && _a !== void 0 ? _a : 0) - ((_b = b.distance) !== null && _b !== void 0 ? _b : 0); });
|
|
96
|
+
}
|
|
97
|
+
const inZoneWithPriority = revenueCenters
|
|
98
|
+
.filter(i => i.inZone && i.priority)
|
|
99
|
+
.sort((a, b) => { var _a, _b; return ((_a = a.priority) !== null && _a !== void 0 ? _a : 0) - ((_b = b.priority) !== null && _b !== void 0 ? _b : 0); });
|
|
100
|
+
const inZoneWithoutPriority = revenueCenters
|
|
101
|
+
.filter(i => i.inZone && !i.priority)
|
|
102
|
+
.sort((a, b) => { var _a, _b; return ((_a = a.distance) !== null && _a !== void 0 ? _a : 0) - ((_b = b.distance) !== null && _b !== void 0 ? _b : 0); });
|
|
103
|
+
const outOfZone = revenueCenters
|
|
104
|
+
.filter(i => !i.inZone)
|
|
105
|
+
.sort((a, b) => { var _a, _b; return ((_a = a.distance) !== null && _a !== void 0 ? _a : 0) - ((_b = b.distance) !== null && _b !== void 0 ? _b : 0); });
|
|
106
|
+
return [...inZoneWithPriority, ...inZoneWithoutPriority, ...outOfZone];
|
|
107
|
+
};
|
|
108
|
+
exports.sortRevenueCenters = sortRevenueCenters;
|
|
109
|
+
const calcMinDistance = (revenueCenters, maxDistance = constants_1.MAX_DISTANCE) => {
|
|
110
|
+
const withDistance = revenueCenters
|
|
111
|
+
.filter(i => i.distance !== null && i.distance !== undefined)
|
|
112
|
+
.map(i => { var _a; return (_a = i.distance) !== null && _a !== void 0 ? _a : 0; });
|
|
113
|
+
return withDistance ? Math.min(...withDistance) : maxDistance;
|
|
114
|
+
};
|
|
115
|
+
exports.calcMinDistance = calcMinDistance;
|
|
116
|
+
const checkServiceType = (revenueCenter, serviceType) => {
|
|
117
|
+
const { settings, service_types } = revenueCenter;
|
|
118
|
+
const serviceTypes = settings ? settings.service_types : service_types;
|
|
119
|
+
if (!serviceTypes)
|
|
120
|
+
return false;
|
|
121
|
+
return serviceTypes.includes(serviceType);
|
|
122
|
+
};
|
|
123
|
+
exports.checkServiceType = checkServiceType;
|
|
124
|
+
const makePickupRevenueCenters = (revenueCenters, maxDistance = constants_1.MAX_DISTANCE) => {
|
|
125
|
+
const hasPickup = revenueCenters
|
|
126
|
+
.filter(i => (0, exports.checkServiceType)(i, 'PICKUP'))
|
|
127
|
+
.filter(i => !i.distance || i.distance < maxDistance);
|
|
128
|
+
return (0, exports.sortRevenueCenters)(hasPickup);
|
|
129
|
+
};
|
|
130
|
+
exports.makePickupRevenueCenters = makePickupRevenueCenters;
|
|
131
|
+
const makeWalkinRevenueCenters = (revenueCenters, maxDistance = constants_1.MAX_DISTANCE) => {
|
|
132
|
+
const hasWalkin = revenueCenters
|
|
133
|
+
.filter(i => (0, exports.checkServiceType)(i, 'WALKIN'))
|
|
134
|
+
.filter(i => !i.distance || i.distance < maxDistance);
|
|
135
|
+
return (0, exports.sortRevenueCenters)(hasWalkin);
|
|
136
|
+
};
|
|
137
|
+
exports.makeWalkinRevenueCenters = makeWalkinRevenueCenters;
|
|
138
|
+
const makeDeliveryRevenueCenters = (revenueCenters) => {
|
|
139
|
+
const hasDelivery = revenueCenters.filter(i => (0, exports.checkServiceType)(i, 'DELIVERY'));
|
|
140
|
+
const sorted = (0, exports.sortRevenueCenters)(hasDelivery, true);
|
|
141
|
+
return sorted.filter(i => i.inZone);
|
|
142
|
+
};
|
|
143
|
+
exports.makeDeliveryRevenueCenters = makeDeliveryRevenueCenters;
|
|
144
|
+
const makePickupMesssaging = (address, geoLatLng, count, minDistance, maxDistance = constants_1.MAX_DISTANCE, messages = exports.LOCATIONS_MESSAGES) => {
|
|
145
|
+
if (address) {
|
|
146
|
+
if (minDistance >= maxDistance) {
|
|
147
|
+
return messages.PICKUP.addressFar;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
return {
|
|
151
|
+
title: `${count} ${messages.PICKUP.address.title}`,
|
|
152
|
+
msg: messages.PICKUP.address.msg
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (geoLatLng) {
|
|
157
|
+
if (minDistance >= maxDistance) {
|
|
158
|
+
return messages.PICKUP.geoFar;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
return {
|
|
162
|
+
title: `${count} ${messages.PICKUP.geo.title}`,
|
|
163
|
+
msg: messages.PICKUP.geo.msg
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return messages.PICKUP.default;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
exports.makePickupMesssaging = makePickupMesssaging;
|
|
172
|
+
const makeWalkinMessaging = (address, geoLatLng, count, minDistance, maxDistance = constants_1.MAX_DISTANCE, messages = exports.LOCATIONS_MESSAGES) => {
|
|
173
|
+
const { title, msg } = (0, exports.makePickupMesssaging)(address, geoLatLng, count, minDistance, maxDistance, messages);
|
|
174
|
+
return {
|
|
175
|
+
title: title.replace('pickup', 'dine-in'),
|
|
176
|
+
msg: msg.replace('pickup', 'dine-in')
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
exports.makeWalkinMessaging = makeWalkinMessaging;
|
|
180
|
+
const makeDeliveryMesssaging = (address, count, messages = exports.LOCATIONS_MESSAGES) => {
|
|
181
|
+
if (!address) {
|
|
182
|
+
return messages.DELIVERY.default;
|
|
183
|
+
}
|
|
184
|
+
else if (!address.street) {
|
|
185
|
+
return messages.DELIVERY.noStreet;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
if (count) {
|
|
189
|
+
const locationMsg = count > 1 ? 'locations deliver' : 'location delivers';
|
|
190
|
+
return {
|
|
191
|
+
title: messages.DELIVERY.hasDelivery.title,
|
|
192
|
+
msg: `${count} ${locationMsg} to your address.`,
|
|
193
|
+
error: null
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
return messages.DELIVERY.noDelivery;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
exports.makeDeliveryMesssaging = makeDeliveryMesssaging;
|
|
202
|
+
const makeDisplayedRevenueCenters = (revenueCenters, serviceType, address, geoLatLng, maxDistance) => {
|
|
203
|
+
if (serviceType === 'WALKIN') {
|
|
204
|
+
const displayed = (0, exports.makeWalkinRevenueCenters)(revenueCenters, maxDistance);
|
|
205
|
+
const minDistance = (0, exports.calcMinDistance)(displayed);
|
|
206
|
+
const count = displayed.length;
|
|
207
|
+
const { title, msg } = (0, exports.makeWalkinMessaging)(address, geoLatLng, count, minDistance, maxDistance);
|
|
208
|
+
const error = null;
|
|
209
|
+
return { title, msg, error, displayed };
|
|
210
|
+
}
|
|
211
|
+
else if (serviceType === 'PICKUP') {
|
|
212
|
+
const displayed = (0, exports.makePickupRevenueCenters)(revenueCenters, maxDistance);
|
|
213
|
+
const minDistance = (0, exports.calcMinDistance)(displayed);
|
|
214
|
+
const count = displayed.length;
|
|
215
|
+
const { title, msg } = (0, exports.makePickupMesssaging)(address, geoLatLng, count, minDistance, maxDistance);
|
|
216
|
+
const error = null;
|
|
217
|
+
return { title, msg, error, displayed };
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
const displayed = (0, exports.makeDeliveryRevenueCenters)(revenueCenters);
|
|
221
|
+
const count = displayed.length;
|
|
222
|
+
const { title, msg, error } = (0, exports.makeDeliveryMesssaging)(address, count);
|
|
223
|
+
return { title, msg, error, displayed };
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
exports.makeDisplayedRevenueCenters = makeDisplayedRevenueCenters;
|
|
227
|
+
exports.LOCATIONS_MESSAGES = {
|
|
228
|
+
PICKUP: {
|
|
229
|
+
default: {
|
|
230
|
+
title: 'Please choose a location',
|
|
231
|
+
msg: 'Or enter a zip code to find the location nearest you.'
|
|
232
|
+
},
|
|
233
|
+
address: {
|
|
234
|
+
title: 'locations near you',
|
|
235
|
+
msg: 'Please choose a location below.'
|
|
236
|
+
},
|
|
237
|
+
addressFar: {
|
|
238
|
+
title: "Looks like we don't have any locations that offer pickup in your area",
|
|
239
|
+
msg: 'Sorry about that. Please enter a different address or head back and choose a different order type.'
|
|
240
|
+
},
|
|
241
|
+
geo: {
|
|
242
|
+
title: 'locations in your area',
|
|
243
|
+
msg: 'Please enter an address or zip code for a more accurate result.'
|
|
244
|
+
},
|
|
245
|
+
geoFar: {
|
|
246
|
+
title: "Looks like we don't have any locations that offer pickup in your area",
|
|
247
|
+
msg: 'Please enter an address or zip code if you live in a different area.'
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
DELIVERY: {
|
|
251
|
+
default: {
|
|
252
|
+
title: "Let's find the nearest location",
|
|
253
|
+
msg: 'Please enter your address.',
|
|
254
|
+
error: null
|
|
255
|
+
},
|
|
256
|
+
noStreet: {
|
|
257
|
+
title: 'Please enter a street address',
|
|
258
|
+
msg: '',
|
|
259
|
+
error: 'A full address with street number is required for delivery orders.'
|
|
260
|
+
},
|
|
261
|
+
hasDelivery: {
|
|
262
|
+
title: 'Delivery is available!',
|
|
263
|
+
msg: 'Please choose a location below.',
|
|
264
|
+
error: null
|
|
265
|
+
},
|
|
266
|
+
noDelivery: {
|
|
267
|
+
title: "Delivery isn't available in your area at this time",
|
|
268
|
+
msg: "We're really sorry about that. Please enter a different address or head back and start a pickup order.",
|
|
269
|
+
error: null
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
const renameLocation = (str, names) => {
|
|
274
|
+
if (!(0, helpers_1.isString)(str))
|
|
275
|
+
return str;
|
|
276
|
+
const [singular, plural] = names;
|
|
277
|
+
return str
|
|
278
|
+
.replace('1 locations', '1 location')
|
|
279
|
+
.replace('locations', plural)
|
|
280
|
+
.replace('location', singular)
|
|
281
|
+
.replace(' a a', ' an a')
|
|
282
|
+
.replace(' a e', ' an e')
|
|
283
|
+
.replace(' a i', ' an i')
|
|
284
|
+
.replace(' a o', ' an o')
|
|
285
|
+
.replace(' a u', ' an u');
|
|
286
|
+
};
|
|
287
|
+
exports.renameLocation = renameLocation;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Cart, ItemTypes, OrderChannel, OrderCounts, Orders, PrepStatus, Store, TenderType, Ticket, TimezonePython, Timezone } from '@open-tender/types';
|
|
2
|
+
export declare const makeChannelName: (channel: OrderChannel) => string | null | undefined;
|
|
3
|
+
export declare const makeTenderTypeName: (tenderType: TenderType) => string;
|
|
4
|
+
export declare const notDone: (prep_status: PrepStatus) => boolean;
|
|
5
|
+
export declare const isDone: (prep_status: PrepStatus) => boolean;
|
|
6
|
+
export declare const notCompleted: (prep_status: PrepStatus) => boolean;
|
|
7
|
+
export declare const isCompleted: (prep_status: PrepStatus) => boolean;
|
|
8
|
+
export declare const makeOrdersCounts: (itemTypes?: ItemTypes, orders?: Orders) => {
|
|
9
|
+
current: {
|
|
10
|
+
Orders: number;
|
|
11
|
+
};
|
|
12
|
+
future: {
|
|
13
|
+
Orders: number;
|
|
14
|
+
};
|
|
15
|
+
qa: {
|
|
16
|
+
Orders: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare const makeOrderBuckets: (orders: Orders, tz: TimezonePython | Timezone, prepStates?: Array<PrepStatus>) => {
|
|
20
|
+
orders: import("@open-tender/types").Order[];
|
|
21
|
+
start: number | Date;
|
|
22
|
+
end: number | Date;
|
|
23
|
+
}[];
|
|
24
|
+
export declare const makeOrderBucketsCounts: (itemTypes?: ItemTypes, orders?: Orders) => {
|
|
25
|
+
Orders: number;
|
|
26
|
+
};
|
|
27
|
+
export declare const makeTicketCounts: (tickets: Array<Ticket>) => any;
|
|
28
|
+
export declare const makeCartLookup: (cart: Cart) => {};
|
|
29
|
+
export declare const makeItemTypeSettings: (itemType: Ticket) => {
|
|
30
|
+
is_default: boolean;
|
|
31
|
+
is_grouped: boolean;
|
|
32
|
+
is_hidden_assembly: boolean;
|
|
33
|
+
is_hidden_qa: boolean;
|
|
34
|
+
print_on_completed: boolean;
|
|
35
|
+
};
|
|
36
|
+
export declare const makeItemTypesMap: (itemTypes: Array<Ticket>) => {};
|
|
37
|
+
export declare const makeTicketGroups: (tickets: Array<Ticket>, cart: Cart, itemTypes: Array<Ticket>, isAssembly: boolean) => unknown[];
|
|
38
|
+
export declare const makeDisplayCounts: (counts: OrderCounts) => any[] | "";
|
|
39
|
+
export declare const displayCounts: (counts: OrderCounts) => string;
|
|
40
|
+
export declare const makeColor: (settings: Store, minutes: number) => string;
|