@open-tender/utils 0.4.31 → 0.4.32

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.
Files changed (245) hide show
  1. package/LICENSE.md +21 -21
  2. package/README.md +2 -2
  3. package/dist/cjs/__tests__/utils/helpers.test.d.ts +1 -1
  4. package/dist/cjs/__tests__/utils/helpers.test.js +96 -96
  5. package/dist/cjs/__tests__/utils/theme.test.d.ts +1 -1
  6. package/dist/cjs/__tests__/utils/theme.test.js +37 -37
  7. package/dist/cjs/hooks/index.d.ts +35 -35
  8. package/dist/cjs/hooks/index.js +38 -38
  9. package/dist/cjs/hooks/types.d.ts +4 -4
  10. package/dist/cjs/hooks/types.js +2 -2
  11. package/dist/cjs/hooks/useAccordion.d.ts +22 -22
  12. package/dist/cjs/hooks/useAccordion.js +56 -56
  13. package/dist/cjs/hooks/useAddressForm.d.ts +12 -12
  14. package/dist/cjs/hooks/useAddressForm.js +83 -83
  15. package/dist/cjs/hooks/useAllergenForm.d.ts +10 -10
  16. package/dist/cjs/hooks/useAllergenForm.js +58 -58
  17. package/dist/cjs/hooks/useBuilder.d.ts +14 -14
  18. package/dist/cjs/hooks/useBuilder.js +144 -144
  19. package/dist/cjs/hooks/useCartGuestForm.d.ts +12 -12
  20. package/dist/cjs/hooks/useCartGuestForm.js +58 -58
  21. package/dist/cjs/hooks/useCartPoints.d.ts +13 -13
  22. package/dist/cjs/hooks/useCartPoints.js +74 -74
  23. package/dist/cjs/hooks/useCommunicationPreferences.js +1 -1
  24. package/dist/cjs/hooks/useCreditCard.d.ts +13 -13
  25. package/dist/cjs/hooks/useCreditCard.js +63 -63
  26. package/dist/cjs/hooks/useCreditCardForm.d.ts +10 -10
  27. package/dist/cjs/hooks/useCreditCardForm.js +71 -71
  28. package/dist/cjs/hooks/useCurbside.d.ts +9 -9
  29. package/dist/cjs/hooks/useCurbside.js +39 -39
  30. package/dist/cjs/hooks/useDineInForm.d.ts +11 -11
  31. package/dist/cjs/hooks/useDineInForm.js +56 -56
  32. package/dist/cjs/hooks/useDonationForm.d.ts +28 -28
  33. package/dist/cjs/hooks/useDonationForm.js +172 -172
  34. package/dist/cjs/hooks/useFirstTimes.d.ts +18 -18
  35. package/dist/cjs/hooks/useFirstTimes.js +81 -81
  36. package/dist/cjs/hooks/useGiftCardAssignForm.d.ts +14 -14
  37. package/dist/cjs/hooks/useGiftCardAssignForm.js +57 -57
  38. package/dist/cjs/hooks/useGiftCardAssignOtherForm.d.ts +14 -14
  39. package/dist/cjs/hooks/useGiftCardAssignOtherForm.js +50 -50
  40. package/dist/cjs/hooks/useGiftCardForm.d.ts +12 -12
  41. package/dist/cjs/hooks/useGiftCardForm.js +74 -74
  42. package/dist/cjs/hooks/useGiftCardsForm.d.ts +31 -31
  43. package/dist/cjs/hooks/useGiftCardsForm.js +195 -195
  44. package/dist/cjs/hooks/useGuestCheckoutForm.d.ts +21 -21
  45. package/dist/cjs/hooks/useGuestCheckoutForm.js +89 -89
  46. package/dist/cjs/hooks/useGuestForm.d.ts +12 -12
  47. package/dist/cjs/hooks/useGuestForm.js +60 -60
  48. package/dist/cjs/hooks/useImage.d.ts +5 -5
  49. package/dist/cjs/hooks/useImage.js +33 -33
  50. package/dist/cjs/hooks/useLoginForm.d.ts +12 -12
  51. package/dist/cjs/hooks/useLoginForm.js +67 -67
  52. package/dist/cjs/hooks/useMenuItem.d.ts +57 -57
  53. package/dist/cjs/hooks/useMenuItem.js +67 -67
  54. package/dist/cjs/hooks/useModifier.d.ts +53 -53
  55. package/dist/cjs/hooks/useModifier.js +72 -72
  56. package/dist/cjs/hooks/useModifierGroup.d.ts +15 -15
  57. package/dist/cjs/hooks/useModifierGroup.js +17 -17
  58. package/dist/cjs/hooks/useOneTimePasscodeForm.d.ts +16 -16
  59. package/dist/cjs/hooks/useOneTimePasscodeForm.js +87 -87
  60. package/dist/cjs/hooks/useOrderFulfillmentForm.d.ts +11 -11
  61. package/dist/cjs/hooks/useOrderFulfillmentForm.js +65 -65
  62. package/dist/cjs/hooks/useOrderItem.d.ts +48 -48
  63. package/dist/cjs/hooks/useOrderItem.js +54 -54
  64. package/dist/cjs/hooks/useOrderRating.d.ts +10 -10
  65. package/dist/cjs/hooks/useOrderRating.js +34 -34
  66. package/dist/cjs/hooks/useOrderRatingForm.d.ts +11 -11
  67. package/dist/cjs/hooks/useOrderRatingForm.js +35 -35
  68. package/dist/cjs/hooks/useProfileForm.d.ts +15 -15
  69. package/dist/cjs/hooks/useProfileForm.js +116 -116
  70. package/dist/cjs/hooks/useResetPasswordForm.d.ts +12 -12
  71. package/dist/cjs/hooks/useResetPasswordForm.js +77 -77
  72. package/dist/cjs/hooks/useSendResetForm.d.ts +14 -14
  73. package/dist/cjs/hooks/useSendResetForm.js +57 -57
  74. package/dist/cjs/hooks/useSignUpForm.d.ts +20 -20
  75. package/dist/cjs/hooks/useSignUpForm.js +151 -151
  76. package/dist/cjs/hooks/useSignUpGuestForm.d.ts +23 -23
  77. package/dist/cjs/hooks/useSignUpGuestForm.js +122 -113
  78. package/dist/cjs/hooks/useSigninForm.d.ts +12 -12
  79. package/dist/cjs/hooks/useSigninForm.js +66 -66
  80. package/dist/cjs/index.d.ts +2 -2
  81. package/dist/cjs/index.js +5 -5
  82. package/dist/cjs/utils/cards.d.ts +20 -20
  83. package/dist/cjs/utils/cards.js +155 -155
  84. package/dist/cjs/utils/cart.d.ts +202 -202
  85. package/dist/cjs/utils/cart.js +909 -909
  86. package/dist/cjs/utils/checkout.d.ts +55 -55
  87. package/dist/cjs/utils/checkout.js +125 -125
  88. package/dist/cjs/utils/constants.d.ts +43 -43
  89. package/dist/cjs/utils/constants.js +58 -58
  90. package/dist/cjs/utils/customer.d.ts +4 -4
  91. package/dist/cjs/utils/customer.js +34 -34
  92. package/dist/cjs/utils/datetimes.d.ts +99 -99
  93. package/dist/cjs/utils/datetimes.js +601 -601
  94. package/dist/cjs/utils/errors.d.ts +51 -51
  95. package/dist/cjs/utils/errors.js +191 -191
  96. package/dist/cjs/utils/favorites.d.ts +10 -10
  97. package/dist/cjs/utils/favorites.js +119 -119
  98. package/dist/cjs/utils/googleMaps.d.ts +14 -14
  99. package/dist/cjs/utils/googleMaps.js +30 -30
  100. package/dist/cjs/utils/helpers.d.ts +63 -63
  101. package/dist/cjs/utils/helpers.js +244 -244
  102. package/dist/cjs/utils/index.d.ts +19 -19
  103. package/dist/cjs/utils/index.js +23 -23
  104. package/dist/cjs/utils/keypad.d.ts +9 -9
  105. package/dist/cjs/utils/keypad.js +105 -105
  106. package/dist/cjs/utils/maps.d.ts +226 -226
  107. package/dist/cjs/utils/maps.js +334 -334
  108. package/dist/cjs/utils/menu.d.ts +117 -117
  109. package/dist/cjs/utils/menu.js +82 -82
  110. package/dist/cjs/utils/orders.d.ts +21 -21
  111. package/dist/cjs/utils/orders.js +202 -202
  112. package/dist/cjs/utils/pizzaBuilder.d.ts +10 -10
  113. package/dist/cjs/utils/pizzaBuilder.js +43 -43
  114. package/dist/cjs/utils/refunds.d.ts +35 -35
  115. package/dist/cjs/utils/refunds.js +98 -98
  116. package/dist/cjs/utils/revenueCenters.d.ts +11 -11
  117. package/dist/cjs/utils/revenueCenters.js +125 -125
  118. package/dist/cjs/utils/rewards.d.ts +4 -4
  119. package/dist/cjs/utils/rewards.js +106 -106
  120. package/dist/cjs/utils/theme.d.ts +27 -27
  121. package/dist/cjs/utils/theme.js +266 -266
  122. package/dist/cjs/utils/version.d.ts +4 -4
  123. package/dist/cjs/utils/version.js +38 -38
  124. package/dist/esm/__tests__/utils/helpers.test.d.ts +1 -1
  125. package/dist/esm/__tests__/utils/helpers.test.js +94 -94
  126. package/dist/esm/__tests__/utils/theme.test.d.ts +1 -1
  127. package/dist/esm/__tests__/utils/theme.test.js +35 -35
  128. package/dist/esm/hooks/index.d.ts +35 -35
  129. package/dist/esm/hooks/index.js +35 -35
  130. package/dist/esm/hooks/types.d.ts +4 -4
  131. package/dist/esm/hooks/types.js +1 -1
  132. package/dist/esm/hooks/useAccordion.d.ts +22 -22
  133. package/dist/esm/hooks/useAccordion.js +52 -52
  134. package/dist/esm/hooks/useAddressForm.d.ts +12 -12
  135. package/dist/esm/hooks/useAddressForm.js +79 -79
  136. package/dist/esm/hooks/useAllergenForm.d.ts +10 -10
  137. package/dist/esm/hooks/useAllergenForm.js +54 -54
  138. package/dist/esm/hooks/useBuilder.d.ts +14 -14
  139. package/dist/esm/hooks/useBuilder.js +140 -140
  140. package/dist/esm/hooks/useCartGuestForm.d.ts +12 -12
  141. package/dist/esm/hooks/useCartGuestForm.js +54 -54
  142. package/dist/esm/hooks/useCartPoints.d.ts +13 -13
  143. package/dist/esm/hooks/useCartPoints.js +70 -70
  144. package/dist/esm/hooks/useCommunicationPreferences.js +1 -1
  145. package/dist/esm/hooks/useCreditCard.d.ts +13 -13
  146. package/dist/esm/hooks/useCreditCard.js +59 -59
  147. package/dist/esm/hooks/useCreditCardForm.d.ts +10 -10
  148. package/dist/esm/hooks/useCreditCardForm.js +67 -67
  149. package/dist/esm/hooks/useCurbside.d.ts +9 -9
  150. package/dist/esm/hooks/useCurbside.js +35 -35
  151. package/dist/esm/hooks/useDineInForm.d.ts +11 -11
  152. package/dist/esm/hooks/useDineInForm.js +52 -52
  153. package/dist/esm/hooks/useDonationForm.d.ts +28 -28
  154. package/dist/esm/hooks/useDonationForm.js +168 -168
  155. package/dist/esm/hooks/useFirstTimes.d.ts +18 -18
  156. package/dist/esm/hooks/useFirstTimes.js +77 -77
  157. package/dist/esm/hooks/useGiftCardAssignForm.d.ts +14 -14
  158. package/dist/esm/hooks/useGiftCardAssignForm.js +53 -53
  159. package/dist/esm/hooks/useGiftCardAssignOtherForm.d.ts +14 -14
  160. package/dist/esm/hooks/useGiftCardAssignOtherForm.js +46 -46
  161. package/dist/esm/hooks/useGiftCardForm.d.ts +12 -12
  162. package/dist/esm/hooks/useGiftCardForm.js +70 -70
  163. package/dist/esm/hooks/useGiftCardsForm.d.ts +31 -31
  164. package/dist/esm/hooks/useGiftCardsForm.js +191 -191
  165. package/dist/esm/hooks/useGuestCheckoutForm.d.ts +21 -21
  166. package/dist/esm/hooks/useGuestCheckoutForm.js +85 -85
  167. package/dist/esm/hooks/useGuestForm.d.ts +12 -12
  168. package/dist/esm/hooks/useGuestForm.js +56 -56
  169. package/dist/esm/hooks/useImage.d.ts +5 -5
  170. package/dist/esm/hooks/useImage.js +29 -29
  171. package/dist/esm/hooks/useLoginForm.d.ts +12 -12
  172. package/dist/esm/hooks/useLoginForm.js +63 -63
  173. package/dist/esm/hooks/useMenuItem.d.ts +57 -57
  174. package/dist/esm/hooks/useMenuItem.js +63 -63
  175. package/dist/esm/hooks/useModifier.d.ts +53 -53
  176. package/dist/esm/hooks/useModifier.js +68 -68
  177. package/dist/esm/hooks/useModifierGroup.d.ts +15 -15
  178. package/dist/esm/hooks/useModifierGroup.js +13 -13
  179. package/dist/esm/hooks/useOneTimePasscodeForm.d.ts +16 -16
  180. package/dist/esm/hooks/useOneTimePasscodeForm.js +83 -83
  181. package/dist/esm/hooks/useOrderFulfillmentForm.d.ts +11 -11
  182. package/dist/esm/hooks/useOrderFulfillmentForm.js +61 -61
  183. package/dist/esm/hooks/useOrderItem.d.ts +48 -48
  184. package/dist/esm/hooks/useOrderItem.js +50 -50
  185. package/dist/esm/hooks/useOrderRating.d.ts +10 -10
  186. package/dist/esm/hooks/useOrderRating.js +30 -30
  187. package/dist/esm/hooks/useOrderRatingForm.d.ts +11 -11
  188. package/dist/esm/hooks/useOrderRatingForm.js +31 -31
  189. package/dist/esm/hooks/useProfileForm.d.ts +15 -15
  190. package/dist/esm/hooks/useProfileForm.js +112 -112
  191. package/dist/esm/hooks/useResetPasswordForm.d.ts +12 -12
  192. package/dist/esm/hooks/useResetPasswordForm.js +73 -73
  193. package/dist/esm/hooks/useSendResetForm.d.ts +14 -14
  194. package/dist/esm/hooks/useSendResetForm.js +53 -53
  195. package/dist/esm/hooks/useSignUpForm.d.ts +20 -20
  196. package/dist/esm/hooks/useSignUpForm.js +147 -147
  197. package/dist/esm/hooks/useSignUpGuestForm.d.ts +23 -23
  198. package/dist/esm/hooks/useSignUpGuestForm.js +118 -109
  199. package/dist/esm/hooks/useSigninForm.d.ts +12 -12
  200. package/dist/esm/hooks/useSigninForm.js +62 -62
  201. package/dist/esm/index.d.ts +2 -2
  202. package/dist/esm/index.js +2 -2
  203. package/dist/esm/utils/cards.d.ts +20 -20
  204. package/dist/esm/utils/cards.js +146 -146
  205. package/dist/esm/utils/cart.d.ts +202 -202
  206. package/dist/esm/utils/cart.js +868 -868
  207. package/dist/esm/utils/checkout.d.ts +55 -55
  208. package/dist/esm/utils/checkout.js +117 -117
  209. package/dist/esm/utils/constants.d.ts +43 -43
  210. package/dist/esm/utils/constants.js +55 -55
  211. package/dist/esm/utils/customer.d.ts +4 -4
  212. package/dist/esm/utils/customer.js +29 -29
  213. package/dist/esm/utils/datetimes.d.ts +99 -99
  214. package/dist/esm/utils/datetimes.js +531 -531
  215. package/dist/esm/utils/errors.d.ts +51 -51
  216. package/dist/esm/utils/errors.js +180 -180
  217. package/dist/esm/utils/favorites.d.ts +10 -10
  218. package/dist/esm/utils/favorites.js +109 -109
  219. package/dist/esm/utils/googleMaps.d.ts +14 -14
  220. package/dist/esm/utils/googleMaps.js +26 -26
  221. package/dist/esm/utils/helpers.d.ts +63 -63
  222. package/dist/esm/utils/helpers.js +205 -205
  223. package/dist/esm/utils/index.d.ts +19 -19
  224. package/dist/esm/utils/index.js +20 -20
  225. package/dist/esm/utils/keypad.d.ts +9 -9
  226. package/dist/esm/utils/keypad.js +97 -97
  227. package/dist/esm/utils/maps.d.ts +226 -226
  228. package/dist/esm/utils/maps.js +316 -316
  229. package/dist/esm/utils/menu.d.ts +117 -117
  230. package/dist/esm/utils/menu.js +74 -74
  231. package/dist/esm/utils/orders.d.ts +21 -21
  232. package/dist/esm/utils/orders.js +185 -185
  233. package/dist/esm/utils/pizzaBuilder.d.ts +10 -10
  234. package/dist/esm/utils/pizzaBuilder.js +38 -38
  235. package/dist/esm/utils/refunds.d.ts +35 -35
  236. package/dist/esm/utils/refunds.js +90 -90
  237. package/dist/esm/utils/revenueCenters.d.ts +11 -11
  238. package/dist/esm/utils/revenueCenters.js +115 -115
  239. package/dist/esm/utils/rewards.d.ts +4 -4
  240. package/dist/esm/utils/rewards.js +100 -100
  241. package/dist/esm/utils/theme.d.ts +27 -27
  242. package/dist/esm/utils/theme.js +254 -254
  243. package/dist/esm/utils/version.d.ts +4 -4
  244. package/dist/esm/utils/version.js +34 -34
  245. package/package.json +69 -68
