@ubnt/store.core 9.17.0-alpha.5 → 9.18.0-alpha.0

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 (253) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/apis/smartcat.js +1 -4
  3. package/lib/apis/smartcat.js.map +1 -1
  4. package/lib/apis/smartcat.mjs +1 -4
  5. package/lib/apis/smartcat.mjs.map +1 -1
  6. package/lib/assets/attention.svg +5 -5
  7. package/lib/assets/attention2.svg +5 -5
  8. package/lib/assets/close2.svg +2 -3
  9. package/lib/assets/close3.svg +3 -2
  10. package/lib/components/CategoryTabs/CategoryTabs.types.d.ts +1 -1
  11. package/lib/components/CloserLookSection/CloserLookSection.js.map +1 -1
  12. package/lib/components/CloserLookSection/CloserLookSection.mjs.map +1 -1
  13. package/lib/components/CustomImage/CustomImage.js.map +1 -1
  14. package/lib/components/CustomImage/CustomImage.mjs.map +1 -1
  15. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  16. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js.map +1 -1
  17. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  18. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs.map +1 -1
  19. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  20. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  21. package/lib/components/Footer/hooks/useFooterContent.d.ts +3 -1
  22. package/lib/components/Footer/hooks/useFooterContent.js +8 -1
  23. package/lib/components/Footer/hooks/useFooterContent.js.map +1 -1
  24. package/lib/components/Footer/hooks/useFooterContent.mjs +8 -1
  25. package/lib/components/Footer/hooks/useFooterContent.mjs.map +1 -1
  26. package/lib/components/Footer/translations/ar.json.js +1 -1
  27. package/lib/components/Footer/translations/ar.json.mjs +1 -1
  28. package/lib/components/Footer/translations/de.json.js +1 -1
  29. package/lib/components/Footer/translations/de.json.mjs +1 -1
  30. package/lib/components/Footer/translations/el.json.js +1 -1
  31. package/lib/components/Footer/translations/el.json.mjs +1 -1
  32. package/lib/components/Footer/translations/en.json.js +1 -0
  33. package/lib/components/Footer/translations/en.json.js.map +1 -1
  34. package/lib/components/Footer/translations/en.json.mjs +1 -0
  35. package/lib/components/Footer/translations/en.json.mjs.map +1 -1
  36. package/lib/components/Footer/translations/es.json.js +1 -1
  37. package/lib/components/Footer/translations/es.json.mjs +1 -1
  38. package/lib/components/Footer/translations/fr.json.js +4 -4
  39. package/lib/components/Footer/translations/fr.json.mjs +4 -4
  40. package/lib/components/Footer/translations/it.json.js +1 -1
  41. package/lib/components/Footer/translations/it.json.mjs +1 -1
  42. package/lib/components/Footer/translations/ja.json.js +2 -2
  43. package/lib/components/Footer/translations/ja.json.mjs +2 -2
  44. package/lib/components/Footer/translations/pt-BR.json.js +1 -1
  45. package/lib/components/Footer/translations/pt-BR.json.mjs +1 -1
  46. package/lib/components/Footer/translations/zh-Hans.json.js +4 -4
  47. package/lib/components/Footer/translations/zh-Hans.json.mjs +4 -4
  48. package/lib/components/Footer/translations/zh-Hant-TW.json.js +1 -1
  49. package/lib/components/Footer/translations/zh-Hant-TW.json.mjs +1 -1
  50. package/lib/components/GridGallery/GridGallery.js.map +1 -1
  51. package/lib/components/GridGallery/GridGallery.mjs.map +1 -1
  52. package/lib/components/Header/AccountMenu/AccountMenu.js +22 -20
  53. package/lib/components/Header/AccountMenu/AccountMenu.js.map +1 -1
  54. package/lib/components/Header/AccountMenu/AccountMenu.mjs +22 -20
  55. package/lib/components/Header/AccountMenu/AccountMenu.mjs.map +1 -1
  56. package/lib/components/Header/AccountMenu/megaphone.http.service.js +1 -4
  57. package/lib/components/Header/AccountMenu/megaphone.http.service.js.map +1 -1
  58. package/lib/components/Header/AccountMenu/megaphone.http.service.mjs +1 -4
  59. package/lib/components/Header/AccountMenu/megaphone.http.service.mjs.map +1 -1
  60. package/lib/components/Header/CartModalV2/CartModal.js.map +1 -1
  61. package/lib/components/Header/CartModalV2/CartModal.mjs.map +1 -1
  62. package/lib/components/Header/Header.js.map +1 -1
  63. package/lib/components/Header/Header.mjs.map +1 -1
  64. package/lib/components/Header/Header.types.d.ts +6 -2
  65. package/lib/components/Header/Header.types.js.map +1 -1
  66. package/lib/components/Header/Header.types.mjs.map +1 -1
  67. package/lib/components/Header/LanguageFrame/LanguageFrame.js.map +1 -1
  68. package/lib/components/Header/LanguageFrame/LanguageFrame.mjs.map +1 -1
  69. package/lib/components/Header/LanguageFrame/Mobile/Mobile.js.map +1 -1
  70. package/lib/components/Header/LanguageFrame/Mobile/Mobile.mjs.map +1 -1
  71. package/lib/components/Header/MenuItem/MenuItem.styles.js +2 -2
  72. package/lib/components/Header/MenuItem/MenuItem.styles.js.map +1 -1
  73. package/lib/components/Header/MenuItem/MenuItem.styles.mjs +2 -2
  74. package/lib/components/Header/MenuItem/MenuItem.styles.mjs.map +1 -1
  75. package/lib/components/Header/MenuItem/MenuItem.types.d.ts +1 -0
  76. package/lib/components/Header/Navigation/ProMenu/ProMenu.d.ts +1 -1
  77. package/lib/components/Header/Navigation/ProMenu/ProMenu.js +24 -30
  78. package/lib/components/Header/Navigation/ProMenu/ProMenu.js.map +1 -1
  79. package/lib/components/Header/Navigation/ProMenu/ProMenu.mjs +26 -32
  80. package/lib/components/Header/Navigation/ProMenu/ProMenu.mjs.map +1 -1
  81. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.d.ts +6 -7
  82. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.js +8 -41
  83. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.js.map +1 -1
  84. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.mjs +9 -41
  85. package/lib/components/Header/Navigation/ProMenu/ProMenu.styles.mjs.map +1 -1
  86. package/lib/components/Header/Navigation/ProMenu/ProMenu.types.d.ts +0 -1
  87. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.d.ts +1 -1
  88. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js +67 -92
  89. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.js.map +1 -1
  90. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs +68 -93
  91. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.mjs.map +1 -1
  92. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.d.ts +3 -0
  93. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js +4 -0
  94. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.js.map +1 -1
  95. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs +5 -2
  96. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.styles.mjs.map +1 -1
  97. package/lib/components/Header/Navigation/ProMobileMenu/ProMobileMenu.types.d.ts +7 -6
  98. package/lib/components/Header/Overlay/Overlay.js.map +1 -1
  99. package/lib/components/Header/Overlay/Overlay.mjs.map +1 -1
  100. package/lib/components/Header/ProHeader/ProHeader.d.ts +2 -1
  101. package/lib/components/Header/ProHeader/ProHeader.js +132 -119
  102. package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
  103. package/lib/components/Header/ProHeader/ProHeader.mjs +134 -121
  104. package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
  105. package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +5 -2
  106. package/lib/components/Header/ProHeader/ProHeader.styles.js +8 -2
  107. package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
  108. package/lib/components/Header/ProHeader/ProHeader.styles.mjs +8 -2
  109. package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
  110. package/lib/components/Header/translations/ar.json.js +4 -1
  111. package/lib/components/Header/translations/ar.json.js.map +1 -1
  112. package/lib/components/Header/translations/ar.json.mjs +4 -2
  113. package/lib/components/Header/translations/ar.json.mjs.map +1 -1
  114. package/lib/components/Header/translations/de.json.js +4 -1
  115. package/lib/components/Header/translations/de.json.js.map +1 -1
  116. package/lib/components/Header/translations/de.json.mjs +4 -2
  117. package/lib/components/Header/translations/de.json.mjs.map +1 -1
  118. package/lib/components/Header/translations/el.json.js +4 -1
  119. package/lib/components/Header/translations/el.json.js.map +1 -1
  120. package/lib/components/Header/translations/el.json.mjs +4 -2
  121. package/lib/components/Header/translations/el.json.mjs.map +1 -1
  122. package/lib/components/Header/translations/es.json.js +4 -1
  123. package/lib/components/Header/translations/es.json.js.map +1 -1
  124. package/lib/components/Header/translations/es.json.mjs +4 -2
  125. package/lib/components/Header/translations/es.json.mjs.map +1 -1
  126. package/lib/components/Header/translations/fr.json.js +4 -1
  127. package/lib/components/Header/translations/fr.json.js.map +1 -1
  128. package/lib/components/Header/translations/fr.json.mjs +4 -2
  129. package/lib/components/Header/translations/fr.json.mjs.map +1 -1
  130. package/lib/components/Header/translations/it.json.js +4 -1
  131. package/lib/components/Header/translations/it.json.js.map +1 -1
  132. package/lib/components/Header/translations/it.json.mjs +4 -2
  133. package/lib/components/Header/translations/it.json.mjs.map +1 -1
  134. package/lib/components/Header/translations/ja.json.js +4 -1
  135. package/lib/components/Header/translations/ja.json.js.map +1 -1
  136. package/lib/components/Header/translations/ja.json.mjs +4 -2
  137. package/lib/components/Header/translations/ja.json.mjs.map +1 -1
  138. package/lib/components/Header/translations/pt-BR.json.js +4 -1
  139. package/lib/components/Header/translations/pt-BR.json.js.map +1 -1
  140. package/lib/components/Header/translations/pt-BR.json.mjs +4 -2
  141. package/lib/components/Header/translations/pt-BR.json.mjs.map +1 -1
  142. package/lib/components/Header/translations/zh-Hans.json.js +4 -1
  143. package/lib/components/Header/translations/zh-Hans.json.js.map +1 -1
  144. package/lib/components/Header/translations/zh-Hans.json.mjs +4 -2
  145. package/lib/components/Header/translations/zh-Hans.json.mjs.map +1 -1
  146. package/lib/components/Header/translations/zh-Hant-TW.json.js +4 -1
  147. package/lib/components/Header/translations/zh-Hant-TW.json.js.map +1 -1
  148. package/lib/components/Header/translations/zh-Hant-TW.json.mjs +4 -2
  149. package/lib/components/Header/translations/zh-Hant-TW.json.mjs.map +1 -1
  150. package/lib/components/ImageSequence/ImageSequence.js.map +1 -1
  151. package/lib/components/ImageSequence/ImageSequence.mjs.map +1 -1
  152. package/lib/components/LandingPage/Cards/Card/Card.js.map +1 -1
  153. package/lib/components/LandingPage/Cards/Card/Card.mjs.map +1 -1
  154. package/lib/components/LandingPage/Cards/Cards.js.map +1 -1
  155. package/lib/components/LandingPage/Cards/Cards.mjs.map +1 -1
  156. package/lib/components/MicrositeIntroductionBlock/MicrositeIntroductionBlock.js.map +1 -1
  157. package/lib/components/MicrositeIntroductionBlock/MicrositeIntroductionBlock.mjs.map +1 -1
  158. package/lib/components/MicrositeMediaGrid/MicrositeMediaGrid.js.map +1 -1
  159. package/lib/components/MicrositeMediaGrid/MicrositeMediaGrid.mjs.map +1 -1
  160. package/lib/components/MicrositeProductGrid/MicrositeProductGrid.js.map +1 -1
  161. package/lib/components/MicrositeProductGrid/MicrositeProductGrid.mjs.map +1 -1
  162. package/lib/components/Microsites/MicrositeProductPage.js +39 -0
  163. package/lib/components/Microsites/MicrositeProductPage.js.map +1 -1
  164. package/lib/components/Microsites/MicrositeProductPage.mjs +39 -0
  165. package/lib/components/Microsites/MicrositeProductPage.mjs.map +1 -1
  166. package/lib/components/ModelCompareV3/StickyGrid/StickyGridHeader.js.map +1 -1
  167. package/lib/components/ModelCompareV3/StickyGrid/StickyGridHeader.mjs.map +1 -1
  168. package/lib/components/ProductCompare/ProductCompare.js.map +1 -1
  169. package/lib/components/ProductCompare/ProductCompare.mjs.map +1 -1
  170. package/lib/components/QuantityControls/QuantityControls.js.map +1 -1
  171. package/lib/components/QuantityControls/QuantityControls.mjs.map +1 -1
  172. package/lib/components/RelatedProducts/RelatedProducts.js.map +1 -1
  173. package/lib/components/RelatedProducts/RelatedProducts.mjs.map +1 -1
  174. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  175. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  176. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  177. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  178. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  179. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  180. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  181. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  182. package/lib/components/ReverseLoopingVideo/ReverseLoopingVideo.js.map +1 -1
  183. package/lib/components/ReverseLoopingVideo/ReverseLoopingVideo.mjs.map +1 -1
  184. package/lib/components/ScrollWrapper/ScrollWrapper.js.map +1 -1
  185. package/lib/components/ScrollWrapper/ScrollWrapper.mjs.map +1 -1
  186. package/lib/components/StorageSliders/Slider/Slider.js.map +1 -1
  187. package/lib/components/StorageSliders/Slider/Slider.mjs.map +1 -1
  188. package/lib/components/StorageSliders/StorageSliders.context.js.map +1 -1
  189. package/lib/components/StorageSliders/StorageSliders.context.mjs.map +1 -1
  190. package/lib/components/VariantSelector/Variant/Compatibility/Compatibility.js.map +1 -1
  191. package/lib/components/VariantSelector/Variant/Compatibility/Compatibility.mjs.map +1 -1
  192. package/lib/components/VariantSelector/Variant/Variant.js.map +1 -1
  193. package/lib/components/VariantSelector/Variant/Variant.mjs.map +1 -1
  194. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  195. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  196. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  197. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  198. package/lib/constants/icons/options/colors/black.svg.js +5 -5
  199. package/lib/constants/icons/options/colors/index.js +3 -3
  200. package/lib/constants/icons/options/styles/black.svg.js +5 -5
  201. package/lib/constants/icons/options/styles/index.js +3 -3
  202. package/lib/constants/optionIcons.js +6 -6
  203. package/lib/constants/optionIcons.mjs +4 -4
  204. package/lib/constants/theme.js +4 -0
  205. package/lib/constants/theme.js.map +1 -1
  206. package/lib/constants/theme.mjs +4 -0
  207. package/lib/constants/theme.mjs.map +1 -1
  208. package/lib/constants/url.d.ts +2 -1
  209. package/lib/constants/url.js +1 -0
  210. package/lib/constants/url.js.map +1 -1
  211. package/lib/constants/url.mjs +1 -0
  212. package/lib/constants/url.mjs.map +1 -1
  213. package/lib/contexts/MenuContext/utils.js +1 -0
  214. package/lib/contexts/MenuContext/utils.js.map +1 -1
  215. package/lib/contexts/MenuContext/utils.mjs +1 -0
  216. package/lib/contexts/MenuContext/utils.mjs.map +1 -1
  217. package/lib/helpers/product.js.map +1 -1
  218. package/lib/helpers/product.mjs.map +1 -1
  219. package/lib/helpers/ux.js.map +1 -1
  220. package/lib/helpers/ux.mjs.map +1 -1
  221. package/lib/hooks/useHasTouch.js.map +1 -1
  222. package/lib/hooks/useHasTouch.mjs.map +1 -1
  223. package/lib/hooks/useHorizontalScroll.js.map +1 -1
  224. package/lib/hooks/useHorizontalScroll.mjs.map +1 -1
  225. package/lib/utils/money/allocators/fixedAmount.js +1 -4
  226. package/lib/utils/money/allocators/fixedAmount.js.map +1 -1
  227. package/lib/utils/money/allocators/fixedAmount.mjs +1 -4
  228. package/lib/utils/money/allocators/fixedAmount.mjs.map +1 -1
  229. package/lib/utils/money/allocators/productAmount.js +15 -27
  230. package/lib/utils/money/allocators/productAmount.js.map +1 -1
  231. package/lib/utils/money/allocators/productAmount.mjs +15 -27
  232. package/lib/utils/money/allocators/productAmount.mjs.map +1 -1
  233. package/lib/utils/productSort.js +1 -0
  234. package/lib/utils/productSort.js.map +1 -1
  235. package/lib/utils/productSort.mjs +1 -0
  236. package/lib/utils/productSort.mjs.map +1 -1
  237. package/lib/utils/validations/postalCodeSuperRefinement.js +3 -0
  238. package/lib/utils/validations/postalCodeSuperRefinement.js.map +1 -1
  239. package/lib/utils/validations/postalCodeSuperRefinement.mjs +3 -0
  240. package/lib/utils/validations/postalCodeSuperRefinement.mjs.map +1 -1
  241. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.js +2 -0
  242. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.js.map +1 -1
  243. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.mjs +2 -0
  244. package/lib/utils/validations/stateRegistrationNumberSuperRefinement.mjs.map +1 -1
  245. package/lib/utils/validations/taxIdSuperRefinement.js +2 -0
  246. package/lib/utils/validations/taxIdSuperRefinement.js.map +1 -1
  247. package/lib/utils/validations/taxIdSuperRefinement.mjs +2 -0
  248. package/lib/utils/validations/taxIdSuperRefinement.mjs.map +1 -1
  249. package/lib/utils/variant.js.map +1 -1
  250. package/lib/utils/variant.mjs.map +1 -1
  251. package/lib/utils/wattage.js.map +1 -1
  252. package/lib/utils/wattage.mjs.map +1 -1
  253. package/package.json +1 -1
@@ -4,40 +4,28 @@ var misc = require('../misc.js');
4
4
  var fixedAmount = require('./fixedAmount.js');
5
5
  "use strict";
6
6
  var __defProp = Object.defineProperty;
7
+ var __typeError = msg => {
8
+ throw TypeError(msg);
9
+ };
7
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
8
11
  enumerable: true,
9
12
  configurable: true,
10
13
  writable: true,
11
14
  value
12
15
  }) : obj[key] = value;
13
- var __publicField = (obj, key, value) => {
14
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
- return value;
16
- };
17
- var __accessCheck = (obj, member, msg) => {
18
- if (!member.has(obj)) throw TypeError("Cannot " + msg);
19
- };
20
- var __privateGet = (obj, member, getter) => {
21
- __accessCheck(obj, member, "read from private field");
22
- return getter ? getter.call(obj) : member.get(obj);
23
- };
24
- var __privateAdd = (obj, member, value) => {
25
- if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
26
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
27
- };
28
- var __privateSet = (obj, member, value, setter) => {
29
- __accessCheck(obj, member, "write to private field");
30
- setter ? setter.call(obj, value) : member.set(obj, value);
31
- return value;
32
- };
16
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
17
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
18
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
19
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
20
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
33
21
  var _itemPrice, _currency, _subtotal, _discountAmount, _taxableAmount, _tax, _total;