@@ -1,334 +1,334 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeMapStyles = 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 = void 0;
4
- const constants_1 = require("./constants");
5
- const RADIUS_MILES = 3959; // radius of the earth in miles
6
- const RADIUS_KM = 6371; // radius of the earth in kilometers
7
- // https://stackoverflow.com/questions/18883601/function-to-calculate-distance-between-two-coordinates
8
- const getDistance = (pointA, pointB, inMiles = true) => {
9
- const { lat: lat1, lng: lng1 } = pointA;
10
- const { lat: lat2, lng: lng2 } = pointB;
11
- const R = inMiles ? RADIUS_MILES : RADIUS_KM;
12
- const dLat = deg2rad(lat2 - lat1); // see deg2rad below
13
- const dLng = deg2rad(lng2 - lng1);
14
- const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
15
- Math.cos(deg2rad(lat1)) *
16
- Math.cos(deg2rad(lat2)) *
17
- Math.sin(dLng / 2) *
18
- Math.sin(dLng / 2);
19
- const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
20
- const d = R * c;
21
- return d;
22
- };
23
- exports.getDistance = getDistance;
24
- const deg2rad = (deg) => {
25
- return deg * (Math.PI / 180);
26
- };
27
- // ray-casting algorithm based on
28
- // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
29
- const pointInPolygon = (point, vs) => {
30
- const x = point[0], y = point[1];
31
- let inside = false;
32
- for (let i = 0, j = vs.length - 1; i < vs.length; j = i++) {
33
- const xi = vs[i][0], yi = vs[i][1];
34
- const xj = vs[j][0], yj = vs[j][1];
35
- const intersect = yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
36
- if (intersect)
37
- inside = !inside;
38
- }
39
- return inside;
40
- };
41
- const inZone = (latLng, polygon) => {
42
- const point = [latLng.lat, latLng.lng];
43
- return pointInPolygon(point, polygon);
44
- };
45
- exports.inZone = inZone;
46
- const addDistance = (revenueCenters, latLng) => {
47
- if (!latLng)
48
- return revenueCenters;
49
- const withDistance = revenueCenters.map(i => {
50
- const iLatLng = i.address.lat
51
- ? { lat: i.address.lat, lng: i.address.lng }
52
- : null;
53
- i.distance = iLatLng ? (0, exports.getDistance)(latLng, iLatLng) : 1000;
54
- const { coordinates, priority } = i.delivery_zone;
55
- i.inZone = coordinates ? (0, exports.inZone)(latLng, coordinates) : false;
56
- i.priority = priority !== null && priority !== void 0 ? priority : 0;
57
- return i;
58
- });
59
- return withDistance;
60
- };
61
- exports.addDistance = addDistance;
62
- const sortRevenueCenters = (revenueCenters, isDelivery = false) => {
63
- if (!isDelivery) {
64
- 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); });
65
- }
66
- const inZoneWithPriority = revenueCenters
67
- .filter(i => i.inZone && i.priority)
68
- .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); });
69
- const inZoneWithoutPriority = revenueCenters
70
- .filter(i => i.inZone && !i.priority)
71
- .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); });
72
- const outOfZone = revenueCenters
73
- .filter(i => !i.inZone)
74
- .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); });
75
- return [...inZoneWithPriority, ...inZoneWithoutPriority, ...outOfZone];
76
- };
77
- exports.sortRevenueCenters = sortRevenueCenters;
78
- const calcMinDistance = (revenueCenters, maxDistance = constants_1.MAX_DISTANCE) => {
79
- const withDistance = revenueCenters
80
- .filter(i => i.distance !== null && i.distance !== undefined)
81
- .map(i => { var _a; return (_a = i.distance) !== null && _a !== void 0 ? _a : 0; });
82
- return withDistance ? Math.min(...withDistance) : maxDistance;
83
- };
84
- exports.calcMinDistance = calcMinDistance;
85
- const checkServiceType = (revenueCenter, serviceType) => {
86
- const { service_types } = revenueCenter;
87
- if (!service_types)
88
- return false;
89
- return service_types.includes(serviceType);
90
- };
91
- exports.checkServiceType = checkServiceType;
92
- const makePickupRevenueCenters = (revenueCenters, maxDistance = constants_1.MAX_DISTANCE) => {
93
- const hasPickup = revenueCenters
94
- .filter(i => (0, exports.checkServiceType)(i, 'PICKUP'))
95
- .filter(i => !i.distance || i.distance < maxDistance);
96
- return (0, exports.sortRevenueCenters)(hasPickup);
97
- };
98
- exports.makePickupRevenueCenters = makePickupRevenueCenters;
99
- const makeWalkinRevenueCenters = (revenueCenters, maxDistance = constants_1.MAX_DISTANCE) => {
100
- const hasWalkin = revenueCenters
101
- .filter(i => (0, exports.checkServiceType)(i, 'WALKIN'))
102
- .filter(i => !i.distance || i.distance < maxDistance);
103
- return (0, exports.sortRevenueCenters)(hasWalkin);
104
- };
105
- exports.makeWalkinRevenueCenters = makeWalkinRevenueCenters;
106
- const makeDeliveryRevenueCenters = (revenueCenters) => {
107
- const hasDelivery = revenueCenters.filter(i => (0, exports.checkServiceType)(i, 'DELIVERY'));
108
- const sorted = (0, exports.sortRevenueCenters)(hasDelivery, true);
109
- return sorted.filter(i => i.inZone);
110
- };
111
- exports.makeDeliveryRevenueCenters = makeDeliveryRevenueCenters;
112
- const makePickupMesssaging = (address, latLng, count, minDistance, maxDistance = constants_1.MAX_DISTANCE, messages = exports.LOCATIONS_MESSAGES) => {
113
- if (address) {
114
- if (minDistance >= maxDistance) {
115
- return messages.PICKUP.addressFar;
116
- }
117
- else {
118
- return {
119
- title: `${count} ${messages.PICKUP.address.title}`,
120
- msg: messages.PICKUP.address.msg
121
- };
122
- }
123
- }
124
- else if (latLng) {
125
- if (minDistance >= maxDistance) {
126
- return messages.PICKUP.geoFar;
127
- }
128
- else {
129
- return {
130
- title: `${count} ${messages.PICKUP.geo.title}`,
131
- msg: messages.PICKUP.geo.msg
132
- };
133
- }
134
- }
135
- else {
136
- return messages.PICKUP.default;
137
- }
138
- };
139
- exports.makePickupMesssaging = makePickupMesssaging;
140
- const makeWalkinMessaging = (address, latLng, count, minDistance, maxDistance = constants_1.MAX_DISTANCE, messages = exports.LOCATIONS_MESSAGES) => {
141
- const { title, msg } = (0, exports.makePickupMesssaging)(address, latLng, count, minDistance, maxDistance, messages);
142
- return {
143
- title: title.replace('pickup', 'dine-in'),
144
- msg: msg.replace('pickup', 'dine-in')
145
- };
146
- };
147
- exports.makeWalkinMessaging = makeWalkinMessaging;
148
- const makeDeliveryMesssaging = (address, count, messages = exports.LOCATIONS_MESSAGES) => {
149
- if (!address) {
150
- return messages.DELIVERY.default;
151
- }
152
- else if (!address.street) {
153
- return messages.DELIVERY.noStreet;
154
- }
155
- else {
156
- if (count) {
157
- const locationMsg = count > 1 ? 'locations deliver' : 'location delivers';
158
- return {
159
- title: messages.DELIVERY.hasDelivery.title,
160
- msg: `${count} ${locationMsg} to your address.`,
161
- error: null
162
- };
163
- }
164
- else {
165
- return messages.DELIVERY.noDelivery;
166
- }
167
- }
168
- };
169
- exports.makeDeliveryMesssaging = makeDeliveryMesssaging;
170
- const makeDisplayedRevenueCenters = (revenueCenters, serviceType, address, latLng, maxDistance, isGroupOrder) => {
171
- const filtered = isGroupOrder
172
- ? revenueCenters.filter(i => i.group_ordering)
173
- : revenueCenters;
174
- if (serviceType === 'DELIVERY') {
175
- const displayed = (0, exports.makeDeliveryRevenueCenters)(filtered);
176
- const count = displayed.length;
177
- const { title, msg, error } = (0, exports.makeDeliveryMesssaging)(address, count);
178
- return { title, msg, error, displayed };
179
- }
180
- else if (serviceType === 'WALKIN') {
181
- const displayed = (0, exports.makeWalkinRevenueCenters)(filtered, maxDistance);
182
- const minDistance = (0, exports.calcMinDistance)(displayed);
183
- const count = displayed.length;
184
- const { title, msg } = (0, exports.makeWalkinMessaging)(address, latLng, count, minDistance, maxDistance);
185
- const error = null;
186
- return { title, msg, error, displayed };
187
- }
188
- else {
189
- const displayed = (0, exports.makePickupRevenueCenters)(filtered, maxDistance);
190
- const minDistance = (0, exports.calcMinDistance)(displayed);
191
- const count = displayed.length;
192
- const { title, msg } = (0, exports.makePickupMesssaging)(address, latLng, count, minDistance, maxDistance);
193
- const error = null;
194
- return { title, msg, error, displayed };
195
- }
196
- };
197
- exports.makeDisplayedRevenueCenters = makeDisplayedRevenueCenters;
198
- exports.LOCATIONS_MESSAGES = {
199
- PICKUP: {
200
- default: {
201
- title: 'Please choose a location',
202
- msg: 'Or enter a zip code to find the location nearest you.'
203
- },
204
- address: {
205
- title: 'locations near you',
206
- msg: 'Please choose a location below.'
207
- },
208
- addressFar: {
209
- title: "Looks like we don't have any locations that offer pickup in your area",
210
- msg: 'Sorry about that. Please enter a different address or head back and choose a different order type.'
211
- },
212
- geo: {
213
- title: 'locations in your area',
214
- msg: 'Please enter an address or zip code for a more accurate result.'
215
- },
216
- geoFar: {
217
- title: "Looks like we don't have any locations that offer pickup in your area",
218
- msg: 'Please enter an address or zip code if you live in a different area.'
219
- }
220
- },
221
- DELIVERY: {
222
- default: {
223
- title: "Let's find the nearest location",
224
- msg: 'Please enter your address.',
225
- error: null
226
- },
227
- noStreet: {
228
- title: 'Please enter a street address',
229
- msg: '',
230
- error: 'A full address with street number is required for delivery orders.'
231
- },
232
- hasDelivery: {
233
- title: 'Delivery is available!',
234
- msg: 'Please choose a location below.',
235
- error: null
236
- },
237
- noDelivery: {
238
- title: "Delivery isn't available in your area at this time",
239
- msg: "We're really sorry about that. Please enter a different address or head back and start a pickup order.",
240
- error: null
241
- }
242
- }
243
- };
244
- const renameLocation = (str, names) => {
245
- const [singular, plural] = names;
246
- return str
247
- .replace('1 locations', '1 location')
248
- .replace('locations', plural)
249
- .replace('location', singular)
250
- .replace(' a a', ' an a')
251
- .replace(' a e', ' an e')
252
- .replace(' a i', ' an i')
253
- .replace(' a o', ' an o')
254
- .replace(' a u', ' an u');
255
- };
256
- exports.renameLocation = renameLocation;
257
- const makeMapStyles = ({ labelColor, roadColor, featureColor, waterColor, backgroundColor }) => [
258
- {
259
- featureType: 'transit',
260
- elementType: 'all',
261
- stylers: [{ visibility: 'off' }]
262
- },
263
- {
264
- featureType: 'administrative',
265
- elementType: 'labels.text.fill',
266
- stylers: [{ visibility: 'off' }]
267
- },
268
- {
269
- featureType: 'administrative',
270
- elementType: 'labels.text.stroke',
271
- stylers: [{ visibility: 'off' }]
272
- },
273
- {
274
- featureType: 'road',
275
- elementType: 'labels.icon',
276
- stylers: [{ visibility: 'off' }]
277
- },
278
- {
279
- featureType: 'road',
280
- elementType: 'geometry',
281
- stylers: [{ visibility: 'simplified' }, { color: roadColor }]
282
- },
283
- {
284
- featureType: 'road',
285
- elementType: 'labels.text.fill',
286
- stylers: [{ color: labelColor }]
287
- },
288
- {
289
- featureType: 'road',
290
- elementType: 'labels.text.stroke',
291
- stylers: [{ visibility: 'off' }]
292
- },
293
- {
294
- featureType: 'road.highway',
295
- elementType: 'geometry',
296
- stylers: [{ color: featureColor }]
297
- },
298
- {
299
- featureType: 'road.highway',
300
- elementType: 'labels',
301
- stylers: [{ visibility: 'off' }]
302
- },
303
- {
304
- featureType: 'water',
305
- elementType: 'geometry',
306
- stylers: [{ color: waterColor }]
307
- },
308
- {
309
- featureType: 'water',
310
- elementType: 'labels',
311
- stylers: [{ visibility: 'off' }]
312
- },
313
- {
314
- featureType: 'poi',
315
- elementType: 'geometry',
316
- stylers: [{ color: backgroundColor }]
317
- },
318
- {
319
- featureType: 'poi',
320
- elementType: 'labels',
321
- stylers: [{ visibility: 'off' }]
322
- },
323
- {
324
- featureType: 'landscape',
325
- elementType: 'geometry',
326
- stylers: [{ color: backgroundColor }]
327
- },
328
- {
329
- featureType: 'landscape',
330
- elementType: 'labels',
331
- stylers: [{ visibility: 'off' }]
332
- }
333
- ];
334
- exports.makeMapStyles = makeMapStyles;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeMapStyles = 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 = void 0;
4
+ const constants_1 = require("./constants");
5
+ const RADIUS_MILES = 3959; // radius of the earth in miles
6
+ const RADIUS_KM = 6371; // radius of the earth in kilometers
7
+ // https://stackoverflow.com/questions/18883601/function-to-calculate-distance-between-two-coordinates
8
+ const getDistance = (pointA, pointB, inMiles = true) => {
9
+ const { lat: lat1, lng: lng1 } = pointA;
10
+ const { lat: lat2, lng: lng2 } = pointB;
11
+ const R = inMiles ? RADIUS_MILES : RADIUS_KM;
12
+ const dLat = deg2rad(lat2 - lat1); // see deg2rad below
13
+ const dLng = deg2rad(lng2 - lng1);
14
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
15
+ Math.cos(deg2rad(lat1)) *
16
+ Math.cos(deg2rad(lat2)) *
17
+ Math.sin(dLng / 2) *
18
+ Math.sin(dLng / 2);
19
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
20
+ const d = R * c;
21
+ return d;
22
+ };
23
+ exports.getDistance = getDistance;
24
+ const deg2rad = (deg) => {
25
+ return deg * (Math.PI / 180);
26
+ };
27
+ // ray-casting algorithm based on
28
+ // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
29
+ const pointInPolygon = (point, vs) => {
30
+ const x = point[0], y = point[1];
31
+ let inside = false;
32
+ for (let i = 0, j = vs.length - 1; i < vs.length; j = i++) {
33
+ const xi = vs[i][0], yi = vs[i][1];
34
+ const xj = vs[j][0], yj = vs[j][1];
35
+ const intersect = yi > y != yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
36
+ if (intersect)
37
+ inside = !inside;
38
+ }
39
+ return inside;
40
+ };
41
+ const inZone = (latLng, polygon) => {
42
+ const point = [latLng.lat, latLng.lng];
43
+ return pointInPolygon(point, polygon);
44
+ };
45
+ exports.inZone = inZone;
46
+ const addDistance = (revenueCenters, latLng) => {
47
+ if (!latLng)
48
+ return revenueCenters;
49
+ const withDistance = revenueCenters.map(i => {
50
+ const iLatLng = i.address.lat
51
+ ? { lat: i.address.lat, lng: i.address.lng }
52
+ : null;
53
+ i.distance = iLatLng ? (0, exports.getDistance)(latLng, iLatLng) : 1000;
54
+ const { coordinates, priority } = i.delivery_zone;
55
+ i.inZone = coordinates ? (0, exports.inZone)(latLng, coordinates) : false;
56
+ i.priority = priority !== null && priority !== void 0 ? priority : 0;
57
+ return i;
58
+ });
59
+ return withDistance;
60
+ };
61
+ exports.addDistance = addDistance;
62
+ const sortRevenueCenters = (revenueCenters, isDelivery = false) => {
63
+ if (!isDelivery) {
64
+ 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); });
65
+ }
66
+ const inZoneWithPriority = revenueCenters
67
+ .filter(i => i.inZone && i.priority)
68
+ .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); });
69
+ const inZoneWithoutPriority = revenueCenters
70
+ .filter(i => i.inZone && !i.priority)
71
+ .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); });
72
+ const outOfZone = revenueCenters
73
+ .filter(i => !i.inZone)
74
+ .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); });
75
+ return [...inZoneWithPriority, ...inZoneWithoutPriority, ...outOfZone];
76
+ };
77
+ exports.sortRevenueCenters = sortRevenueCenters;
78
+ const calcMinDistance = (revenueCenters, maxDistance = constants_1.MAX_DISTANCE) => {
79
+ const withDistance = revenueCenters
80
+ .filter(i => i.distance !== null && i.distance !== undefined)
81
+ .map(i => { var _a; return (_a = i.distance) !== null && _a !== void 0 ? _a : 0; });
82
+ return withDistance ? Math.min(...withDistance) : maxDistance;
83
+ };
84
+ exports.calcMinDistance = calcMinDistance;
85
+ const checkServiceType = (revenueCenter, serviceType) => {
86
+ const { service_types } = revenueCenter;
87
+ if (!service_types)
88
+ return false;
89
+ return service_types.includes(serviceType);
90
+ };
91
+ exports.checkServiceType = checkServiceType;
92
+ const makePickupRevenueCenters = (revenueCenters, maxDistance = constants_1.MAX_DISTANCE) => {
93
+ const hasPickup = revenueCenters
94
+ .filter(i => (0, exports.checkServiceType)(i, 'PICKUP'))
95
+ .filter(i => !i.distance || i.distance < maxDistance);
96
+ return (0, exports.sortRevenueCenters)(hasPickup);
97
+ };
98
+ exports.makePickupRevenueCenters = makePickupRevenueCenters;
99
+ const makeWalkinRevenueCenters = (revenueCenters, maxDistance = constants_1.MAX_DISTANCE) => {
100
+ const hasWalkin = revenueCenters
101
+ .filter(i => (0, exports.checkServiceType)(i, 'WALKIN'))
102
+ .filter(i => !i.distance || i.distance < maxDistance);
103
+ return (0, exports.sortRevenueCenters)(hasWalkin);
104
+ };
105
+ exports.makeWalkinRevenueCenters = makeWalkinRevenueCenters;
106
+ const makeDeliveryRevenueCenters = (revenueCenters) => {
107
+ const hasDelivery = revenueCenters.filter(i => (0, exports.checkServiceType)(i, 'DELIVERY'));
108
+ const sorted = (0, exports.sortRevenueCenters)(hasDelivery, true);
109
+ return sorted.filter(i => i.inZone);
110
+ };
111
+ exports.makeDeliveryRevenueCenters = makeDeliveryRevenueCenters;
112
+ const makePickupMesssaging = (address, latLng, count, minDistance, maxDistance = constants_1.MAX_DISTANCE, messages = exports.LOCATIONS_MESSAGES) => {
113
+ if (address) {
114
+ if (minDistance >= maxDistance) {
115
+ return messages.PICKUP.addressFar;
116
+ }
117
+ else {
118
+ return {
119
+ title: `${count} ${messages.PICKUP.address.title}`,
120
+ msg: messages.PICKUP.address.msg
121
+ };
122
+ }
123
+ }
124
+ else if (latLng) {
125
+ if (minDistance >= maxDistance) {
126
+ return messages.PICKUP.geoFar;
127
+ }
128
+ else {
129
+ return {
130
+ title: `${count} ${messages.PICKUP.geo.title}`,
131
+ msg: messages.PICKUP.geo.msg
132
+ };
133
+ }
134
+ }
135
+ else {
136
+ return messages.PICKUP.default;
137
+ }
138
+ };
139
+ exports.makePickupMesssaging = makePickupMesssaging;
140
+ const makeWalkinMessaging = (address, latLng, count, minDistance, maxDistance = constants_1.MAX_DISTANCE, messages = exports.LOCATIONS_MESSAGES) => {
141
+ const { title, msg } = (0, exports.makePickupMesssaging)(address, latLng, count, minDistance, maxDistance, messages);
142
+ return {
143
+ title: title.replace('pickup', 'dine-in'),
144
+ msg: msg.replace('pickup', 'dine-in')
145
+ };
146
+ };
147
+ exports.makeWalkinMessaging = makeWalkinMessaging;
148
+ const makeDeliveryMesssaging = (address, count, messages = exports.LOCATIONS_MESSAGES) => {
149
+ if (!address) {
150
+ return messages.DELIVERY.default;
151
+ }
152
+ else if (!address.street) {
153
+ return messages.DELIVERY.noStreet;
154
+ }
155
+ else {
156
+ if (count) {
157
+ const locationMsg = count > 1 ? 'locations deliver' : 'location delivers';
158
+ return {
159
+ title: messages.DELIVERY.hasDelivery.title,
160
+ msg: `${count} ${locationMsg} to your address.`,
161
+ error: null
162
+ };
163
+ }
164
+ else {
165
+ return messages.DELIVERY.noDelivery;
166
+ }
167
+ }
168
+ };
169
+ exports.makeDeliveryMesssaging = makeDeliveryMesssaging;
170
+ const makeDisplayedRevenueCenters = (revenueCenters, serviceType, address, latLng, maxDistance, isGroupOrder) => {
171
+ const filtered = isGroupOrder
172
+ ? revenueCenters.filter(i => i.group_ordering)
173
+ : revenueCenters;
174
+ if (serviceType === 'DELIVERY') {
175
+ const displayed = (0, exports.makeDeliveryRevenueCenters)(filtered);
176
+ const count = displayed.length;
177
+ const { title, msg, error } = (0, exports.makeDeliveryMesssaging)(address, count);
178
+ return { title, msg, error, displayed };
179
+ }
180
+ else if (serviceType === 'WALKIN') {
181
+ const displayed = (0, exports.makeWalkinRevenueCenters)(filtered, maxDistance);
182
+ const minDistance = (0, exports.calcMinDistance)(displayed);
183
+ const count = displayed.length;
184
+ const { title, msg } = (0, exports.makeWalkinMessaging)(address, latLng, count, minDistance, maxDistance);
185
+ const error = null;
186
+ return { title, msg, error, displayed };
187
+ }
188
+ else {
189
+ const displayed = (0, exports.makePickupRevenueCenters)(filtered, maxDistance);
190
+ const minDistance = (0, exports.calcMinDistance)(displayed);
191
+ const count = displayed.length;
192
+ const { title, msg } = (0, exports.makePickupMesssaging)(address, latLng, count, minDistance, maxDistance);
193
+ const error = null;
194
+ return { title, msg, error, displayed };
195
+ }
196
+ };
197
+ exports.makeDisplayedRevenueCenters = makeDisplayedRevenueCenters;
198
+ exports.LOCATIONS_MESSAGES = {
199
+ PICKUP: {
200
+ default: {
201
+ title: 'Please choose a location',
202
+ msg: 'Or enter a zip code to find the location nearest you.'
203
+ },
204
+ address: {
205
+ title: 'locations near you',
206
+ msg: 'Please choose a location below.'
207
+ },
208
+ addressFar: {
209
+ title: "Looks like we don't have any locations that offer pickup in your area",
210
+ msg: 'Sorry about that. Please enter a different address or head back and choose a different order type.'
211
+ },
212
+ geo: {
213
+ title: 'locations in your area',
214
+ msg: 'Please enter an address or zip code for a more accurate result.'
215
+ },
216
+ geoFar: {
217
+ title: "Looks like we don't have any locations that offer pickup in your area",
218
+ msg: 'Please enter an address or zip code if you live in a different area.'
219
+ }
220
+ },
221
+ DELIVERY: {
222
+ default: {
223
+ title: "Let's find the nearest location",
224
+ msg: 'Please enter your address.',
225
+ error: null
226
+ },
227
+ noStreet: {
228
+ title: 'Please enter a street address',
229
+ msg: '',
230
+ error: 'A full address with street number is required for delivery orders.'
231
+ },
232
+ hasDelivery: {
233
+ title: 'Delivery is available!',
234
+ msg: 'Please choose a location below.',
235
+ error: null
236
+ },
237
+ noDelivery: {
238
+ title: "Delivery isn't available in your area at this time",
239
+ msg: "We're really sorry about that. Please enter a different address or head back and start a pickup order.",
240
+ error: null
241
+ }
242
+ }
243
+ };
244
+ const renameLocation = (str, names) => {
245
+ const [singular, plural] = names;
246
+ return str
247
+ .replace('1 locations', '1 location')
248
+ .replace('locations', plural)
249
+ .replace('location', singular)
250
+ .replace(' a a', ' an a')
251
+ .replace(' a e', ' an e')
252
+ .replace(' a i', ' an i')
253
+ .replace(' a o', ' an o')
254
+ .replace(' a u', ' an u');
255
+ };
256
+ exports.renameLocation = renameLocation;
257
+ const makeMapStyles = ({ labelColor, roadColor, featureColor, waterColor, backgroundColor }) => [
258
+ {
259
+ featureType: 'transit',
260
+ elementType: 'all',
261
+ stylers: [{ visibility: 'off' }]
262
+ },
263
+ {
264
+ featureType: 'administrative',
265
+ elementType: 'labels.text.fill',
266
+ stylers: [{ visibility: 'off' }]
267
+ },
268
+ {
269
+ featureType: 'administrative',
270
+ elementType: 'labels.text.stroke',
271
+ stylers: [{ visibility: 'off' }]
272
+ },
273
+ {
274
+ featureType: 'road',
275
+ elementType: 'labels.icon',
276
+ stylers: [{ visibility: 'off' }]
277
+ },
278
+ {
279
+ featureType: 'road',
280
+ elementType: 'geometry',
281
+ stylers: [{ visibility: 'simplified' }, { color: roadColor }]
282
+ },
283
+ {
284
+ featureType: 'road',
285
+ elementType: 'labels.text.fill',
286
+ stylers: [{ color: labelColor }]
287
+ },
288
+ {
289
+ featureType: 'road',
290
+ elementType: 'labels.text.stroke',
291
+ stylers: [{ visibility: 'off' }]
292
+ },
293
+ {
294
+ featureType: 'road.highway',
295
+ elementType: 'geometry',
296
+ stylers: [{ color: featureColor }]
297
+ },
298
+ {
299
+ featureType: 'road.highway',
300
+ elementType: 'labels',
301
+ stylers: [{ visibility: 'off' }]
302
+ },
303
+ {
304
+ featureType: 'water',
305
+ elementType: 'geometry',
306
+ stylers: [{ color: waterColor }]
307
+ },
308
+ {
309
+ featureType: 'water',
310
+ elementType: 'labels',
311
+ stylers: [{ visibility: 'off' }]
312
+ },
313
+ {
314
+ featureType: 'poi',
315
+ elementType: 'geometry',
316
+ stylers: [{ color: backgroundColor }]
317
+ },
318
+ {
319
+ featureType: 'poi',
320
+ elementType: 'labels',
321
+ stylers: [{ visibility: 'off' }]
322
+ },
323
+ {
324
+ featureType: 'landscape',
325
+ elementType: 'geometry',
326
+ stylers: [{ color: backgroundColor }]
327
+ },
328
+ {
329
+ featureType: 'landscape',
330
+ elementType: 'labels',
331
+ stylers: [{ visibility: 'off' }]
332
+ }
333
+ ];
334
+ exports.makeMapStyles = makeMapStyles;