34
22
  class ProductAmountAllocator {
35
23
  constructor(productSummary) {
36
24
  // #############################################################################
37
25
  // Fixed values
38
26
  // #############################################################################
39
- __privateAdd(this, _itemPrice, void 0);
40
- __privateAdd(this, _currency, void 0);
27
+ __privateAdd(this, _itemPrice);
28
+ __privateAdd(this, _currency);
41
29
  // #############################################################################
42
30
  /**
43
31
  * Remaining quantity to allocate
@@ -46,11 +34,11 @@ class ProductAmountAllocator {
46
34
  // #############################################################################
47
35
  // Specific amount allocators
48
36
  // #############################################################################
49
- __privateAdd(this, _subtotal, void 0);
50
- __privateAdd(this, _discountAmount, void 0);
51
- __privateAdd(this, _taxableAmount, void 0);
52
- __privateAdd(this, _tax, void 0);
53
- __privateAdd(this, _total, void 0);
37
+ __privateAdd(this, _subtotal);
38
+ __privateAdd(this, _discountAmount);
39
+ __privateAdd(this, _taxableAmount);
40
+ __privateAdd(this, _tax);
41
+ __privateAdd(this, _total);
54
42
  const currency = productSummary.currency;
55
43
  const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
56
44
  __privateSet(this, _itemPrice, productSummary.itemPrice);
@@ -1 +1 @@
1
- {"version":3,"file":"productAmount.js","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","__privateGet","amount","allocate","WeakMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,eAAA,EAAAC,cAAA,EAAAC,IAAA,EAAAC,MAAA;AAQO,MAAMC,sBAAuB,CAAA;EAoBlCC,YAAYC,cAAqC,EAAA;IAhBjD;IAAA;IAAA;IAAAC,YAAA,CAAA,IAAA,EAASV,UAAT,EAAA,KAAA,CAAA,CAAA;IACAU,YAAA,CAAA,IAAA,EAAST,SAAT,EAAA,KAAA,CAAA,CAAA;IAKA;IAAA;AAAA;AAAA;IAAAU,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAIA;IAAA;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CAAA,CAAK2B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC,CAAA;MACjEuB,KAAA,EAAOO,YAAOD,YAAK,CAAA,IAAA,EAAAxB,MAAA,CAAA,CAAO0B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC;IAAA,CACvE;EACF;AACF;AApFWD,UAAA,GAAA,IAAAiC,OAAA,CAAA,CAAA;AACAhC,SAAA,GAAA,IAAAgC,OAAA,CAAA,CAAA;AAST/B,SAAA,GAAA,IAAA+B,OAAA,CAAA,CAAA;AACA9B,eAAA,GAAA,IAAA8B,OAAA,CAAA,CAAA;AACA7B,cAAA,GAAA,IAAA6B,OAAA,CAAA,CAAA;AACA5B,IAAA,GAAA,IAAA4B,OAAA,CAAA,CAAA;AACA3B,MAAA,GAAA,IAAA2B,OAAA,CAAA,CAAA;"}
1
+ {"version":3,"file":"productAmount.js","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQu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AAA,EAAA3B,eAAA,CAAA,CAAgB6B,QAAS,CAAAH,iBAAA,EAAmBC,mBAAK7B,SAAS,CAAA,CACjE,CAAA;MACAqB,aAAe,EAAAS,IAAA,CAAAA,MAAA,CACbD,YAAK,CAAA,IAAA,EAAA1B,cAAA,CAAA,CAAe4B,QAAS,CAAAH,iBAAA,EAAmBC,mBAAK7B,SAAS,CAAA,CAChE,CAAA;MACAsB,GAAA,EAAKQ,YAAOD,YAAK,CAAA,IAAA,EAAAzB,IAAA,CAAA,CAAK2B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC,CAAA;MACjEuB,KAAA,EAAOO,YAAOD,YAAK,CAAA,IAAA,EAAAxB,MAAA,CAAA,CAAO0B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC;IAAA,CACvE;EACF;AACF;AApFWD,UAAA,GAAA,IAAAiC,OAAA,CAAA,CAAA;AACAhC,SAAA,GAAA,IAAAgC,OAAA,CAAA,CAAA;AAST/B,SAAA,GAAA,IAAA+B,OAAA,CAAA,CAAA;AACA9B,eAAA,GAAA,IAAA8B,OAAA,CAAA,CAAA;AACA7B,cAAA,GAAA,IAAA6B,OAAA,CAAA,CAAA;AACA5B,IAAA,GAAA,IAAA4B,OAAA,CAAA,CAAA;AACA3B,MAAA,GAAA,IAAA2B,OAAA,CAAA,CAAA;"}
@@ -2,40 +2,28 @@ import { amount } from '../misc.mjs';
2
2
  import { FixedAmountAllocator } from './fixedAmount.mjs';
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
5
+ var __typeError = msg => {
6
+ throw TypeError(msg);
7
+ };
5
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
6
9
  enumerable: true,
7
10
  configurable: true,
8
11
  writable: true,
9
12
  value
10
13
  }) : obj[key] = value;
11
- var __publicField = (obj, key, value) => {
12
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
- return value;
14
- };
15
- var __accessCheck = (obj, member, msg) => {
16
- if (!member.has(obj)) throw TypeError("Cannot " + msg);
17
- };
18
- var __privateGet = (obj, member, getter) => {
19
- __accessCheck(obj, member, "read from private field");
20
- return getter ? getter.call(obj) : member.get(obj);
21
- };
22
- var __privateAdd = (obj, member, value) => {
23
- if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
24
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
- };
26
- var __privateSet = (obj, member, value, setter) => {
27
- __accessCheck(obj, member, "write to private field");
28
- setter ? setter.call(obj, value) : member.set(obj, value);
29
- return value;
30
- };
14
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
16
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
17
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
18
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
31
19
  var _itemPrice, _currency, _subtotal, _discountAmount, _taxableAmount, _tax, _total;
32
20
  class ProductAmountAllocator {
33
21
  constructor(productSummary) {
34
22
  // #############################################################################
35
23
  // Fixed values
36
24
  // #############################################################################
37
- __privateAdd(this, _itemPrice, void 0);
38
- __privateAdd(this, _currency, void 0);
25
+ __privateAdd(this, _itemPrice);
26
+ __privateAdd(this, _currency);
39
27
  // #############################################################################
40
28
  /**
41
29
  * Remaining quantity to allocate
@@ -44,11 +32,11 @@ class ProductAmountAllocator {
44
32
  // #############################################################################
45
33
  // Specific amount allocators
46
34
  // #############################################################################
47
- __privateAdd(this, _subtotal, void 0);
48
- __privateAdd(this, _discountAmount, void 0);
49
- __privateAdd(this, _taxableAmount, void 0);
50
- __privateAdd(this, _tax, void 0);
51
- __privateAdd(this, _total, void 0);
35
+ __privateAdd(this, _subtotal);
36
+ __privateAdd(this, _discountAmount);
37
+ __privateAdd(this, _taxableAmount);
38
+ __privateAdd(this, _tax);
39
+ __privateAdd(this, _total);
52
40
  const currency = productSummary.currency;
53
41
  const priceForAllocation = productSummary.itemPrice * productSummary.quantity;
54
42
  __privateSet(this, _itemPrice, productSummary.itemPrice);
@@ -1 +1 @@
1
- {"version":3,"file":"productAmount.mjs","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","__privateGet","amount","allocate","WeakMap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,eAAA,EAAAC,cAAA,EAAAC,IAAA,EAAAC,MAAA;AAQO,MAAMC,sBAAuB,CAAA;EAoBlCC,YAAYC,cAAqC,EAAA;IAhBjD;IAAA;IAAA;IAAAC,YAAA,CAAA,IAAA,EAASV,UAAT,EAAA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,CAAAH,iBAAA,EAAmBC,mBAAK7B,SAAS,CAAA,CAChE,CAAA;MACAsB,GAAA,EAAKQ,OAAOD,YAAK,CAAA,IAAA,EAAAzB,IAAA,CAAA,CAAK2B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC,CAAA;MACjEuB,KAAA,EAAOO,OAAOD,YAAK,CAAA,IAAA,EAAAxB,MAAA,CAAA,CAAO0B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC;IAAA,CACvE;EACF;AACF;AApFWD,UAAA,GAAA,IAAAiC,OAAA,CAAA,CAAA;AACAhC,SAAA,GAAA,IAAAgC,OAAA,CAAA,CAAA;AAST/B,SAAA,GAAA,IAAA+B,OAAA,CAAA,CAAA;AACA9B,eAAA,GAAA,IAAA8B,OAAA,CAAA,CAAA;AACA7B,cAAA,GAAA,IAAA6B,OAAA,CAAA,CAAA;AACA5B,IAAA,GAAA,IAAA4B,OAAA,CAAA,CAAA;AACA3B,MAAA,GAAA,IAAA2B,OAAA,CAAA,CAAA;"}
1
+ {"version":3,"file":"productAmount.mjs","sources":["../../../../src/utils/money/allocators/productAmount.ts"],"sourcesContent":["import type { Currency } from \"../../../types\";\nimport { amount } from \"../misc\";\nimport type { Cents, FullLineItemSummary } from \"../types\";\nimport { FixedAmountAllocator } from \"./fixedAmount\";\n\n/**\n * Helper class to distribute a total amount for a product\n */\nexport class ProductAmountAllocator {\n // #############################################################################\n // Fixed values\n // #############################################################################\n readonly #itemPrice: Cents;\n readonly #currency: Currency;\n // #############################################################################\n /**\n * Remaining quantity to allocate\n */\n quantity: number;\n // #############################################################################\n // Specific amount allocators\n // #############################################################################\n #subtotal: FixedAmountAllocator;\n #discountAmount: FixedAmountAllocator;\n #taxableAmount: FixedAmountAllocator;\n #tax: FixedAmountAllocator;\n #total: FixedAmountAllocator;\n\n constructor(productSummary: FullLineItemSummary) {\n const currency = productSummary.currency;\n\n /**\n * Somewhat hackish, just need a stable price that can easily divide later by quantity\n */\n const priceForAllocation =\n productSummary.itemPrice * productSummary.quantity;\n\n this.#itemPrice = productSummary.itemPrice;\n this.#currency = currency;\n this.quantity = productSummary.quantity;\n this.#subtotal = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.subtotal,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#discountAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.discountAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#taxableAmount = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.taxableAmount,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#tax = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.tax,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n this.#total = new FixedAmountAllocator({\n initialAllocateAmount: productSummary.total,\n initialTotalAmount: priceForAllocation,\n currency,\n });\n }\n\n allocateQty(quantity: number): FullLineItemSummary {\n // Calculate remaining allocatable quantity\n let quantityNormalized = Math.max(quantity, 0);\n quantityNormalized =\n this.quantity - quantityNormalized >= 0 ? quantityNormalized : 0;\n\n // Adjust remaining qty\n this.quantity = Math.max(this.quantity - quantityNormalized, 0);\n\n // How big of a slice of the total price we need to allocate\n const itemQuantityPrice = this.#itemPrice * quantityNormalized;\n\n return {\n itemPrice: this.#itemPrice,\n currency: this.#currency,\n quantity: quantityNormalized,\n subtotal: amount(\n this.#subtotal.allocate(itemQuantityPrice, this.#currency),\n ),\n discountAmount: amount(\n this.#discountAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n taxableAmount: amount(\n this.#taxableAmount.allocate(itemQuantityPrice, this.#currency),\n ),\n tax: amount(this.#tax.allocate(itemQuantityPrice, this.#currency)),\n total: amount(this.#total.allocate(itemQuantityPrice, this.#currency)),\n } satisfies FullLineItemSummary;\n }\n}\n"],"names":["_itemPrice","_currency","_subtotal","_discountAmount","_taxableAmount","_tax","_total","ProductAmountAllocator","constructor","productSummary","__privateAdd","__publicField","currency","priceForAllocation","itemPrice","quantity","__privateSet","FixedAmountAllocator","initialAllocateAmount","subtotal","initialTotalAmount","discountAmount","taxableAmount","tax","total","allocateQty","quantityNormalized","Math","max","itemQuantityPrice","__privateGet","amount","allocate","WeakMap"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,EAAAC,SAAA,EAAAC,SAAA,EAAAC,eAAA,EAAAC,cAAA,EAAAC,IAAA,EAAAC,MAAA;AAQO,MAAMC,sBAAuB,CAAA;EAoBlCC,YAAYC,cAAqC,EAAA;IAhBjD;IAAA;IAAA;IAASC,YAAA,CAAA,IAAA,EAAAV,UAAA,CAAA;IACAU,YAAA,CAAA,IAAA,EAAAT,SAAA,CAAA;IAKT;IAAA;AAAA;AAAA;IAAAU,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;IAIA;IAAA;IAAA;IAAAD,YAAA,CAAA,IAAA,EAAAR,SAAA,CAAA;IACAQ,YAAA,CAAA,IAAA,EAAAP,eAAA,CAAA;IACAO,YAAA,CAAA,IAAA,EAAAN,cAAA,CAAA;IACAM,YAAA,CAAA,IAAA,EAAAL,IAAA,CAAA;IACAK,YAAA,CAAA,IAAA,EAAAJ,MAAA,CAAA;IAGE,MAAMM,WAAWH,cAAe,CAAAG,QAAA;IAK1B,MAAAC,kBAAA,GACJJ,cAAe,CAAAK,SAAA,GAAYL,cAAe,CAAAM,QAAA;IAE5CC,YAAA,CAAA,IAAA,EAAKhB,YAAaS,cAAe,CAAAK,SAAA,CAAA;IACjCE,YAAA,CAAA,IAAA,EAAKf,SAAY,EAAAW,QAAA,CAAA;IACjB,IAAA,CAAKG,WAAWN,cAAe,CAAAM,QAAA;IAC1BC,YAAA,CAAA,IAAA,EAAAd,SAAA,EAAY,IAAIe,oBAAqB,CAAA;MACxCC,uBAAuBT,cAAe,CAAAU,QAAA;MACtCC,kBAAoB,EAAAP,kBAAA;MACpBD;IACD,CAAA,CAAA,CAAA;IACII,YAAA,CAAA,IAAA,EAAAb,eAA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A,EAAmBC,mBAAK7B,SAAS,CAAA,CAC3D,CAAA;MACAoB,cAAgB,EAAAU,MAAA,CACdD,YAAK,CAAA,IAAA,EAAA3B,eAAA,CAAA,CAAgB6B,QAAS,CAAAH,iBAAA,EAAmBC,mBAAK7B,SAAS,CAAA,CACjE,CAAA;MACAqB,aAAe,EAAAS,MAAA,CACbD,YAAK,CAAA,IAAA,EAAA1B,cAAA,CAAA,CAAe4B,QAAS,CAAAH,iBAAA,EAAmBC,mBAAK7B,SAAS,CAAA,CAChE,CAAA;MACAsB,GAAA,EAAKQ,OAAOD,YAAK,CAAA,IAAA,EAAAzB,IAAA,CAAA,CAAK2B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC,CAAA;MACjEuB,KAAA,EAAOO,OAAOD,YAAK,CAAA,IAAA,EAAAxB,MAAA,CAAA,CAAO0B,SAASH,iBAAmB,EAAAC,YAAA,CAAA,IAAA,EAAK7B,UAAS,CAAC;IAAA,CACvE;EACF;AACF;AApFWD,UAAA,GAAA,IAAAiC,OAAA,CAAA,CAAA;AACAhC,SAAA,GAAA,IAAAgC,OAAA,CAAA,CAAA;AAST/B,SAAA,GAAA,IAAA+B,OAAA,CAAA,CAAA;AACA9B,eAAA,GAAA,IAAA8B,OAAA,CAAA,CAAA;AACA7B,cAAA,GAAA,IAAA6B,OAAA,CAAA,CAAA;AACA5B,IAAA,GAAA,IAAA4B,OAAA,CAAA,CAAA;AACA3B,MAAA,GAAA,IAAA2B,OAAA,CAAA,CAAA;"}
@@ -38,6 +38,7 @@ const sortByPrice = order => (current, next) => {
38
38
  };
39
39
  const sortProducts = (currentSort, storeId, sortByWeightTag = true) => (current, next) => {
40
40
  switch (currentSort) {
41
+ // Sort by price
41
42
  case "highest-price" /* HighestPrice */:
42
43
  case "lowest-price" /* LowestPrice */:
43
44
  {
@@ -1 +1 @@
1
- {"version":3,"file":"productSort.js","sources":["../../src/utils/productSort.ts"],"sourcesContent":["import type { Nullish, StorefrontProduct, StoreId, UnionToAllPossibleTuples } from \"../types\";\nimport { DisplayProductStatus } from \"../types\";\nimport { combineSorts, normalizeSortResult } from \"./array\";\nimport { sortByTagWeight, SortSiteId } from \"./product\";\n\n/**\n * Narrow MinimalProProductFragment type even more to the union of fields that are needed to sort product\n */\ntype ProductMinFieldsForSorting = Pick<\n StorefrontProduct,\n \"status\" | \"tags\" | \"minDisplayPrice\"\n> & {\n variants: {\n // We only need bare minimum from array to compare array length\n // FIXME: move it to backend as a boolean field so we don't need to fetch entire array to reduce it to a boolean ourselves\n availableInOtherStores: Array<{ __typename: string }>;\n }[];\n linkedProducts?: {\n status: StorefrontProduct[\"status\"];\n }[];\n};\n\nexport enum Sort {\n HighestPrice = \"highest-price\",\n LowestPrice = \"lowest-price\",\n Availability = \"availability\",\n}\n\nexport enum SortOrder {\n Asc = \"Asc\",\n Desc = \"Desc\",\n}\n\n/**\n * Variants statuses sorted in ascending order from least preferable to most, so if some new status comes in, then the\n * lookup for `.indexOf()` would return `-1`, thus being \"worse\" then DisplayProductStatus.SoldOut and moved to the very\n * back of list\n */\nexport const sortedStatusesByPriorityAsc: UnionToAllPossibleTuples<DisplayProductStatus> =\n [\n DisplayProductStatus.Unavailable,\n DisplayProductStatus.ComingSoon,\n DisplayProductStatus.SoldOut,\n DisplayProductStatus.RegionNotAvailable,\n DisplayProductStatus.Backorder,\n DisplayProductStatus.Available,\n ];\n/**\n * Due to currently variant status being nullable for historical reasons we need to have a fallback state\n * TODO: remove once display status is StorefrontProductVariant.status is non-nullable\n */\nconst getProductStatusPriority = (\n product: ProductMinFieldsForSorting,\n): number => {\n let sortStatus = product.status;\n\n // Virtually set sort status as available if it has alternative stores\n if (\n product.variants.some((variant) => variant.availableInOtherStores.length) ||\n (product.linkedProducts &&\n product.linkedProducts.some(\n (linkedProduct) =>\n linkedProduct.status === DisplayProductStatus.Available,\n ))\n ) {\n sortStatus = DisplayProductStatus.Available;\n }\n\n return sortedStatusesByPriorityAsc.indexOf(sortStatus);\n};\n\nexport const sortByAvailabilityDesc = (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n): number => {\n return normalizeSortResult(\n getProductStatusPriority(next) - getProductStatusPriority(current),\n );\n};\n\nexport const sortByPrice =\n (order: SortOrder) => (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n ): number => {\n const currentProductPrice = current.minDisplayPrice.amount;\n\n const nextProductPrice = next.minDisplayPrice.amount;\n\n if (order === SortOrder.Desc) {\n return nextProductPrice - currentProductPrice;\n } else {\n return currentProductPrice - nextProductPrice;\n }\n };\n\n\n/**\n * Sorts products based on the given sort type.\n * @param currentSort - sort type\n * @param sortByWeightTag - if false, then sort by weight tag is\n * ignored (e.g. for `Related Add-ons` where\n * we don't want to sort by weight tag)\n */\nexport const sortProducts = (\n currentSort: Nullish<string | Sort>,\n storeId?: StoreId,\n sortByWeightTag = true,\n ) =>\n (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => {\n switch (currentSort) {\n // Sort by price\n case Sort.HighestPrice:\n case Sort.LowestPrice: {\n return sortByPrice(\n currentSort === Sort.HighestPrice ? SortOrder.Desc : SortOrder.Asc,\n )(current, next);\n }\n\n case Sort.Availability: {\n return sortByAvailabilityDesc(current, next);\n }\n\n default: {\n const sorts = [sortByAvailabilityDesc];\n\n // Add sorting by tag weight\n if (sortByWeightTag) {\n sorts.push(sortByTagWeight(SortSiteId.Store, storeId));\n }\n\n // Do additional sorting by tag weight only after initial sorting resulting in \"same group\"\n return combineSorts(sorts)(current, next);\n }\n }\n };"],"names":["Sort","SortOrder","sortedStatusesByPriorityAsc","DisplayProductStatus","Unavailable","ComingSoon","SoldOut","RegionNotAvailable","Backorder","Available","getProductStatusPriority","product","sortStatus","status","variants","some","variant","availableInOtherStores","length","linkedProducts","linkedProduct","indexOf","sortByAvailabilityDesc","current","next","normalizeSortResult","sortByPrice","order","currentProductPrice","minDisplayPrice","amount","nextProductPrice","sortProducts","currentSort","storeId","sort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file":"productSort.js","sources":["../../src/utils/productSort.ts"],"sourcesContent":["import type { Nullish, StorefrontProduct, StoreId, UnionToAllPossibleTuples } from \"../types\";\nimport { DisplayProductStatus } from \"../types\";\nimport { combineSorts, normalizeSortResult } from \"./array\";\nimport { sortByTagWeight, SortSiteId } from \"./product\";\n\n/**\n * Narrow MinimalProProductFragment type even more to the union of fields that are needed to sort product\n */\ntype ProductMinFieldsForSorting = Pick<\n StorefrontProduct,\n \"status\" | \"tags\" | \"minDisplayPrice\"\n> & {\n variants: {\n // We only need bare minimum from array to compare array length\n // FIXME: move it to backend as a boolean field so we don't need to fetch entire array to reduce it to a boolean ourselves\n availableInOtherStores: Array<{ __typename: string }>;\n }[];\n linkedProducts?: {\n status: StorefrontProduct[\"status\"];\n }[];\n};\n\nexport enum Sort {\n HighestPrice = \"highest-price\",\n LowestPrice = \"lowest-price\",\n Availability = \"availability\",\n}\n\nexport enum SortOrder {\n Asc = \"Asc\",\n Desc = \"Desc\",\n}\n\n/**\n * Variants statuses sorted in ascending order from least preferable to most, so if some new status comes in, then the\n * lookup for `.indexOf()` would return `-1`, thus being \"worse\" then DisplayProductStatus.SoldOut and moved to the very\n * back of list\n */\nexport const sortedStatusesByPriorityAsc: UnionToAllPossibleTuples<DisplayProductStatus> =\n [\n DisplayProductStatus.Unavailable,\n DisplayProductStatus.ComingSoon,\n DisplayProductStatus.SoldOut,\n DisplayProductStatus.RegionNotAvailable,\n DisplayProductStatus.Backorder,\n DisplayProductStatus.Available,\n ];\n/**\n * Due to currently variant status being nullable for historical reasons we need to have a fallback state\n * TODO: remove once display status is StorefrontProductVariant.status is non-nullable\n */\nconst getProductStatusPriority = (\n product: ProductMinFieldsForSorting,\n): number => {\n let sortStatus = product.status;\n\n // Virtually set sort status as available if it has alternative stores\n if (\n product.variants.some((variant) => variant.availableInOtherStores.length) ||\n (product.linkedProducts &&\n product.linkedProducts.some(\n (linkedProduct) =>\n linkedProduct.status === DisplayProductStatus.Available,\n ))\n ) {\n sortStatus = DisplayProductStatus.Available;\n }\n\n return sortedStatusesByPriorityAsc.indexOf(sortStatus);\n};\n\nexport const sortByAvailabilityDesc = (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n): number => {\n return normalizeSortResult(\n getProductStatusPriority(next) - getProductStatusPriority(current),\n );\n};\n\nexport const sortByPrice =\n (order: SortOrder) => (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n ): number => {\n const currentProductPrice = current.minDisplayPrice.amount;\n\n const nextProductPrice = next.minDisplayPrice.amount;\n\n if (order === SortOrder.Desc) {\n return nextProductPrice - currentProductPrice;\n } else {\n return currentProductPrice - nextProductPrice;\n }\n };\n\n\n/**\n * Sorts products based on the given sort type.\n * @param currentSort - sort type\n * @param sortByWeightTag - if false, then sort by weight tag is\n * ignored (e.g. for `Related Add-ons` where\n * we don't want to sort by weight tag)\n */\nexport const sortProducts = (\n currentSort: Nullish<string | Sort>,\n storeId?: StoreId,\n sortByWeightTag = true,\n ) =>\n (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => {\n switch (currentSort) {\n // Sort by price\n case Sort.HighestPrice:\n case Sort.LowestPrice: {\n return sortByPrice(\n currentSort === Sort.HighestPrice ? SortOrder.Desc : SortOrder.Asc,\n )(current, next);\n }\n\n case Sort.Availability: {\n return sortByAvailabilityDesc(current, next);\n }\n\n default: {\n const sorts = [sortByAvailabilityDesc];\n\n // Add sorting by tag weight\n if (sortByWeightTag) {\n sorts.push(sortByTagWeight(SortSiteId.Store, storeId));\n }\n\n // Do additional sorting by tag weight only after initial sorting resulting in \"same group\"\n return combineSorts(sorts)(current, next);\n }\n }\n };"],"names":["Sort","SortOrder","sortedStatusesByPriorityAsc","DisplayProductStatus","Unavailable","ComingSoon","SoldOut","RegionNotAvailable","Backorder","Available","getProductStatusPriority","product","sortStatus","status","variants","some","variant","availableInOtherStores","length","linkedProducts","linkedProduct","indexOf","sortByAvailabilityDesc","current","next","normalizeSortResult","sortByPrice","order","currentProductPrice","minDisplayPrice","amount","nextProductPrice","sortProducts","currentSort","storeId","sortByWeightTag","sorts","push","sortByTagWeight","SortSiteId","Store","combineSorts"],"mappings":";;;;;;;AAsBY,IAAAA,IAAA,GAAA,gBAAAA,KAAL,IAAA;EACLA,MAAA,cAAe,CAAA,GAAA,eAAA;EACfA,MAAA,aAAc,CAAA,GAAA,cAAA;EACdA,MAAA,cAAe,CAAA,GAAA,cAAA;EAHLA,OAAAA,KAAAA;AAAA,CAAA,EAAAA,IAAA,IAAA,CAAA,CAAA,CAAA;AAMA,IAAAC,SAAA,GAAA,gBAAAA,UAAL,IAAA;EACLA,WAAA,KAAM,CAAA,GAAA,KAAA;EACNA,WAAA,MAAO,CAAA,GAAA,MAAA;EAFGA,OAAAA,UAAAA;AAAA,CAAA,EAAAA,SAAA,IAAA,CAAA,CAAA,CAAA;AAUL,MAAMC,2BACX,GAAA,CACEC,OAAAA,CAAAA,oBAAqB,CAAAC,WAAA,EACrBD,OAAAA,CAAAA,oBAAqB,CAAAE,UAAA,EACrBF,OAAAA,CAAAA,oBAAqB,CAAAG,OAAA,EACrBH,OAAAA,CAAAA,oBAAqB,CAAAI,kBAAA,EACrBJ,OAAAA,CAAAA,oBAAqB,CAAAK,SAAA,EACrBL,OAAAA,CAAAA,oBAAqB,CAAAM,SAAA,CACvB;AAKF,MAAMC,wBAAA,GACJC,SACW,IAAA;EACX,IAAIC,aAAaD,SAAQ,CAAAE,MAAA;EAGzB,IACEF,SAAQ,CAAAG,QAAA,CAASC,IAAK,CAACC,OAAY,IAAAA,OAAA,CAAQC,sBAAuB,CAAAC,MAAM,CACvE,IAAAP,SAAA,CAAQQ,cACP,IAAAR,SAAA,CAAQQ,cAAe,CAAAJ,IAAA,CACpBK,aAAA,IACCA,aAAc,CAAAP,MAAA,KAAWV,OAAqB,CAAAA,oBAAA,CAAAM,SAAA,CAEpD,EAAA;IACAG,UAAA,GAAaT,OAAqB,CAAAA,oBAAA,CAAAM,SAAA;EACpC;EAE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C,IAAI,CAAA;MAC1C;EACF;AACF,CAAA;;;;;;"}
@@ -36,6 +36,7 @@ const sortByPrice = order => (current, next) => {
36
36
  };
37
37
  const sortProducts = (currentSort, storeId, sortByWeightTag = true) => (current, next) => {
38
38
  switch (currentSort) {
39
+ // Sort by price
39
40
  case "highest-price" /* HighestPrice */:
40
41
  case "lowest-price" /* LowestPrice */:
41
42
  {
@@ -1 +1 @@
1
- {"version":3,"file":"productSort.mjs","sources":["../../src/utils/productSort.ts"],"sourcesContent":["import type { Nullish, StorefrontProduct, StoreId, UnionToAllPossibleTuples } from \"../types\";\nimport { DisplayProductStatus } from \"../types\";\nimport { combineSorts, normalizeSortResult } from \"./array\";\nimport { sortByTagWeight, SortSiteId } from \"./product\";\n\n/**\n * Narrow MinimalProProductFragment type even more to the union of fields that are needed to sort product\n */\ntype ProductMinFieldsForSorting = Pick<\n StorefrontProduct,\n \"status\" | \"tags\" | \"minDisplayPrice\"\n> & {\n variants: {\n // We only need bare minimum from array to compare array length\n // FIXME: move it to backend as a boolean field so we don't need to fetch entire array to reduce it to a boolean ourselves\n availableInOtherStores: Array<{ __typename: string }>;\n }[];\n linkedProducts?: {\n status: StorefrontProduct[\"status\"];\n }[];\n};\n\nexport enum Sort {\n HighestPrice = \"highest-price\",\n LowestPrice = \"lowest-price\",\n Availability = \"availability\",\n}\n\nexport enum SortOrder {\n Asc = \"Asc\",\n Desc = \"Desc\",\n}\n\n/**\n * Variants statuses sorted in ascending order from least preferable to most, so if some new status comes in, then the\n * lookup for `.indexOf()` would return `-1`, thus being \"worse\" then DisplayProductStatus.SoldOut and moved to the very\n * back of list\n */\nexport const sortedStatusesByPriorityAsc: UnionToAllPossibleTuples<DisplayProductStatus> =\n [\n DisplayProductStatus.Unavailable,\n DisplayProductStatus.ComingSoon,\n DisplayProductStatus.SoldOut,\n DisplayProductStatus.RegionNotAvailable,\n DisplayProductStatus.Backorder,\n DisplayProductStatus.Available,\n ];\n/**\n * Due to currently variant status being nullable for historical reasons we need to have a fallback state\n * TODO: remove once display status is StorefrontProductVariant.status is non-nullable\n */\nconst getProductStatusPriority = (\n product: ProductMinFieldsForSorting,\n): number => {\n let sortStatus = product.status;\n\n // Virtually set sort status as available if it has alternative stores\n if (\n product.variants.some((variant) => variant.availableInOtherStores.length) ||\n (product.linkedProducts &&\n product.linkedProducts.some(\n (linkedProduct) =>\n linkedProduct.status === DisplayProductStatus.Available,\n ))\n ) {\n sortStatus = DisplayProductStatus.Available;\n }\n\n return sortedStatusesByPriorityAsc.indexOf(sortStatus);\n};\n\nexport const sortByAvailabilityDesc = (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n): number => {\n return normalizeSortResult(\n getProductStatusPriority(next) - getProductStatusPriority(current),\n );\n};\n\nexport const sortByPrice =\n (order: SortOrder) => (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n ): number => {\n const currentProductPrice = current.minDisplayPrice.amount;\n\n const nextProductPrice = next.minDisplayPrice.amount;\n\n if (order === SortOrder.Desc) {\n return nextProductPrice - currentProductPrice;\n } else {\n return currentProductPrice - nextProductPrice;\n }\n };\n\n\n/**\n * Sorts products based on the given sort type.\n * @param currentSort - sort type\n * @param sortByWeightTag - if false, then sort by weight tag is\n * ignored (e.g. for `Related Add-ons` where\n * we don't want to sort by weight tag)\n */\nexport const sortProducts = (\n currentSort: Nullish<string | Sort>,\n storeId?: StoreId,\n sortByWeightTag = true,\n ) =>\n (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => {\n switch (currentSort) {\n // Sort by price\n case Sort.HighestPrice:\n case Sort.LowestPrice: {\n return sortByPrice(\n currentSort === Sort.HighestPrice ? SortOrder.Desc : SortOrder.Asc,\n )(current, next);\n }\n\n case Sort.Availability: {\n return sortByAvailabilityDesc(current, next);\n }\n\n default: {\n const sorts = [sortByAvailabilityDesc];\n\n // Add sorting by tag weight\n if (sortByWeightTag) {\n sorts.push(sortByTagWeight(SortSiteId.Store, storeId));\n }\n\n // Do additional sorting by tag weight only after initial sorting resulting in \"same group\"\n return combineSorts(sorts)(current, next);\n }\n }\n };"],"names":["Sort","SortOrder","sortedStatusesByPriorityAsc","DisplayProductStatus","Unavailable","ComingSoon","SoldOut","RegionNotAvailable","Backorder","Available","getProductStatusPriority","product","sortStatus","status","variants","some","variant","availableInOtherStores","length","linkedProducts","linkedProduct","indexOf","sortByAvailabilityDesc","current","next","normalizeSortResult","sortByPrice","order","currentProductPrice","minDisplayPrice","amount","nextProductPrice","sortProducts","currentSort","storeId","sortByWeightTag","sorts","push","sortByTagWeight","SortSiteId","Store","combineSorts"],"mappings":";;;;;AAsBY,IAAAA,IAAA,GAAA,gBAAAA,KAAL,IAAA;EACLA,MAAA,cAAe,CAAA,GAAA,eAAA;EACfA,MAAA,aAAc,CAAA,GAAA,cAAA;EACdA,MAAA,cAAe,CAAA,GAAA,cAAA;EAHLA,OAAAA,KAAAA;AAAA,CAAA,EAAAA,IAAA,IAAA,CAAA,CAAA,CAAA;AAMA,IAAAC,SAAA,GAAA,gBAAAA,UAAL,IAAA;EACLA,WAAA,KAAM,CAAA,GAAA,KAAA;EACNA,WAAA,MAAO,CAAA,GAAA,MAAA;EAFGA,OAAAA,UAAAA;AAAA,CAAA,EAAAA,SAAA,IAAA,CAAA,CAAA,CAAA;AAUL,MAAMC,2BACX,GAAA,CACEC,oBAAqB,CAAAC,WAAA,EACrBD,oBAAqB,CAAAE,UAAA,EACrBF,oBAAqB,CAAAG,OAAA,EACrBH,oBAAqB,CAAAI,kBAAA,EACrBJ,oBAAqB,CAAAK,SAAA,EACrBL,oBAAqB,CAAAM,SAAA,CACvB;AAKF,MAAMC,wBAAA,GACJC,OACW,IAAA;EACX,IAAIC,aAAaD,OAAQ,CAAAE,MAAA;EAGzB,IACEF,OAAQ,CAAAG,QAAA,CAASC,IAAK,CAACC,OAAY,IAAAA,OAAA,CAAQC,sBAAuB,CAAAC,MAAM,CACvE,IAAAP,OAAA,CAAQQ,cACP,IAAAR,OAAA,CAA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AAAC,KAAA,EAAON,OAAO,CAAC,CAAA;QACvD;QAGA,OAAOO,YAAa,CAAAL,KAAK,CAAE,CAAAb,OAAA,EAASC,IAAI,CAAA;MAC1C;EACF;AACF,CAAA;"}
1
+ {"version":3,"file":"productSort.mjs","sources":["../../src/utils/productSort.ts"],"sourcesContent":["import type { Nullish, StorefrontProduct, StoreId, UnionToAllPossibleTuples } from \"../types\";\nimport { DisplayProductStatus } from \"../types\";\nimport { combineSorts, normalizeSortResult } from \"./array\";\nimport { sortByTagWeight, SortSiteId } from \"./product\";\n\n/**\n * Narrow MinimalProProductFragment type even more to the union of fields that are needed to sort product\n */\ntype ProductMinFieldsForSorting = Pick<\n StorefrontProduct,\n \"status\" | \"tags\" | \"minDisplayPrice\"\n> & {\n variants: {\n // We only need bare minimum from array to compare array length\n // FIXME: move it to backend as a boolean field so we don't need to fetch entire array to reduce it to a boolean ourselves\n availableInOtherStores: Array<{ __typename: string }>;\n }[];\n linkedProducts?: {\n status: StorefrontProduct[\"status\"];\n }[];\n};\n\nexport enum Sort {\n HighestPrice = \"highest-price\",\n LowestPrice = \"lowest-price\",\n Availability = \"availability\",\n}\n\nexport enum SortOrder {\n Asc = \"Asc\",\n Desc = \"Desc\",\n}\n\n/**\n * Variants statuses sorted in ascending order from least preferable to most, so if some new status comes in, then the\n * lookup for `.indexOf()` would return `-1`, thus being \"worse\" then DisplayProductStatus.SoldOut and moved to the very\n * back of list\n */\nexport const sortedStatusesByPriorityAsc: UnionToAllPossibleTuples<DisplayProductStatus> =\n [\n DisplayProductStatus.Unavailable,\n DisplayProductStatus.ComingSoon,\n DisplayProductStatus.SoldOut,\n DisplayProductStatus.RegionNotAvailable,\n DisplayProductStatus.Backorder,\n DisplayProductStatus.Available,\n ];\n/**\n * Due to currently variant status being nullable for historical reasons we need to have a fallback state\n * TODO: remove once display status is StorefrontProductVariant.status is non-nullable\n */\nconst getProductStatusPriority = (\n product: ProductMinFieldsForSorting,\n): number => {\n let sortStatus = product.status;\n\n // Virtually set sort status as available if it has alternative stores\n if (\n product.variants.some((variant) => variant.availableInOtherStores.length) ||\n (product.linkedProducts &&\n product.linkedProducts.some(\n (linkedProduct) =>\n linkedProduct.status === DisplayProductStatus.Available,\n ))\n ) {\n sortStatus = DisplayProductStatus.Available;\n }\n\n return sortedStatusesByPriorityAsc.indexOf(sortStatus);\n};\n\nexport const sortByAvailabilityDesc = (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n): number => {\n return normalizeSortResult(\n getProductStatusPriority(next) - getProductStatusPriority(current),\n );\n};\n\nexport const sortByPrice =\n (order: SortOrder) => (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n ): number => {\n const currentProductPrice = current.minDisplayPrice.amount;\n\n const nextProductPrice = next.minDisplayPrice.amount;\n\n if (order === SortOrder.Desc) {\n return nextProductPrice - currentProductPrice;\n } else {\n return currentProductPrice - nextProductPrice;\n }\n };\n\n\n/**\n * Sorts products based on the given sort type.\n * @param currentSort - sort type\n * @param sortByWeightTag - if false, then sort by weight tag is\n * ignored (e.g. for `Related Add-ons` where\n * we don't want to sort by weight tag)\n */\nexport const sortProducts = (\n currentSort: Nullish<string | Sort>,\n storeId?: StoreId,\n sortByWeightTag = true,\n ) =>\n (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => {\n switch (currentSort) {\n // Sort by price\n case Sort.HighestPrice:\n case Sort.LowestPrice: {\n return sortByPrice(\n currentSort === Sort.HighestPrice ? SortOrder.Desc : SortOrder.Asc,\n )(current, next);\n }\n\n case Sort.Availability: {\n return sortByAvailabilityDesc(current, next);\n }\n\n default: {\n const sorts = [sortByAvailabilityDesc];\n\n // Add sorting by tag weight\n if (sortByWeightTag) {\n sorts.push(sortByTagWeight(SortSiteId.Store, storeId));\n }\n\n // Do additional sorting by tag weight only after initial sorting resulting in \"same group\"\n return combineSorts(sorts)(current, next);\n }\n }\n };"],"names":["Sort","SortOrder","sortedStatusesByPriorityAsc","DisplayProductStatus","Unavailable","ComingSoon","SoldOut","RegionNotAvailable","Backorder","Available","getProductStatusPriority","product","sortStatus","status","variants","some","variant","availableInOtherStores","length","linkedProducts","linkedProduct","indexOf","sortByAvailabilityDesc","current","next","normalizeSortResult","sortByPrice","order","currentProductPrice","minDisplayPrice","amount","nextProductPrice","sortProducts","currentSort","storeId","sortByWeightTag","sorts","push","sortByTagWeight","SortSiteId","Store","combineSorts"],"mappings":";;;;;AAsBY,IAAAA,IAAA,GAAA,gBAAAA,KAAL,IAAA;EACLA,MAAA,cAAe,CAAA,GAAA,eAAA;EACfA,MAAA,aAAc,CAAA,GAAA,cAAA;EACdA,MAAA,cAAe,CAAA,GAAA,cAAA;EAHLA,OAAAA,KAAAA;AAAA,CAAA,EAAAA,IAAA,IAAA,CAAA,CAAA,CAAA;AAMA,IAAAC,SAAA,GAAA,gBAAAA,UAAL,IAAA;EACLA,WAAA,KAAM,CAAA,GAAA,KAAA;EACNA,WAAA,MAAO,CAAA,GAAA,MAAA;EAFGA,OAAAA,UAAAA;AAAA,CAAA,EAAAA,SAAA,IAAA,CAAA,CAAA,CAAA;AAUL,MAAMC,2BACX,GAAA,CACEC,oBAAqB,CAAAC,WAAA,EACrBD,oBAAqB,CAAAE,UAAA,EACrBF,oBAAqB,CAAAG,OAAA,EACrBH,oBAAqB,CAAAI,kBAAA,EACrBJ,oBAAqB,CAAAK,SAAA,EACrBL,oBAAqB,CAAAM,SAAA,CACvB;AAKF,MAAMC,wBAAA,GACJC,OACW,IAAA;EACX,IAAIC,aAAaD,OAAQ,CAAAE,MAAA;EAGzB,IACEF,OAAQ,CAAAG,QAAA,CAASC,IAAK,CAACC,OAAY,IAAAA,OAAA,CAAQC,sBAAuB,CAAAC,MAAM,CACvE,IAAAP,OAAA,CAAQQ,cACP,IAAAR,OAAA,CAAQQ,cAAe,CAAAJ,IAAA,CACpBK,aAAA,IACCA,aAAc,CAAAP,MAAA,KAAWV,oBAAqB,CAAAM,SAAA,CAEpD,EAAA;IACAG,UAAA,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MAC1C;EACF;AACF,CAAA;"}
@@ -29,6 +29,9 @@ const postalCodeSuperRefinement = ({
29
29
  return zod$1.addCustomZodIssue(ctx, "postalCode", zod$1.CustomZodIssueCode.PostalCode);
30
30
  }
31
31
  switch (country$1) {
32
+ /**
33
+ * We additionally validate that the postal code matches the selected province
34
+ */
32
35
  case generated.CountryCode.Ca:
33
36
  {
34
37
  if (province && postalCode$1) {
@@ -1 +1 @@
1
- {"version":3,"file":"postalCodeSuperRefinement.js","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAAC,OAAA,EAAEA;cAASC,YAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,OAAAA,CAAAA,oBAAqB,CAAAJ,SAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,YAAA,IAAc,CAACA,YAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,UAAAA,CAAAA,wBAAyB,CAAAf,SAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,YAAU,CAAG,EAAA;IACtE,OAAOiB,KAAkB,CAAAA,iBAAA,CAAAf,GAAA,EAAK,YAAc,EAAAgB,KAAA,CAAAA,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,SAAS;IAIf,KAAKqB,SAAAA,CAAAA,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,YAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,aAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,UAAA,CAAAA,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
1
+ {"version":3,"file":"postalCodeSuperRefinement.js","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAAC,OAAA,EAAEA;cAASC,YAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,OAAAA,CAAAA,oBAAqB,CAAAJ,SAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,YAAA,IAAc,CAACA,YAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,UAAAA,CAAAA,wBAAyB,CAAAf,SAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,YAAU,CAAG,EAAA;IACtE,OAAOiB,KAAkB,CAAAA,iBAAA,CAAAf,GAAA,EAAK,YAAc,EAAAgB,KAAA,CAAAA,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,SAAS;IAAA;AAAA;AAAA;IAIf,KAAKqB,SAAAA,CAAAA,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,YAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,aAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,UAAA,CAAAA,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,KAAA,CAAAA,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
@@ -27,6 +27,9 @@ const postalCodeSuperRefinement = ({
27
27
  return addCustomZodIssue(ctx, "postalCode", CustomZodIssueCode.PostalCode);
28
28
  }
29
29
  switch (country) {
30
+ /**
31
+ * We additionally validate that the postal code matches the selected province
32
+ */
30
33
  case CountryCode.Ca:
31
34
  {
32
35
  if (province && postalCode) {
@@ -1 +1 @@
1
- {"version":3,"file":"postalCodeSuperRefinement.mjs","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAEC;EAASC,UAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,oBAAqB,CAAAJ,OAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,UAAA,IAAc,CAACA,UAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,YAAa,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,wBAAyB,CAAAf,OAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,UAAU,CAAG,EAAA;IACtE,OAAOiB,iBAAkB,CAAAf,GAAA,EAAK,YAAc,EAAAgB,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,OAAS;IAIf,KAAKqB,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,UAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,WAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
1
+ {"version":3,"file":"postalCodeSuperRefinement.mjs","sources":["../../../src/utils/validations/postalCodeSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport {\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n COUNTRY_CODE_POSTAL_CODE,\n} from \"../../constants/postalCode\";\nimport { CountryCode } from \"../../types\";\nimport type { Nullish } from \"../../types\";\nimport { countryHasPostalCode } from \"../country\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\n/**\n * Validate Postal Code (based on other address fields - country/province)\n * - If country requires postal code, validate postal code\n * - If country does not require postal code, ignore\n * - If country requires postal code, but no postal code, error\n * - If country requires postal code, but invalid postal code, error\n */\nexport const postalCodeSuperRefinement: SuperRefinement<{\n country: CountryCode;\n postalCode?: Nullish<string>;\n province?: Nullish<string>;\n}> = ({ country, postalCode, province }, ctx) => {\n /**\n * Exit early for countries that do not need validation\n */\n if (!countryHasPostalCode(country)) {\n return;\n }\n\n /**\n * First check if postal code is missing for countries that require it\n * Return short length error\n */\n if (!postalCode || !postalCode?.length) {\n return ctx.addIssue({\n path: [\"postalCode\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n /**\n * If there is, validate country against provided postal code regex\n */\n const countryPostalCodeRegex = COUNTRY_CODE_POSTAL_CODE[country]?.regex;\n if (countryPostalCodeRegex && !countryPostalCodeRegex.test(postalCode)) {\n return addCustomZodIssue(ctx, \"postalCode\", CustomZodIssueCode.PostalCode);\n }\n\n /**\n * Extra validations there might be per country regarding postal code\n */\n switch (country) {\n /**\n * We additionally validate that the postal code matches the selected province\n */\n case CountryCode.Ca: {\n if (province && postalCode) {\n const firstPostalCodeChar = postalCode[0];\n if (!firstPostalCodeChar) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n\n const validRegionPostalCode = Object.entries(\n CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER,\n ).some(\n ([character, provinceCodes]) =>\n character.toUpperCase() === firstPostalCodeChar.toUpperCase() &&\n provinceCodes.includes(province),\n );\n\n if (!validRegionPostalCode) {\n return addCustomZodIssue(\n ctx,\n \"postalCode\",\n CustomZodIssueCode.PostalCode,\n );\n }\n }\n\n break;\n }\n default:\n break;\n }\n};\n"],"names":["postalCodeSuperRefinement","country","postalCode","province","ctx","countryHasPostalCode","length","addIssue","path","code","ZodIssueCode","too_small","type","minimum","inclusive","countryPostalCodeRegex","COUNTRY_CODE_POSTAL_CODE","regex","test","addCustomZodIssue","CustomZodIssueCode","PostalCode","CountryCode","Ca","firstPostalCodeChar","validRegionPostalCode","Object","entries","CA_POSTAL_CODE_PROVINCE_FIRST_CHARACTER","some","character","provinceCodes","toUpperCase","includes"],"mappings":";;;;;;;AAmBO,MAAMA,4BAIRA,CAAC;EAAEC;EAASC,UAAY;EAAAC;AAAA,GAAYC,GAAQ,KAAA;EAI3C,IAAA,CAACC,oBAAqB,CAAAJ,OAAO,CAAG,EAAA;IAClC;EACF;EAMA,IAAI,CAACC,UAAA,IAAc,CAACA,UAAA,EAAYI,MAAQ,EAAA;IACtC,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,YAAY,CAAA;MACnBC,MAAMC,YAAa,CAAAC,SAAA;MACnBC,IAAM,EAAA,QAAA;MACNC,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAKM,MAAAC,sBAAA,GAAyBC,wBAAyB,CAAAf,OAAO,CAAG,EAAAgB,KAAA;EAClE,IAAIF,sBAA0B,IAAA,CAACA,sBAAuB,CAAAG,IAAA,CAAKhB,UAAU,CAAG,EAAA;IACtE,OAAOiB,iBAAkB,CAAAf,GAAA,EAAK,YAAc,EAAAgB,kBAAA,CAAmBC,UAAU,CAAA;EAC3E;EAKA,QAAQpB,OAAS;IAAA;AAAA;AAAA;IAIf,KAAKqB,YAAYC,EAAI;MAAA;QACnB,IAAIpB,YAAYD,UAAY,EAAA;UACpB,MAAAsB,mBAAA,GAAsBtB,WAAW,CAAC,CAAA;UACxC,IAAI,CAACsB,mBAAqB,EAAA;YACjB,OAAAL,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;UAEA,MAAMI,wBAAwBC,MAAO,CAAAC,OAAA,CACnCC,uCAAA,CACA,CAAAC,IAAA,CACA,CAAC,CAACC,SAAW,EAAAC,aAAa,CACxB,KAAAD,SAAA,CAAUE,WAAY,CAAA,CAAA,KAAMR,mBAAoB,CAAAQ,WAAA,CAChD,CAAA,IAAAD,aAAA,CAAcE,SAAS9B,QAAQ,CAAA,CACnC;UAEA,IAAI,CAACsB,qBAAuB,EAAA;YACnB,OAAAN,iBAAA,CACLf,GAAA,EACA,YAAA,EACAgB,kBAAmB,CAAAC,UAAA,CACrB;UACF;QACF;QAEA;MACF;IACA;MACE;EACJ;AACF,CAAA;"}
@@ -17,8 +17,10 @@ const createStateRegistrationNumberSuperRefinement = ({
17
17
  type
18
18
  }, ctx) => {
19
19
  switch (addressUsageType) {
20
+ // Exit early because state registration number is generally not needed for billing addresses.
20
21
  case constants.AddressUsageType.Billing:
21
22
  return;
23
+ // Don't do anything and proceed with the validation logic below.
22
24
  case constants.AddressUsageType.ReturnShipping:
23
25
  case constants.AddressUsageType.Shipping:
24
26
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"stateRegistrationNumberSuperRefinement.js","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAExB,KAAKK,SAAiB,CAAAA,gBAAA,CAAAC,OAAA;MACpB;IAEF,KAAKD,SAAAA,CAAAA,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,SAAiB,CAAAA,gBAAA,CAAAG,QAAA;MACpB;IACF;MACEC,MAAA,CAAAA,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,qBAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,SAAAA,CAAAA,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,KAAA,CAAAA,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;;"}
1
+ {"version":3,"file":"stateRegistrationNumberSuperRefinement.js","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAAA;IAExB,KAAKK,SAAiB,CAAAA,gBAAA,CAAAC,OAAA;MACpB;IAAA;IAEF,KAAKD,SAAAA,CAAAA,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,SAAiB,CAAAA,gBAAA,CAAAG,QAAA;MACpB;IACF;MACEC,MAAA,CAAAA,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,qBAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,SAAAA,CAAAA,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,GAAa,CAAAA,YAAA,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,KAAA,CAAAA,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,KAAAA,CAAAA,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;;"}
@@ -15,8 +15,10 @@ const createStateRegistrationNumberSuperRefinement = ({
15
15
  type
16
16
  }, ctx) => {
17
17
  switch (addressUsageType) {
18
+ // Exit early because state registration number is generally not needed for billing addresses.
18
19
  case AddressUsageType.Billing:
19
20
  return;
21
+ // Don't do anything and proceed with the validation logic below.
20
22
  case AddressUsageType.ReturnShipping:
21
23
  case AddressUsageType.Shipping:
22
24
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"stateRegistrationNumberSuperRefinement.mjs","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAExB,KAAKK,gBAAiB,CAAAC,OAAA;MACpB;IAEF,KAAKD,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,gBAAiB,CAAAG,QAAA;MACpB;IACF;MACEC,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,WAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,YAAa,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;"}
1
+ {"version":3,"file":"stateRegistrationNumberSuperRefinement.mjs","sources":["../../../src/utils/validations/stateRegistrationNumberSuperRefinement.ts"],"sourcesContent":["import { type SuperRefinement, ZodIssueCode } from \"zod\";\n\nimport type { Nullish } from \"../../types\";\nimport { AddressType, AddressUsageType, CountryCode } from \"../../types\";\nimport { assertUnreachable } from \"../errors\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport const EXEMPTED = \"EXEMPTED\";\nconst IS_DIGITS_ONLY_REGEX = /^\\d+$/;\n\nexport const createStateRegistrationNumberSuperRefinement =\n ({\n addressUsageType,\n }: {\n addressUsageType: AddressUsageType;\n }): SuperRefinement<{\n stateRegistrationNumber?: Nullish<string>;\n country: CountryCode;\n type: AddressType;\n }> =>\n ({ stateRegistrationNumber, country, type }, ctx) => {\n switch (addressUsageType) {\n // Exit early because state registration number is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n // Only relevant for Brazil business addresses.\n if (!(country === CountryCode.Br && type === AddressType.Business)) {\n return;\n }\n\n // Exempted state registration numbers are valid.\n if (stateRegistrationNumber === EXEMPTED) {\n return;\n }\n\n // Handle cases when the value is too small.\n if (!stateRegistrationNumber?.length) {\n return ctx.addIssue({\n path: [\"stateRegistrationNumber\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n // It should be only digits.\n if (!IS_DIGITS_ONLY_REGEX.test(stateRegistrationNumber)) {\n return addCustomZodIssue(\n ctx,\n \"stateRegistrationNumber\",\n CustomZodIssueCode.DigitsOnly,\n );\n }\n };\n"],"names":["EXEMPTED","IS_DIGITS_ONLY_REGEX","createStateRegistrationNumberSuperRefinement","addressUsageType","stateRegistrationNumber","country","type","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","CountryCode","Br","AddressType","Business","length","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","test","addCustomZodIssue","CustomZodIssueCode","DigitsOnly"],"mappings":";;;;;;;AAOO,MAAMA,QAAW,GAAA,UAAA;AACxB,MAAMC,oBAAuB,GAAA,OAAA;AAEtB,MAAMC,+CACXA,CAAC;EACCC;AACF,CAAA,KAOA,CAAC;EAAEC,uBAAA;EAAyBC,OAAS;EAAAC;AAAA,GAAQC,GAAQ,KAAA;EACnD,QAAQJ,gBAAkB;IAAA;IAExB,KAAKK,gBAAiB,CAAAC,OAAA;MACpB;IAAA;IAEF,KAAKD,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,gBAAiB,CAAAG,QAAA;MACpB;IACF;MACEC,iBAAA,CAAkBT,gBAAgB,CAAA;EACtC;EAGA,IAAI,EAAEE,OAAY,KAAAQ,WAAA,CAAYC,EAAM,IAAAR,IAAA,KAASS,YAAYC,QAAW,CAAA,EAAA;IAClE;EACF;EAGA,IAAIZ,4BAA4BJ,QAAU,EAAA;IACxC;EACF;EAGI,IAAA,CAACI,yBAAyBa,MAAQ,EAAA;IACpC,OAAOV,IAAIW,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,yBAAyB,CAAA;MAChCC,MAAMC,YAAa,CAAAC,SAAA;MACnBhB,IAAM,EAAA,QAAA;MACNiB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAGA,IAAI,CAACvB,oBAAA,CAAqBwB,IAAK,CAAArB,uBAAuB,CAAG,EAAA;IAChD,OAAAsB,iBAAA,CACLnB,GAAA,EACA,yBAAA,EACAoB,kBAAmB,CAAAC,UAAA,CACrB;EACF;AACF,CAAA;"}
@@ -19,8 +19,10 @@ const createTaxIdSuperRefinement = ({
19
19
  taxId
20
20
  }, ctx) => {
21
21
  switch (addressUsageType) {
22
+ // Exit early because tax ID is generally not needed for billing addresses.
22
23
  case constants.AddressUsageType.Billing:
23
24
  return;
25
+ // Don't do anything and proceed with the validation logic below.
24
26
  case constants.AddressUsageType.ReturnShipping:
25
27
  case constants.AddressUsageType.Shipping:
26
28
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"taxIdSuperRefinement.js","sources":["../../../src/utils/validations/taxIdSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport type { AddressType, CountryCode, Nullish } from \"../../types\";\nimport { AddressUsageType, ValidateTaxStatus } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport {\n getTaxCountry,\n getTaxLabelTypeByCountry,\n getValidationMappingByType,\n hasTaxNumberPatternValidation,\n isValidTaxNumberPattern,\n} from \"../tax\";\nimport { TaxLabelType } from \"../tax/types\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport type ValidateTaxIdExternally = (opts: {\n type: AddressType;\n countryCode: CountryCode;\n province: Nullish<string>;\n taxId: string;\n}) => Promise<Nullish<ValidateTaxStatus>>;\n\nexport const createTaxIdSuperRefinement =\n ({\n addressUsageType,\n validateTaxIdExternally,\n }: {\n addressUsageType: AddressUsageType;\n validateTaxIdExternally?: ValidateTaxIdExternally;\n }): SuperRefinement<{\n type: AddressType;\n country: CountryCode;\n province?: Nullish<string>;\n taxId?: Nullish<string>;\n }> =>\n async ({ type, country, province, taxId }, ctx) => {\n switch (addressUsageType) {\n // Exit early because tax ID is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n const taxCountryCode = getTaxCountry({\n country,\n province,\n });\n\n // Doesn't require strict validation\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n if (!taxId && isOptional) {\n return;\n }\n\n // Ensure that we have tax ID before passing it to the validation\n if (!taxId) {\n return ctx.addIssue({\n path: [\"taxId\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n const taxLabelType = getTaxLabelTypeByCountry(country, {\n type: \"specific\",\n addressType: type,\n });\n const shouldUppercaseTaxLabel = [\n TaxLabelType.Gst,\n TaxLabelType.Vat,\n TaxLabelType.Cpf,\n TaxLabelType.Cnpj,\n ].includes(taxLabelType);\n const label = shouldUppercaseTaxLabel\n ? taxLabelType.toUpperCase()\n : taxLabelType;\n\n // If the pattern is invalid, error\n if (!isValidTaxNumberPattern(type, taxCountryCode, taxId)) {\n return addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxFormat, {\n label,\n });\n }\n\n if (!validateTaxIdExternally) {\n return;\n }\n\n // Additionally validate tax id externally depending on environment\n const taxStatus = await validateTaxIdExternally({\n type,\n countryCode: country,\n province,\n taxId,\n });\n\n switch (taxStatus) {\n case ValidateTaxStatus.Invalid: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxInvalid, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Unavailable: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxUnavailable, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Valid:\n case ValidateTaxStatus.NotValidated:\n case null:\n case undefined: {\n // Do nothing;\n break;\n }\n\n default: {\n // Do nothing as well (but in a type safe way)\n checkUnreachable(taxStatus);\n }\n }\n };\n"],"names":["createTaxIdSuperRefinement","addressUsageType","validateTaxIdExternally","type","country","province","taxId","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","taxCountryCode","getTaxCountry","hasTaxNumberPatternValidation","mapping","getValidationMappingByType","isOptional","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","taxLabelType","getTaxLabelTypeByCountry","addressType","shouldUppercaseTaxLabel","TaxLabelType","Gst","Vat","Cpf","Cnpj","includes","label","toUpperCase","isValidTaxNumberPattern","addCustomZodIssue","CustomZodIssueCode","TaxFormat","taxStatus","countryCode","ValidateTaxStatus","Invalid","TaxInvalid","Unavailable","TaxUnavailable","Valid","NotValidated","checkUnreachable"],"mappings":";;;;;;;;;;;AAuBO,MAAMA,6BACXA,CAAC;EACCC,gBAAA;EACAC;AACF,CAAA,KASA,OAAO;EAAE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AAA,GACVH,YAAa,CAAAW,WAAA,CAAA,CACb,GAAAX,YAAA;EAGJ,IAAI,CAACY,KAAAA,CAAAA,uBAAA,CAAwBnC,IAAM,EAAAU,cAAA,EAAgBP,KAAK,CAAG,EAAA;IACzD,OAAOiC,KAAkB,CAAAA,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,KAAAA,CAAAA,kBAAA,CAAmBC,SAAW,EAAA;MACnEL;IAAA,CACD,CAAA;EACH;EAEA,IAAI,CAAClC,uBAAyB,EAAA;IAC5B;EACF;EAGM,MAAAwC,SAAA,GAAY,MAAMxC,uBAAwB,CAAA;IAC9CC,IAAA;IACAwC,WAAa,EAAAvC,OAAA;IACbC,QAAA;IACAC;EAAA,CACD,CAAA;EAED,QAAQoC,SAAW;IACjB,KAAKE,SAAAA,CAAAA,kBAAkBC,OAAS;MAAA;QACZN,KAAAA,CAAAA,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,KAAAA,CAAAA,kBAAA,CAAmBM,UAAY,EAAA;UAC7DV;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,SAAAA,CAAAA,kBAAkBG,WAAa;MAAA;QAChBR,KAAAA,CAAAA,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,KAAAA,CAAAA,kBAAA,CAAmBQ,cAAgB,EAAA;UACjEZ;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,SAAAA,CAAAA,iBAAkB,CAAAK,KAAA;IACvB,KAAKL,SAAAA,CAAAA,iBAAkB,CAAAM,YAAA;IACvB,KAAK,IAAA;IACL,KAAK,KAAW,CAAA;MAAA;QAEd;MACF;IAEA;MAAS;QAEPC,MAAA,CAAAA,gBAAA,CAAiBT,SAAS,CAAA;MAC5B;EACF;AACF,CAAA;"}
1
+ {"version":3,"file":"taxIdSuperRefinement.js","sources":["../../../src/utils/validations/taxIdSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport type { AddressType, CountryCode, Nullish } from \"../../types\";\nimport { AddressUsageType, ValidateTaxStatus } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport {\n getTaxCountry,\n getTaxLabelTypeByCountry,\n getValidationMappingByType,\n hasTaxNumberPatternValidation,\n isValidTaxNumberPattern,\n} from \"../tax\";\nimport { TaxLabelType } from \"../tax/types\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport type ValidateTaxIdExternally = (opts: {\n type: AddressType;\n countryCode: CountryCode;\n province: Nullish<string>;\n taxId: string;\n}) => Promise<Nullish<ValidateTaxStatus>>;\n\nexport const createTaxIdSuperRefinement =\n ({\n addressUsageType,\n validateTaxIdExternally,\n }: {\n addressUsageType: AddressUsageType;\n validateTaxIdExternally?: ValidateTaxIdExternally;\n }): SuperRefinement<{\n type: AddressType;\n country: CountryCode;\n province?: Nullish<string>;\n taxId?: Nullish<string>;\n }> =>\n async ({ type, country, province, taxId }, ctx) => {\n switch (addressUsageType) {\n // Exit early because tax ID is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n const taxCountryCode = getTaxCountry({\n country,\n province,\n });\n\n // Doesn't require strict validation\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n if (!taxId && isOptional) {\n return;\n }\n\n // Ensure that we have tax ID before passing it to the validation\n if (!taxId) {\n return ctx.addIssue({\n path: [\"taxId\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n const taxLabelType = getTaxLabelTypeByCountry(country, {\n type: \"specific\",\n addressType: type,\n });\n const shouldUppercaseTaxLabel = [\n TaxLabelType.Gst,\n TaxLabelType.Vat,\n TaxLabelType.Cpf,\n TaxLabelType.Cnpj,\n ].includes(taxLabelType);\n const label = shouldUppercaseTaxLabel\n ? taxLabelType.toUpperCase()\n : taxLabelType;\n\n // If the pattern is invalid, error\n if (!isValidTaxNumberPattern(type, taxCountryCode, taxId)) {\n return addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxFormat, {\n label,\n });\n }\n\n if (!validateTaxIdExternally) {\n return;\n }\n\n // Additionally validate tax id externally depending on environment\n const taxStatus = await validateTaxIdExternally({\n type,\n countryCode: country,\n province,\n taxId,\n });\n\n switch (taxStatus) {\n case ValidateTaxStatus.Invalid: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxInvalid, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Unavailable: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxUnavailable, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Valid:\n case ValidateTaxStatus.NotValidated:\n case null:\n case undefined: {\n // Do nothing;\n break;\n }\n\n default: {\n // Do nothing as well (but in a type safe way)\n checkUnreachable(taxStatus);\n }\n }\n };\n"],"names":["createTaxIdSuperRefinement","addressUsageType","validateTaxIdExternally","type","country","province","taxId","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","taxCountryCode","getTaxCountry","hasTaxNumberPatternValidation","mapping","getValidationMappingByType","isOptional","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","taxLabelType","getTaxLabelTypeByCountry","addressType","shouldUppercaseTaxLabel","TaxLabelType","Gst","Vat","Cpf","Cnpj","includes","label","toUpperCase","isValidTaxNumberPattern","addCustomZodIssue","CustomZodIssueCode","TaxFormat","taxStatus","countryCode","ValidateTaxStatus","Invalid","TaxInvalid","Unavailable","TaxUnavailable","Valid","NotValidated","checkUnreachable"],"mappings":";;;;;;;;;;;AAuBO,MAAMA,6BACXA,CAAC;EACCC,gBAAA;EACAC;AACF,CAAA,KASA,OAAO;EAAEC,IAAA;EA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BAAA,GACVH,YAAa,CAAAW,WAAA,CAAA,CACb,GAAAX,YAAA;EAGJ,IAAI,CAACY,KAAAA,CAAAA,uBAAA,CAAwBnC,IAAM,EAAAU,cAAA,EAAgBP,KAAK,CAAG,EAAA;IACzD,OAAOiC,KAAkB,CAAAA,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,KAAAA,CAAAA,kBAAA,CAAmBC,SAAW,EAAA;MACnEL;IAAA,CACD,CAAA;EACH;EAEA,IAAI,CAAClC,uBAAyB,EAAA;IAC5B;EACF;EAGM,MAAAwC,SAAA,GAAY,MAAMxC,uBAAwB,CAAA;IAC9CC,IAAA;IACAwC,WAAa,EAAAvC,OAAA;IACbC,QAAA;IACAC;EAAA,CACD,CAAA;EAED,QAAQoC,SAAW;IACjB,KAAKE,SAAAA,CAAAA,kBAAkBC,OAAS;MAAA;QACZN,KAAAA,CAAAA,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,KAAAA,CAAAA,kBAAA,CAAmBM,UAAY,EAAA;UAC7DV;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,SAAAA,CAAAA,kBAAkBG,WAAa;MAAA;QAChBR,KAAAA,CAAAA,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,KAAAA,CAAAA,kBAAA,CAAmBQ,cAAgB,EAAA;UACjEZ;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,SAAAA,CAAAA,iBAAkB,CAAAK,KAAA;IACvB,KAAKL,SAAAA,CAAAA,iBAAkB,CAAAM,YAAA;IACvB,KAAK,IAAA;IACL,KAAK,KAAW,CAAA;MAAA;QAEd;MACF;IAEA;MAAS;QAEPC,MAAA,CAAAA,gBAAA,CAAiBT,SAAS,CAAA;MAC5B;EACF;AACF,CAAA;"}
@@ -17,8 +17,10 @@ const createTaxIdSuperRefinement = ({
17
17
  taxId
18
18
  }, ctx) => {
19
19
  switch (addressUsageType) {
20
+ // Exit early because tax ID is generally not needed for billing addresses.
20
21
  case AddressUsageType.Billing:
21
22
  return;
23
+ // Don't do anything and proceed with the validation logic below.
22
24
  case AddressUsageType.ReturnShipping:
23
25
  case AddressUsageType.Shipping:
24
26
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"taxIdSuperRefinement.mjs","sources":["../../../src/utils/validations/taxIdSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport type { AddressType, CountryCode, Nullish } from \"../../types\";\nimport { AddressUsageType, ValidateTaxStatus } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport {\n getTaxCountry,\n getTaxLabelTypeByCountry,\n getValidationMappingByType,\n hasTaxNumberPatternValidation,\n isValidTaxNumberPattern,\n} from \"../tax\";\nimport { TaxLabelType } from \"../tax/types\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport type ValidateTaxIdExternally = (opts: {\n type: AddressType;\n countryCode: CountryCode;\n province: Nullish<string>;\n taxId: string;\n}) => Promise<Nullish<ValidateTaxStatus>>;\n\nexport const createTaxIdSuperRefinement =\n ({\n addressUsageType,\n validateTaxIdExternally,\n }: {\n addressUsageType: AddressUsageType;\n validateTaxIdExternally?: ValidateTaxIdExternally;\n }): SuperRefinement<{\n type: AddressType;\n country: CountryCode;\n province?: Nullish<string>;\n taxId?: Nullish<string>;\n }> =>\n async ({ type, country, province, taxId }, ctx) => {\n switch (addressUsageType) {\n // Exit early because tax ID is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n const taxCountryCode = getTaxCountry({\n country,\n province,\n });\n\n // Doesn't require strict validation\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n if (!taxId && isOptional) {\n return;\n }\n\n // Ensure that we have tax ID before passing it to the validation\n if (!taxId) {\n return ctx.addIssue({\n path: [\"taxId\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n const taxLabelType = getTaxLabelTypeByCountry(country, {\n type: \"specific\",\n addressType: type,\n });\n const shouldUppercaseTaxLabel = [\n TaxLabelType.Gst,\n TaxLabelType.Vat,\n TaxLabelType.Cpf,\n TaxLabelType.Cnpj,\n ].includes(taxLabelType);\n const label = shouldUppercaseTaxLabel\n ? taxLabelType.toUpperCase()\n : taxLabelType;\n\n // If the pattern is invalid, error\n if (!isValidTaxNumberPattern(type, taxCountryCode, taxId)) {\n return addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxFormat, {\n label,\n });\n }\n\n if (!validateTaxIdExternally) {\n return;\n }\n\n // Additionally validate tax id externally depending on environment\n const taxStatus = await validateTaxIdExternally({\n type,\n countryCode: country,\n province,\n taxId,\n });\n\n switch (taxStatus) {\n case ValidateTaxStatus.Invalid: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxInvalid, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Unavailable: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxUnavailable, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Valid:\n case ValidateTaxStatus.NotValidated:\n case null:\n case undefined: {\n // Do nothing;\n break;\n }\n\n default: {\n // Do nothing as well (but in a type safe way)\n checkUnreachable(taxStatus);\n }\n }\n };\n"],"names":["createTaxIdSuperRefinement","addressUsageType","validateTaxIdExternally","type","country","province","taxId","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","taxCountryCode","getTaxCountry","hasTaxNumberPatternValidation","mapping","getValidationMappingByType","isOptional","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","taxLabelType","getTaxLabelTypeByCountry","addressType","shouldUppercaseTaxLabel","TaxLabelType","Gst","Vat","Cpf","Cnpj","includes","label","toUpperCase","isValidTaxNumberPattern","addCustomZodIssue","CustomZodIssueCode","TaxFormat","taxStatus","countryCode","ValidateTaxStatus","Invalid","TaxInvalid","Unavailable","TaxUnavailable","Valid","NotValidated","checkUnreachable"],"mappings":";;;;;;;;;AAuBO,MAAMA,6BACXA,CAAC;EACCC,gBAAA;EACAC;AACF,CAAA,KASA,OAAO;EAAEC,IAAA;EAAMC;EAASC,QAAU;EAAAC;GAASC,GAAQ,KAAA;EACjD,QAAQN,gBAAkB;IAExB,KAAKO,gBAAiB,CAAAC,OAAA;MACpB;IAEF,KAAKD,gBAAiB,CAAAE,cAAA;IACtB,KAAKF,gBAAiB,CAAAG,QAAA;MACpB;IACF;MACEC,iBAAA,CAAkBX,gBAAgB,CAAA;EACtC;EAEA,MAAMY,iBAAiBC,aAAc,CAAA;IACnCV,OAAA;IACAC;EAAA,CACD,CAAA;EAGD,IAAI,CAACU,6BAAA,CAA8BZ,IAAM,EAAAU,cAAc,CAAG,EAAA;IACxD;EACF;EAEM,MAAAG,OAAA,GAAUC,2BAA2Bd,IAAI,CAAA;EAC/C,MAAM;IAAEe;EAAA,CAAe,GAAAF,OAAA,CAAQH,cAAc,CAAA;EAEzC,IAAA,CAACP,SAASY,UAAY,EAAA;IACxB;EACF;EAGA,IAAI,CAACZ,KAAO,EAAA;IACV,OAAOC,IAAIY,QAAS,CAAA;MAClBC,IAAA,EAAM,CAAC,OAAO,CAAA;MACdC,MAAMC,YAAa,CAAAC,SAAA;MACnBpB,IAAM,EAAA,QAAA;MACNqB,OAAS,EAAA,CAAA;MACTC,SAAW,EAAA;IAAA,CACZ,CAAA;EACH;EAEM,MAAAC,YAAA,GAAeC,yBAAyBvB,OAAS,EAAA;IACrDD,IAAM,EAAA,UAAA;IACNyB,WAAa,EAAAzB;EAAA,CACd,CAAA;EACD,MAAM0B,uBAA0B,GAAA,CAC9BC,YAAa,CAAAC,GAAA,EACbD,YAAa,CAAAE,GAAA,EACbF,YAAa,CAAAG,GAAA,EACbH,YAAa,CAAAI,IAAA,CACf,CAAEC,SAAST,YAAY,CAAA;EACvB,MAAMU,KAAQ,GAAAP,uBAAA,GACVH,YAAa,CAAAW,WAAA,CAAA,CACb,GAAAX,YAAA;EAGJ,IAAI,CAACY,uBAAA,CAAwBnC,IAAM,EAAAU,cAAA,EAAgBP,KAAK,CAAG,EAAA;IACzD,OAAOiC,iBAAkB,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,kBAAA,CAAmBC,SAAW,EAAA;MACnEL;IAAA,CACD,CAAA;EACH;EAEA,IAAI,CAAClC,uBAAyB,EAAA;IAC5B;EACF;EAGM,MAAAwC,SAAA,GAAY,MAAMxC,uBAAwB,CAAA;IAC9CC,IAAA;IACAwC,WAAa,EAAAvC,OAAA;IACbC,QAAA;IACAC;EAAA,CACD,CAAA;EAED,QAAQoC,SAAW;IACjB,KAAKE,kBAAkBC,OAAS;MAAA;QACZN,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,kBAAA,CAAmBM,UAAY,EAAA;UAC7DV;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,kBAAkBG,WAAa;MAAA;QAChBR,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,kBAAA,CAAmBQ,cAAgB,EAAA;UACjEZ;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,iBAAkB,CAAAK,KAAA;IACvB,KAAKL,iBAAkB,CAAAM,YAAA;IACvB,KAAK,IAAA;IACL,KAAK,KAAW,CAAA;MAAA;QAEd;MACF;IAEA;MAAS;QAEPC,gBAAA,CAAiBT,SAAS,CAAA;MAC5B;EACF;AACF,CAAA;"}
1
+ {"version":3,"file":"taxIdSuperRefinement.mjs","sources":["../../../src/utils/validations/taxIdSuperRefinement.ts"],"sourcesContent":["import type { SuperRefinement } from \"zod\";\nimport { ZodIssueCode } from \"zod\";\n\nimport type { AddressType, CountryCode, Nullish } from \"../../types\";\nimport { AddressUsageType, ValidateTaxStatus } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport {\n getTaxCountry,\n getTaxLabelTypeByCountry,\n getValidationMappingByType,\n hasTaxNumberPatternValidation,\n isValidTaxNumberPattern,\n} from \"../tax\";\nimport { TaxLabelType } from \"../tax/types\";\nimport { addCustomZodIssue, CustomZodIssueCode } from \"../zod\";\n\nexport type ValidateTaxIdExternally = (opts: {\n type: AddressType;\n countryCode: CountryCode;\n province: Nullish<string>;\n taxId: string;\n}) => Promise<Nullish<ValidateTaxStatus>>;\n\nexport const createTaxIdSuperRefinement =\n ({\n addressUsageType,\n validateTaxIdExternally,\n }: {\n addressUsageType: AddressUsageType;\n validateTaxIdExternally?: ValidateTaxIdExternally;\n }): SuperRefinement<{\n type: AddressType;\n country: CountryCode;\n province?: Nullish<string>;\n taxId?: Nullish<string>;\n }> =>\n async ({ type, country, province, taxId }, ctx) => {\n switch (addressUsageType) {\n // Exit early because tax ID is generally not needed for billing addresses.\n case AddressUsageType.Billing:\n return;\n // Don't do anything and proceed with the validation logic below.\n case AddressUsageType.ReturnShipping:\n case AddressUsageType.Shipping:\n break;\n default:\n assertUnreachable(addressUsageType);\n }\n\n const taxCountryCode = getTaxCountry({\n country,\n province,\n });\n\n // Doesn't require strict validation\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n if (!taxId && isOptional) {\n return;\n }\n\n // Ensure that we have tax ID before passing it to the validation\n if (!taxId) {\n return ctx.addIssue({\n path: [\"taxId\"],\n code: ZodIssueCode.too_small,\n type: \"string\",\n minimum: 1,\n inclusive: true,\n });\n }\n\n const taxLabelType = getTaxLabelTypeByCountry(country, {\n type: \"specific\",\n addressType: type,\n });\n const shouldUppercaseTaxLabel = [\n TaxLabelType.Gst,\n TaxLabelType.Vat,\n TaxLabelType.Cpf,\n TaxLabelType.Cnpj,\n ].includes(taxLabelType);\n const label = shouldUppercaseTaxLabel\n ? taxLabelType.toUpperCase()\n : taxLabelType;\n\n // If the pattern is invalid, error\n if (!isValidTaxNumberPattern(type, taxCountryCode, taxId)) {\n return addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxFormat, {\n label,\n });\n }\n\n if (!validateTaxIdExternally) {\n return;\n }\n\n // Additionally validate tax id externally depending on environment\n const taxStatus = await validateTaxIdExternally({\n type,\n countryCode: country,\n province,\n taxId,\n });\n\n switch (taxStatus) {\n case ValidateTaxStatus.Invalid: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxInvalid, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Unavailable: {\n addCustomZodIssue(ctx, \"taxId\", CustomZodIssueCode.TaxUnavailable, {\n label,\n });\n break;\n }\n\n case ValidateTaxStatus.Valid:\n case ValidateTaxStatus.NotValidated:\n case null:\n case undefined: {\n // Do nothing;\n break;\n }\n\n default: {\n // Do nothing as well (but in a type safe way)\n checkUnreachable(taxStatus);\n }\n }\n };\n"],"names":["createTaxIdSuperRefinement","addressUsageType","validateTaxIdExternally","type","country","province","taxId","ctx","AddressUsageType","Billing","ReturnShipping","Shipping","assertUnreachable","taxCountryCode","getTaxCountry","hasTaxNumberPatternValidation","mapping","getValidationMappingByType","isOptional","addIssue","path","code","ZodIssueCode","too_small","minimum","inclusive","taxLabelType","getTaxLabelTypeByCountry","addressType","shouldUppercaseTaxLabel","TaxLabelType","Gst","Vat","Cpf","Cnpj","includes","label","toUpperCase","isValidTaxNumberPattern","addCustomZodIssue","CustomZodIssueCode","TaxFormat","taxStatus","countryCode","ValidateTaxStatus","Invalid","TaxInvalid","Unavailable","TaxUnavailable","Valid","NotValidated","checkUnreachable"],"mappings":";;;;;;;;;AAuBO,MAAMA,6BACXA,CAAC;EACCC,gBAAA;EACAC;AACF,CAAA,KASA,OAAO;EAAEC,IAAA;EAAMC;EAASC,QAAU;EAAAC;GAASC,GAAQ,KAAA;EACjD,QAAQN,gBAAkB;IAAA;IAEx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L;IAAA,CACD,CAAA;EACH;EAEA,IAAI,CAAClC,uBAAyB,EAAA;IAC5B;EACF;EAGM,MAAAwC,SAAA,GAAY,MAAMxC,uBAAwB,CAAA;IAC9CC,IAAA;IACAwC,WAAa,EAAAvC,OAAA;IACbC,QAAA;IACAC;EAAA,CACD,CAAA;EAED,QAAQoC,SAAW;IACjB,KAAKE,kBAAkBC,OAAS;MAAA;QACZN,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,kBAAA,CAAmBM,UAAY,EAAA;UAC7DV;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,kBAAkBG,WAAa;MAAA;QAChBR,iBAAA,CAAAhC,GAAA,EAAK,OAAS,EAAAiC,kBAAA,CAAmBQ,cAAgB,EAAA;UACjEZ;QAAA,CACD,CAAA;QACD;MACF;IAEA,KAAKQ,iBAAkB,CAAAK,KAAA;IACvB,KAAKL,iBAAkB,CAAAM,YAAA;IACvB,KAAK,IAAA;IACL,KAAK,KAAW,CAAA;MAAA;QAEd;MACF;IAEA;MAAS;QAEPC,gBAAA,CAAiBT,SAAS,CAAA;MAC5B;EACF;AACF,CAAA;"}
@@ -1 +1 @@
1
- {"version":3,"file":"variant.js","sources":["../../src/utils/variant.ts"],"sourcesContent":["/**\n * Removes the regional (and other) SKU postfix from the SKU.\n */\n\nconst REGIONAL_SKU_POSTFIX = [\n \" EU\",\n \"-EU\",\n \"(EU)\",\n \" US\",\n \"(US)\",\n \"-US\",\n \"-BR\",\n \"-CN\",\n \"-TW\",\n \"-JP\",\n \"-AU\",\n \"-AR\",\n \"-UK\",\n \"-U\",\n \"-IND\",\n \"-Standalone\",\n];\n\nexport const removeRegionalSkuPostfix = (sku?: string) => {\n const trimmedSku = sku?.trim();\n\n if (!trimmedSku) return undefined;\n\n const postfix = REGIONAL_SKU_POSTFIX.find((postfix) =>\n trimmedSku.trim().toUpperCase().endsWith(postfix.toUpperCase()),\n );\n\n if (!postfix) return trimmedSku;\n\n return trimmedSku.slice(0, -postfix.length).trim();\n};\n\n/**\n * Returns the SKU text with the extra label if it exists.\n */\nexport const getSkuText = (sku?: string, extraLabel?: string) => {\n if (!sku) return undefined;\n\n const preparedSku = removeRegionalSkuPostfix(sku);\n\n if (!extraLabel) return preparedSku;\n\n return `${preparedSku} (${extraLabel})`;\n};\n"],"names":["REGIONAL_SKU_POSTFIX","removeRegionalSkuPostfix","sku","trimmedSku","trim","postfix","find","toUpperCase","endsWith","slice","length","getSkuText","extraLabel","preparedSku"],"mappings":";;;AAIA,MAAMA,oBAAuB,GAAA,CAC3B,KAAA,EACA,KAAA,EACA,MAAA,EACA,KAAA,EACA,MAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,IAAA,EACA,MAAA,EACA,aAAA,CACF;AAEa,MAAAC,wBAAA,GAA4BC,GAAiB,IAAA;EAClD,MAAAC,UAAA,GAAaD,KAAKE,IAAK,EAAA;EAE7B,IAAI,CAACD,UAAA,EAAmB,OAAA,KAAA,CAAA;EAExB,MAAME,UAAUL,oBAAqB,CAAAM,IAAA,CAAMD,QACzC,IAAAF,UAAA,CAAWC,IAAK,CAAA,CAAA,CAAEG,aAAc,CAAAC,QAAA,CAASH,QAAQ,CAAAE,WAAA,EAAa,CAAA,CAChE;EAEA,IAAI,CAACF,OAAA,EAAgB,OAAAF,UAAA;EAErB,OAAOA,WAAWM,KAAM,CAAA,CAAA,EAAG,CAACJ,OAAQ,CAAAK,MAAM,EAAEN,IAAK,EAAA;AACnD,CAAA;AAKa,MAAAO,UAAA,GAAaA,CAACT,GAAA,EAAcU,UAAwB,KAAA;EAC/D,IAAI,CAACV,GAAA,EAAY,OAAA,KAAA,CAAA;EAEX,MAAAW,WAAA,GAAcZ,yBAAyBC,GAAG,CAAA;EAEhD,IAAI,CAACU,UAAA,EAAmB,OAAAC,WAAA;EAEjB,OAAA,GAAGA,WAAW,KAAKD,UAAU,GAAA;AACtC,CAAA;;"}
1
+ {"version":3,"file":"variant.js","sources":["../../src/utils/variant.ts"],"sourcesContent":["/**\n * Removes the regional (and other) SKU postfix from the SKU.\n */\n\nconst REGIONAL_SKU_POSTFIX = [\n \" EU\",\n \"-EU\",\n \"(EU)\",\n \" US\",\n \"(US)\",\n \"-US\",\n \"-BR\",\n \"-CN\",\n \"-TW\",\n \"-JP\",\n \"-AU\",\n \"-AR\",\n \"-UK\",\n \"-U\",\n \"-IND\",\n \"-Standalone\",\n];\n\nexport const removeRegionalSkuPostfix = (sku?: string) => {\n const trimmedSku = sku?.trim();\n\n if (!trimmedSku) return undefined;\n\n const postfix = REGIONAL_SKU_POSTFIX.find((postfix) =>\n trimmedSku.trim().toUpperCase().endsWith(postfix.toUpperCase()),\n );\n\n if (!postfix) return trimmedSku;\n\n return trimmedSku.slice(0, -postfix.length).trim();\n};\n\n/**\n * Returns the SKU text with the extra label if it exists.\n */\nexport const getSkuText = (sku?: string, extraLabel?: string) => {\n if (!sku) return undefined;\n\n const preparedSku = removeRegionalSkuPostfix(sku);\n\n if (!extraLabel) return preparedSku;\n\n return `${preparedSku} (${extraLabel})`;\n};\n"],"names":["REGIONAL_SKU_POSTFIX","removeRegionalSkuPostfix","sku","trimmedSku","trim","postfix","find","toUpperCase","endsWith","slice","length","getSkuText","extraLabel","preparedSku"],"mappings":";;;AAIA,MAAMA,oBAAuB,GAAA,CAC3B,KAAA,EACA,KAAA,EACA,MAAA,EACA,KAAA,EACA,MAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,IAAA,EACA,MAAA,EACA,aAAA,CACF;AAEa,MAAAC,wBAAA,GAA4BC,GAAiB,IAAA;EAClD,MAAAC,UAAA,GAAaD,KAAKE,IAAK,EAAA;EAEzB,IAAA,CAACD,YAAmB,OAAA,KAAA,CAAA;EAExB,MAAME,UAAUL,oBAAqB,CAAAM,IAAA,CAAMD,QACzC,IAAAF,UAAA,CAAWC,IAAK,CAAA,CAAA,CAAEG,aAAc,CAAAC,QAAA,CAASH,QAAQ,CAAAE,WAAA,EAAa,CAAA,CAChE;EAEI,IAAA,CAACF,SAAgB,OAAAF,UAAA;EAErB,OAAOA,WAAWM,KAAM,CAAA,CAAA,EAAG,CAACJ,OAAQ,CAAAK,MAAM,EAAEN,IAAK,EAAA;AACnD,CAAA;AAKa,MAAAO,UAAA,GAAaA,CAACT,GAAA,EAAcU,UAAwB,KAAA;EAC3D,IAAA,CAACV,KAAY,OAAA,KAAA,CAAA;EAEX,MAAAW,WAAA,GAAcZ,yBAAyBC,GAAG,CAAA;EAE5C,IAAA,CAACU,YAAmB,OAAAC,WAAA;EAEjB,OAAA,GAAGA,WAAW,KAAKD,UAAU,GAAA;AACtC,CAAA;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"variant.mjs","sources":["../../src/utils/variant.ts"],"sourcesContent":["/**\n * Removes the regional (and other) SKU postfix from the SKU.\n */\n\nconst REGIONAL_SKU_POSTFIX = [\n \" EU\",\n \"-EU\",\n \"(EU)\",\n \" US\",\n \"(US)\",\n \"-US\",\n \"-BR\",\n \"-CN\",\n \"-TW\",\n \"-JP\",\n \"-AU\",\n \"-AR\",\n \"-UK\",\n \"-U\",\n \"-IND\",\n \"-Standalone\",\n];\n\nexport const removeRegionalSkuPostfix = (sku?: string) => {\n const trimmedSku = sku?.trim();\n\n if (!trimmedSku) return undefined;\n\n const postfix = REGIONAL_SKU_POSTFIX.find((postfix) =>\n trimmedSku.trim().toUpperCase().endsWith(postfix.toUpperCase()),\n );\n\n if (!postfix) return trimmedSku;\n\n return trimmedSku.slice(0, -postfix.length).trim();\n};\n\n/**\n * Returns the SKU text with the extra label if it exists.\n */\nexport const getSkuText = (sku?: string, extraLabel?: string) => {\n if (!sku) return undefined;\n\n const preparedSku = removeRegionalSkuPostfix(sku);\n\n if (!extraLabel) return preparedSku;\n\n return `${preparedSku} (${extraLabel})`;\n};\n"],"names":["REGIONAL_SKU_POSTFIX","removeRegionalSkuPostfix","sku","trimmedSku","trim","postfix","find","toUpperCase","endsWith","slice","length","getSkuText","extraLabel","preparedSku"],"mappings":";;AAIA,MAAMA,oBAAuB,GAAA,CAC3B,KAAA,EACA,KAAA,EACA,MAAA,EACA,KAAA,EACA,MAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,IAAA,EACA,MAAA,EACA,aAAA,CACF;AAEa,MAAAC,wBAAA,GAA4BC,GAAiB,IAAA;EAClD,MAAAC,UAAA,GAAaD,KAAKE,IAAK,EAAA;EAE7B,IAAI,CAACD,UAAA,EAAmB,OAAA,KAAA,CAAA;EAExB,MAAME,UAAUL,oBAAqB,CAAAM,IAAA,CAAMD,QACzC,IAAAF,UAAA,CAAWC,IAAK,CAAA,CAAA,CAAEG,aAAc,CAAAC,QAAA,CAASH,QAAQ,CAAAE,WAAA,EAAa,CAAA,CAChE;EAEA,IAAI,CAACF,OAAA,EAAgB,OAAAF,UAAA;EAErB,OAAOA,WAAWM,KAAM,CAAA,CAAA,EAAG,CAACJ,OAAQ,CAAAK,MAAM,EAAEN,IAAK,EAAA;AACnD,CAAA;AAKa,MAAAO,UAAA,GAAaA,CAACT,GAAA,EAAcU,UAAwB,KAAA;EAC/D,IAAI,CAACV,GAAA,EAAY,OAAA,KAAA,CAAA;EAEX,MAAAW,WAAA,GAAcZ,yBAAyBC,GAAG,CAAA;EAEhD,IAAI,CAACU,UAAA,EAAmB,OAAAC,WAAA;EAEjB,OAAA,GAAGA,WAAW,KAAKD,UAAU,GAAA;AACtC,CAAA;"}
1
+ {"version":3,"file":"variant.mjs","sources":["../../src/utils/variant.ts"],"sourcesContent":["/**\n * Removes the regional (and other) SKU postfix from the SKU.\n */\n\nconst REGIONAL_SKU_POSTFIX = [\n \" EU\",\n \"-EU\",\n \"(EU)\",\n \" US\",\n \"(US)\",\n \"-US\",\n \"-BR\",\n \"-CN\",\n \"-TW\",\n \"-JP\",\n \"-AU\",\n \"-AR\",\n \"-UK\",\n \"-U\",\n \"-IND\",\n \"-Standalone\",\n];\n\nexport const removeRegionalSkuPostfix = (sku?: string) => {\n const trimmedSku = sku?.trim();\n\n if (!trimmedSku) return undefined;\n\n const postfix = REGIONAL_SKU_POSTFIX.find((postfix) =>\n trimmedSku.trim().toUpperCase().endsWith(postfix.toUpperCase()),\n );\n\n if (!postfix) return trimmedSku;\n\n return trimmedSku.slice(0, -postfix.length).trim();\n};\n\n/**\n * Returns the SKU text with the extra label if it exists.\n */\nexport const getSkuText = (sku?: string, extraLabel?: string) => {\n if (!sku) return undefined;\n\n const preparedSku = removeRegionalSkuPostfix(sku);\n\n if (!extraLabel) return preparedSku;\n\n return `${preparedSku} (${extraLabel})`;\n};\n"],"names":["REGIONAL_SKU_POSTFIX","removeRegionalSkuPostfix","sku","trimmedSku","trim","postfix","find","toUpperCase","endsWith","slice","length","getSkuText","extraLabel","preparedSku"],"mappings":";;AAIA,MAAMA,oBAAuB,GAAA,CAC3B,KAAA,EACA,KAAA,EACA,MAAA,EACA,KAAA,EACA,MAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,KAAA,EACA,IAAA,EACA,MAAA,EACA,aAAA,CACF;AAEa,MAAAC,wBAAA,GAA4BC,GAAiB,IAAA;EAClD,MAAAC,UAAA,GAAaD,KAAKE,IAAK,EAAA;EAEzB,IAAA,CAACD,YAAmB,OAAA,KAAA,CAAA;EAExB,MAAME,UAAUL,oBAAqB,CAAAM,IAAA,CAAMD,QACzC,IAAAF,UAAA,CAAWC,IAAK,CAAA,CAAA,CAAEG,aAAc,CAAAC,QAAA,CAASH,QAAQ,CAAAE,WAAA,EAAa,CAAA,CAChE;EAEI,IAAA,CAACF,SAAgB,OAAAF,UAAA;EAErB,OAAOA,WAAWM,KAAM,CAAA,CAAA,EAAG,CAACJ,OAAQ,CAAAK,MAAM,EAAEN,IAAK,EAAA;AACnD,CAAA;AAKa,MAAAO,UAAA,GAAaA,CAACT,GAAA,EAAcU,UAAwB,KAAA;EAC3D,IAAA,CAACV,KAAY,OAAA,KAAA,CAAA;EAEX,MAAAW,WAAA,GAAcZ,yBAAyBC,GAAG,CAAA;EAE5C,IAAA,CAACU,YAAmB,OAAAC,WAAA;EAEjB,OAAA,GAAGA,WAAW,KAAKD,UAAU,GAAA;AACtC,CAAA;"}