@ubnt/store.core 9.24.0-alpha.2 → 9.24.0-alpha.3

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 (131) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/lib/assets/minus4.svg +8 -8
  3. package/lib/assets/minus5.svg +8 -8
  4. package/lib/assets/plus5.svg +9 -9
  5. package/lib/assets/plus6.svg +9 -9
  6. package/lib/assets/ucgMax.jpg +0 -0
  7. package/lib/assets/ucgMax2.jpg +0 -0
  8. package/lib/assets/ucgUltra.jpg +0 -0
  9. package/lib/assets/ucgUltra2.jpg +0 -0
  10. package/lib/assets/udmPro.jpg +0 -0
  11. package/lib/assets/udmPro2.jpg +0 -0
  12. package/lib/assets/udmProMax.jpg +0 -0
  13. package/lib/assets/udmProMax2.jpg +0 -0
  14. package/lib/assets/udmProSpecial.jpg +0 -0
  15. package/lib/assets/udmProSpecial2.jpg +0 -0
  16. package/lib/components/Gallery/Gallery.context.js +3 -5
  17. package/lib/components/Gallery/Gallery.context.js.map +1 -1
  18. package/lib/components/Gallery/Gallery.context.mjs +3 -5
  19. package/lib/components/Gallery/Gallery.context.mjs.map +1 -1
  20. package/lib/components/Header/AccountFrame/Mobile/Mobile.js +1 -1
  21. package/lib/components/Header/AccountFrame/Mobile/Mobile.js.map +1 -1
  22. package/lib/components/Header/AccountFrame/Mobile/Mobile.mjs +1 -1
  23. package/lib/components/Header/AccountFrame/Mobile/Mobile.mjs.map +1 -1
  24. package/lib/components/Hero/Hero.js +1 -1
  25. package/lib/components/Hero/Hero.js.map +1 -1
  26. package/lib/components/Hero/Hero.mjs +1 -1
  27. package/lib/components/Hero/Hero.mjs.map +1 -1
  28. package/lib/components/LandingPage/LandingPage.js +1 -1
  29. package/lib/components/LandingPage/LandingPage.js.map +1 -1
  30. package/lib/components/LandingPage/LandingPage.mjs +1 -1
  31. package/lib/components/LandingPage/LandingPage.mjs.map +1 -1
  32. package/lib/components/LearnMoreLink/LearnMoreLink.js +1 -1
  33. package/lib/components/LearnMoreLink/LearnMoreLink.js.map +1 -1
  34. package/lib/components/LearnMoreLink/LearnMoreLink.mjs +1 -1
  35. package/lib/components/LearnMoreLink/LearnMoreLink.mjs.map +1 -1
  36. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.d.ts +1 -1
  37. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.js.map +1 -1
  38. package/lib/components/MeetUniFiVideoPlayer/MeetUniFiVideoPlayer.mjs.map +1 -1
  39. package/lib/components/Microsites/MicrositeProductPage.d.ts +1 -1
  40. package/lib/components/Microsites/MicrositeProductPage.js.map +1 -1
  41. package/lib/components/Microsites/MicrositeProductPage.mjs.map +1 -1
  42. package/lib/components/ModelCompareV3/StickyGrid/StickyGrid.js +4 -8
  43. package/lib/components/ModelCompareV3/StickyGrid/StickyGrid.js.map +1 -1
  44. package/lib/components/ModelCompareV3/StickyGrid/StickyGrid.mjs +4 -8
  45. package/lib/components/ModelCompareV3/StickyGrid/StickyGrid.mjs.map +1 -1
  46. package/lib/components/ModelCompareV3/StickyGrid/StickyGridOverlay.d.ts +1 -2
  47. package/lib/components/ModelCompareV3/StickyGrid/StickyGridOverlay.js.map +1 -1
  48. package/lib/components/ModelCompareV3/StickyGrid/StickyGridOverlay.mjs.map +1 -1
  49. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.js +5 -5
  50. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgMax.jpg.mjs +2 -2
  51. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.js +5 -5
  52. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/ucgUltra.jpg.mjs +2 -2
  53. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
  54. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
  55. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.js +5 -5
  56. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProMax.jpg.mjs +2 -2
  57. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
  58. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
  59. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.js +1 -1
  60. package/lib/components/ModelCompareV3/assets/Consoles/ucgMax.jpg.mjs +2 -2
  61. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.js +1 -1
  62. package/lib/components/ModelCompareV3/assets/Consoles/ucgUltra.jpg.mjs +2 -2
  63. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
  64. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
  65. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.js +1 -1
  66. package/lib/components/ModelCompareV3/assets/Consoles/udmProMax.jpg.mjs +2 -2
  67. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
  68. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
  69. package/lib/components/ModelCompareV3/data/CloudGateways.js +15 -15
  70. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +10 -10
  71. package/lib/components/ModelCompareV3/data/products/ucgMax.js +1 -1
  72. package/lib/components/ModelCompareV3/data/products/ucgMax.mjs +1 -1
  73. package/lib/components/ModelCompareV3/data/products/ucgUltra.js +1 -1
  74. package/lib/components/ModelCompareV3/data/products/ucgUltra.mjs +1 -1
  75. package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
  76. package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
  77. package/lib/components/ModelCompareV3/data/products/udmProMax.js +1 -1
  78. package/lib/components/ModelCompareV3/data/products/udmProMax.mjs +1 -1
  79. package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
  80. package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +1 -1
  81. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.js +1 -1
  82. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.js.map +1 -1
  83. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.mjs +1 -1
  84. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/ComputeResourceCalculator.mjs.map +1 -1
  85. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  86. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  87. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  88. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  89. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  90. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  91. package/lib/components/ResourceCalculatorV1/PoeCalculator/PoeCalculator.constants.js +56 -56
  92. package/lib/components/ResourceCalculatorV1/PoeCalculator/PoeCalculator.constants.js.map +1 -1
  93. package/lib/components/ResourceCalculatorV1/PoeCalculator/PoeCalculator.constants.mjs +56 -56
  94. package/lib/components/ResourceCalculatorV1/PoeCalculator/PoeCalculator.constants.mjs.map +1 -1
  95. package/lib/components/ResourceCalculatorV1/PoeCalculator/PoeCalculator.js.map +1 -1
  96. package/lib/components/ResourceCalculatorV1/PoeCalculator/PoeCalculator.mjs.map +1 -1
  97. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +4 -3
  98. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js.map +1 -1
  99. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +5 -4
  100. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs.map +1 -1
  101. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  102. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  103. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  104. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  105. package/lib/components/VariantSelector/Variant/Variant.js +5 -5
  106. package/lib/components/VariantSelector/Variant/Variant.js.map +1 -1
  107. package/lib/components/VariantSelector/Variant/Variant.mjs +5 -5
  108. package/lib/components/VariantSelector/Variant/Variant.mjs.map +1 -1
  109. package/lib/constants/shopify/keyFeatureIcons.js +8 -8
  110. package/lib/constants/shopify/keyFeatureIcons.js.map +1 -1
  111. package/lib/constants/shopify/keyFeatureIcons.mjs +8 -8
  112. package/lib/constants/shopify/keyFeatureIcons.mjs.map +1 -1
  113. package/lib/contexts/MenuContext/utils.d.ts +1 -2
  114. package/lib/contexts/MenuContext/utils.js +1 -1
  115. package/lib/contexts/MenuContext/utils.js.map +1 -1
  116. package/lib/contexts/MenuContext/utils.mjs +1 -1
  117. package/lib/contexts/MenuContext/utils.mjs.map +1 -1
  118. package/lib/utils/money/tax.private.d.ts +0 -8
  119. package/lib/utils/money/tax.private.js +5 -14
  120. package/lib/utils/money/tax.private.js.map +1 -1
  121. package/lib/utils/money/tax.private.mjs +8 -16
  122. package/lib/utils/money/tax.private.mjs.map +1 -1
  123. package/lib/utils/validations/postalCodeSuperRefinement.js +1 -1
  124. package/lib/utils/validations/postalCodeSuperRefinement.js.map +1 -1
  125. package/lib/utils/validations/postalCodeSuperRefinement.mjs +1 -1
  126. package/lib/utils/validations/postalCodeSuperRefinement.mjs.map +1 -1
  127. package/lib/utils/wattage.js +1 -1
  128. package/lib/utils/wattage.js.map +1 -1
  129. package/lib/utils/wattage.mjs +1 -1
  130. package/lib/utils/wattage.mjs.map +1 -1
  131. package/package.json +1 -1
@@ -1,19 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var dinero_js = require('dinero.js');
4
- var errors = require('../errors.js');
5
4
  var fixedAmount = require('./allocators/fixedAmount.js');
5
+ var constants = require('./constants.js');
6
6
  var misc = require('./misc.js');
7
7
  "use strict";
8
- const taxRateToDineroAllocation = taxRate => {
9
- if (taxRate <= 0 || taxRate >= 1) {
10
- throw new RangeError("Unsupported rate, expected in range of 0>rate<1");
11
- }
12
- const rateScale = String(taxRate).split(".")[1]?.length;
13
- errors.assert(rateScale !== void 0, "rateScale is undefined");
14
- const rateInt = Math.round(taxRate * Math.pow(10, rateScale));
15
- return [rateInt, Math.pow(10, rateScale) - rateInt];
16
- };
17
8
  const allocatePerItemTaxableAmount = itemSummary => {
18
9
  if (itemSummary.quantity === 1) {
19
10
  return [itemSummary];
@@ -42,9 +33,10 @@ const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
42
33
  if (taxRate === 0) {
43
34
  return misc.getDinero(0, itemSummary.currency);
44
35
  }
45
- const [taxAmount] = dinero_js.allocate(misc.getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRateToDineroAllocation(taxRate));
46
- errors.assert(taxAmount !== void 0, "taxAmount is undefined");
47
- return taxAmount;
36
+ return dinero_js.dinero({
37
+ amount: constants.Round.Financial(itemSummary.taxableAmount * taxRate),
38
+ currency: misc.getDineroCurrency(itemSummary.currency)
39
+ });
48
40
  };
49
41
  const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
50
42
  if (taxRate === 0) {
@@ -61,5 +53,4 @@ const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
61
53
  exports.allocatePerItemTaxableAmount = allocatePerItemTaxableAmount;
62
54
  exports.calculatePerQtyLineItemTax = calculatePerQtyLineItemTax;
63
55
  exports.calculateWholeQtyLineItemTax = calculateWholeQtyLineItemTax;
64
- exports.taxRateToDineroAllocation = taxRateToDineroAllocation;
65
56
  //# sourceMappingURL=tax.private.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tax.private.js","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport type { Dinero } from \"dinero.js\";\nimport { add, allocate, subtract } from \"dinero.js\";\n\nimport { assert } from \"../errors\";\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { amount, getDinero } from \"./misc\";\nimport type {\n Cents,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Private helper to convert a floating number to a dinero friendly allocation integer pair\n * @see https://v2.dinerojs.com/docs/api/mutations/allocate\n * @example\n * taxRateToDineroAllocation(0.1) // [1, 9]\n * taxRateToDineroAllocation(0.5) // [5, 5]\n */\nexport const taxRateToDineroAllocation = (\n taxRate: TaxRate,\n): [number, number] => {\n if (taxRate <= 0 || taxRate >= 1) {\n throw new RangeError(\"Unsupported rate, expected in range of 0>rate<1\");\n }\n\n // Get the scale of the rate\n const rateScale = String(taxRate).split(\".\")[1]?.length;\n assert(rateScale !== undefined, \"rateScale is undefined\");\n\n // Convert to integers\n const rateInt = Math.round(taxRate * Math.pow(10, rateScale));\n return [rateInt, Math.pow(10, rateScale) - rateInt];\n};\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * FIXME: look into approach with multiply and different scale for control over rounding, currently we just inherit\n * what dinero gives us which cause unexpected rounding issue\n */\n const [taxAmount] = allocate(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n taxRateToDineroAllocation(taxRate),\n );\n\n assert(taxAmount !== undefined, \"taxAmount is undefined\");\n return taxAmount;\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["taxRateToDineroAllocation","taxRate","RangeError","rateScale","String","split","length","assert","rateInt","Math","round","pow","allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxAmount","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach"],"mappings":";;;;;;;AAwBa,MAAAA,yBAAA,GACXC,OACqB,IAAA;EACjB,IAAAA,OAAA,IAAW,CAAK,IAAAA,OAAA,IAAW,CAAG,EAAA;IAC1B,MAAA,IAAIC,WAAW,iDAAiD,CAAA;EACxE;EAGM,MAAAC,SAAA,GAAYC,OAAOH,OAAO,CAAA,CAAEI,MAAM,GAAG,CAAA,CAAE,CAAC,CAAG,EAAAC,MAAA;EAC1CC,MAAAA,CAAAA,MAAA,CAAAJ,SAAA,KAAc,QAAW,wBAAwB,CAAA;EAGlD,MAAAK,OAAA,GAAUC,KAAKC,KAAM,CAAAT,OAAA,GAAUQ,KAAKE,GAAI,CAAA,EAAA,EAAIR,SAAS,CAAC,CAAA;EAC5D,OAAO,CAACK,OAAS,EAAAC,IAAA,CAAKE,IAAI,EAAI,EAAAR,SAAS,IAAIK,OAAO,CAAA;AACpD,CAAA;AAMa,MAAAI,4BAAA,GACXC,WAC4B,IAAA;EAIxB,IAAAA,WAAA,CAAYC,aAAa,CAAG,EAAA;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAoB,GAAAC,SAAA,CAAAA,GAAA,CACxBC,IAAAA,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nB,0BAA0BC,OAAO,CAAA,CACnC;EAEOM,MAAAA,CAAAA,MAAA,CAAA0B,SAAA,KAAc,QAAW,wBAAwB,CAAA;EACjD,OAAAA,SAAA;AACT,CAAA;AAEa,MAAAC,0BAAA,GAA6BA,CACxCrB,WAAA,EACAZ,OACkB,KAAA;EAElB,IAAIA,YAAY,CAAG,EAAA;IACV,OAAAgB,cAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGM,MAAAgB,mBAAA,GAAsBvB,6BAA6BC,WAAW,CAAA;EAGpE,IAAIuB,cAAiB,GAAAnB,IAAA,CAAAA,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAElCgB,mBAAA,CAAAE,OAAA,CAASxB,YAAgB,IAAA;IAGrC,MAAAoB,SAAA,GAAYD,4BAA6BnB,CAAAA,YAAAA,EAAaZ,OAAO,CAAA;IAClDmC,cAAA,GAAApB,SAAA,CAAAA,GAAA,CAAIoB,gBAAgBH,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAG,cAAA;AACT,CAAA;;;;"}
1
+ {"version":3,"file":"tax.private.js","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport type { Dinero } from \"dinero.js\";\nimport { add, dinero, subtract } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Cents,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * Historically we calculate the tax by using dinero allocation, but we did not have control over how we round things.\n * So instead as we are already working with currency in cents we can multiply and round it ourselves.\n */\n return dinero({\n amount: Round.Financial(itemSummary.taxableAmount * taxRate),\n currency: getDineroCurrency(itemSummary.currency),\n });\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","length","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxRate","dinero","Round","Financial","getDineroCurrency","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach","taxAmount"],"mappings":";;;;;;;AAqBa,MAAAA,4BAAA,GACXC,WAC4B,IAAA;EAIxB,IAAAA,WAAA,CAAYC,aAAa,CAAG,EAAA;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAoB,GAAAC,SAAA,CAAAA,GAAA,CACxBC,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYK,aAAe,EAAAL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYO,cAAgB,EAAAP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEM,MAAAE,SAAA,GAAY,IAAIC,gCAAqB,CAAA;IACzCC,uBAAuBV,WAAY,CAAAO,cAAA;IACnCI,kBAAA,EAAoBC,YAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAY,CAAAM;EAAA,CACvB,CAAA;EAGD,OAAOO,MAAMC,IAAK,CAAA;IAAEC,QAAQf,WAAY,CAAAC;EAAA,GAAY,MAAM;IACxD,MAAMe,0BAA0BR,SAAU,CAAAS,QAAA,CACxCjB,WAAY,CAAAkB,SAAA,EACZlB,WAAY,CAAAM,QAAA,CACd;IAEA,MAAMD,aAAgB,GAAAc,SAAA,CAAAA,QAAA,CACpBf,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYkB,SAAW,EAAAlB,WAAA,CAAYM,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,17 +1,8 @@
1
- import { add, subtract, allocate } from 'dinero.js';
2
- import { assert } from '../errors.mjs';
1
+ import { add, subtract, dinero } from 'dinero.js';
3
2
  import { FixedAmountAllocator } from './allocators/fixedAmount.mjs';
4
- import { getDinero, amount } from './misc.mjs';
3
+ import { Round } from './constants.mjs';
4
+ import { getDinero, amount, getDineroCurrency } from './misc.mjs';
5
5
  "use strict";
6
- const taxRateToDineroAllocation = taxRate => {
7
- if (taxRate <= 0 || taxRate >= 1) {
8
- throw new RangeError("Unsupported rate, expected in range of 0>rate<1");
9
- }
10
- const rateScale = String(taxRate).split(".")[1]?.length;
11
- assert(rateScale !== void 0, "rateScale is undefined");
12
- const rateInt = Math.round(taxRate * Math.pow(10, rateScale));
13
- return [rateInt, Math.pow(10, rateScale) - rateInt];
14
- };
15
6
  const allocatePerItemTaxableAmount = itemSummary => {
16
7
  if (itemSummary.quantity === 1) {
17
8
  return [itemSummary];
@@ -40,9 +31,10 @@ const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
40
31
  if (taxRate === 0) {
41
32
  return getDinero(0, itemSummary.currency);
42
33
  }
43
- const [taxAmount] = allocate(getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRateToDineroAllocation(taxRate));
44
- assert(taxAmount !== void 0, "taxAmount is undefined");
45
- return taxAmount;
34
+ return dinero({
35
+ amount: Round.Financial(itemSummary.taxableAmount * taxRate),
36
+ currency: getDineroCurrency(itemSummary.currency)
37
+ });
46
38
  };
47
39
  const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
48
40
  if (taxRate === 0) {
@@ -56,5 +48,5 @@ const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
56
48
  });
57
49
  return totalTaxAmount;
58
50
  };
59
- export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax, taxRateToDineroAllocation };
51
+ export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax };
60
52
  //# sourceMappingURL=tax.private.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"tax.private.mjs","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport type { Dinero } from \"dinero.js\";\nimport { add, allocate, subtract } from \"dinero.js\";\n\nimport { assert } from \"../errors\";\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { amount, getDinero } from \"./misc\";\nimport type {\n Cents,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Private helper to convert a floating number to a dinero friendly allocation integer pair\n * @see https://v2.dinerojs.com/docs/api/mutations/allocate\n * @example\n * taxRateToDineroAllocation(0.1) // [1, 9]\n * taxRateToDineroAllocation(0.5) // [5, 5]\n */\nexport const taxRateToDineroAllocation = (\n taxRate: TaxRate,\n): [number, number] => {\n if (taxRate <= 0 || taxRate >= 1) {\n throw new RangeError(\"Unsupported rate, expected in range of 0>rate<1\");\n }\n\n // Get the scale of the rate\n const rateScale = String(taxRate).split(\".\")[1]?.length;\n assert(rateScale !== undefined, \"rateScale is undefined\");\n\n // Convert to integers\n const rateInt = Math.round(taxRate * Math.pow(10, rateScale));\n return [rateInt, Math.pow(10, rateScale) - rateInt];\n};\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * FIXME: look into approach with multiply and different scale for control over rounding, currently we just inherit\n * what dinero gives us which cause unexpected rounding issue\n */\n const [taxAmount] = allocate(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n taxRateToDineroAllocation(taxRate),\n );\n\n assert(taxAmount !== undefined, \"taxAmount is undefined\");\n return taxAmount;\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["taxRateToDineroAllocation","taxRate","RangeError","rateScale","String","split","length","assert","rateInt","Math","round","pow","allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxAmount","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach"],"mappings":";;;;;AAwBa,MAAAA,yBAAA,GACXC,OACqB,IAAA;EACjB,IAAAA,OAAA,IAAW,CAAK,IAAAA,OAAA,IAAW,CAAG,EAAA;IAC1B,MAAA,IAAIC,WAAW,iDAAiD,CAAA;EACxE;EAGM,MAAAC,SAAA,GAAYC,OAAOH,OAAO,CAAA,CAAEI,MAAM,GAAG,CAAA,CAAE,CAAC,CAAG,EAAAC,MAAA;EAC1CC,MAAA,CAAAJ,SAAA,KAAc,QAAW,wBAAwB,CAAA;EAGlD,MAAAK,OAAA,GAAUC,KAAKC,KAAM,CAAAT,OAAA,GAAUQ,KAAKE,GAAI,CAAA,EAAA,EAAIR,SAAS,CAAC,CAAA;EAC5D,OAAO,CAACK,OAAS,EAAAC,IAAA,CAAKE,IAAI,EAAI,EAAAR,SAAS,IAAIK,OAAO,CAAA;AACpD,CAAA;AAMa,MAAAI,4BAAA,GACXC,WAC4B,IAAA;EAIxB,IAAAA,WAAA,CAAYC,aAAa,CAAG,EAAA;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAoB,GAAAC,GAAA,CACxBC,SAAU,CAAAJ,WAAA,CAAYK,aAAe,EAAAL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,SAAU,CAAAJ,WAAA,CAAYO,cAAgB,EAAAP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEM,MAAAE,SAAA,GAAY,IAAIC,oBAAqB,CAAA;IACzCC,uBAAuBV,WAAY,CAAAO,cAAA;IACnCI,kBAAA,EAAoBC,OAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAY,CAAAM;EAAA,CACvB,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AA,CAAYM,QAAQ,CAAA;EAElCgB,mBAAA,CAAAE,OAAA,CAASxB,YAAgB,IAAA;IAGrC,MAAAoB,SAAA,GAAYD,4BAA6BnB,CAAAA,YAAAA,EAAaZ,OAAO,CAAA;IAClDmC,cAAA,GAAApB,GAAA,CAAIoB,gBAAgBH,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAG,cAAA;AACT,CAAA;"}
1
+ {"version":3,"file":"tax.private.mjs","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport type { Dinero } from \"dinero.js\";\nimport { add, dinero, subtract } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Cents,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * Historically we calculate the tax by using dinero allocation, but we did not have control over how we round things.\n * So instead as we are already working with currency in cents we can multiply and round it ourselves.\n */\n return dinero({\n amount: Round.Financial(itemSummary.taxableAmount * taxRate),\n currency: getDineroCurrency(itemSummary.currency),\n });\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dinero<Cents> => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","length","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxRate","dinero","Round","Financial","getDineroCurrency","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach","taxAmount"],"mappings":";;;;;AAqBa,MAAAA,4BAAA,GACXC,WAC4B,IAAA;EAIxB,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YK,gBAAgBgB,OAAO,CAAA;IAC3Df,QAAA,EAAUmB,iBAAkB,CAAAzB,WAAA,CAAYM,QAAQ;EAAA,CACjD,CAAA;AACH,CAAA;AAEa,MAAAoB,0BAAA,GAA6BA,CACxC1B,WAAA,EACAqB,OACkB,KAAA;EAElB,IAAIA,YAAY,CAAG,EAAA;IACV,OAAAjB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGM,MAAAqB,mBAAA,GAAsB5B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI4B,cAAiB,GAAAxB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAElCqB,mBAAA,CAAAE,OAAA,CAAS7B,YAAgB,IAAA;IAGrC,MAAA8B,SAAA,GAAYV,4BAA6BpB,CAAAA,YAAAA,EAAaqB,OAAO,CAAA;IAClDO,cAAA,GAAAzB,GAAA,CAAIyB,gBAAgBE,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAF,cAAA;AACT,CAAA;"}
@@ -15,7 +15,7 @@ const postalCodeSuperRefinement = ({
15
15
  if (!country.countryHasPostalCode(country$1)) {
16
16
  return;
17
17
  }
18
- if (!postalCode$1 || !postalCode$1?.length) {
18
+ if (!postalCode$1?.length) {
19
19
  return ctx.addIssue({
20
20
  path: ["postalCode"],
21
21
  code: zod.ZodIssueCode.too_small,
@@ -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;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;"}
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?.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;EAMI,IAAA,CAACC,cAAYI,MAAQ,EAAA;IACvB,OAAOF,IAAIG,QAAS,CAAA;MAClBC,IAAA,EAAM,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perRefinement = ({
13
13
  if (!countryHasPostalCode(country)) {
14
14
  return;
15
15
  }
16
- if (!postalCode || !postalCode?.length) {
16
+ if (!postalCode?.length) {
17
17
  return ctx.addIssue({
18
18
  path: ["postalCode"],
19
19
  code: ZodIssueCode.too_small,
@@ -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;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;"}
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?.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;EAMI,IAAA,CAACC,YAAYI,MAAQ,EAAA;IACvB,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;"}
@@ -5,7 +5,7 @@ const POE_WATTAGE_REGEX = /poe:(\d+)w/i;
5
5
  const getPoeWattageFromTag = tagName => {
6
6
  if (!tagName) return void 0;
7
7
  const wattage = POE_WATTAGE_REGEX.exec(tagName)?.[1];
8
- if (!wattage || !wattage.length) return void 0;
8
+ if (!wattage?.length) return void 0;
9
9
  return `${wattage}W`;
10
10
  };
11
11
  const getPoeWattageFromTags = tags => {
@@ -1 +1 @@
1
- {"version":3,"file":"wattage.js","sources":["../../src/utils/wattage.ts"],"sourcesContent":["// #############################################################################\n// PoE Wattage Tags\n// #############################################################################\n\nconst POE_WATTAGE_REGEX = /poe:(\\d+)w/i;\n\n/**\n * Get the PoE wattage from a tag\n * @example \"poe:100w\" => \"100W\"\n */\nexport const getPoeWattageFromTag = (tagName: string | undefined) => {\n // If there is no wattage tag, return undefined\n if (!tagName) return undefined;\n\n // Get the wattage from the tag\n const wattage = POE_WATTAGE_REGEX.exec(tagName)?.[1];\n\n // If there is no wattage, return undefined\n if (!wattage || !wattage.length) return undefined;\n\n // Return the wattage\n return `${wattage}W`;\n};\n\n/**\n * Finds first PoE wattage tag and returns the wattage\n */\nexport const getPoeWattageFromTags = (\n tags: { name: string }[],\n): string | undefined => {\n for (const tag of tags) {\n const watts = getPoeWattageFromTag(tag.name);\n\n if (watts) return watts;\n }\n\n return undefined;\n};\n"],"names":["POE_WATTAGE_REGEX","getPoeWattageFromTag","tagName","wattage","exec","length","getPoeWattageFromTags","tags","tag","watts","name"],"mappings":";;;AAIA,MAAMA,iBAAoB,GAAA,aAAA;AAMb,MAAAC,oBAAA,GAAwBC,OAAgC,IAAA;EAE/D,IAAA,CAACA,SAAgB,OAAA,KAAA,CAAA;EAGrB,MAAMC,OAAU,GAAAH,iBAAA,CAAkBI,IAAK,CAAAF,OAAO,IAAI,CAAC,CAAA;EAGnD,IAAI,CAACC,OAAA,IAAW,CAACA,OAAA,CAAQE,QAAe,OAAA,KAAA,CAAA;EAGxC,UAAUF,OAAO,GAAA;AACnB,CAAA;AAKa,MAAAG,qBAAA,GACXC,IACuB,IAAA;EACvB,KAAA,MAAWC,OAAOD,IAAM,EAAA;IAChB,MAAAE,KAAA,GAAQR,oBAAqB,CAAAO,GAAA,CAAIE,IAAI,CAAA;IAE3C,IAAID,OAAc,OAAAA,KAAA;EACpB;EAEO,OAAA,KAAA,CAAA;AACT,CAAA;;"}
1
+ {"version":3,"file":"wattage.js","sources":["../../src/utils/wattage.ts"],"sourcesContent":["// #############################################################################\n// PoE Wattage Tags\n// #############################################################################\n\nconst POE_WATTAGE_REGEX = /poe:(\\d+)w/i;\n\n/**\n * Get the PoE wattage from a tag\n * @example \"poe:100w\" => \"100W\"\n */\nexport const getPoeWattageFromTag = (tagName: string | undefined) => {\n // If there is no wattage tag, return undefined\n if (!tagName) return undefined;\n\n // Get the wattage from the tag\n const wattage = POE_WATTAGE_REGEX.exec(tagName)?.[1];\n\n // If there is no wattage, return undefined\n if (!wattage?.length) return undefined;\n\n // Return the wattage\n return `${wattage}W`;\n};\n\n/**\n * Finds first PoE wattage tag and returns the wattage\n */\nexport const getPoeWattageFromTags = (\n tags: { name: string }[],\n): string | undefined => {\n for (const tag of tags) {\n const watts = getPoeWattageFromTag(tag.name);\n\n if (watts) return watts;\n }\n\n return undefined;\n};\n"],"names":["POE_WATTAGE_REGEX","getPoeWattageFromTag","tagName","wattage","exec","length","getPoeWattageFromTags","tags","tag","watts","name"],"mappings":";;;AAIA,MAAMA,iBAAoB,GAAA,aAAA;AAMb,MAAAC,oBAAA,GAAwBC,OAAgC,IAAA;EAE/D,IAAA,CAACA,SAAgB,OAAA,KAAA,CAAA;EAGrB,MAAMC,OAAU,GAAAH,iBAAA,CAAkBI,IAAK,CAAAF,OAAO,IAAI,CAAC,CAAA;EAG/C,IAAA,CAACC,OAAS,EAAAE,MAAA,EAAe,OAAA,KAAA,CAAA;EAG7B,UAAUF,OAAO,GAAA;AACnB,CAAA;AAKa,MAAAG,qBAAA,GACXC,IACuB,IAAA;EACvB,KAAA,MAAWC,OAAOD,IAAM,EAAA;IAChB,MAAAE,KAAA,GAAQR,oBAAqB,CAAAO,GAAA,CAAIE,IAAI,CAAA;IAE3C,IAAID,OAAc,OAAAA,KAAA;EACpB;EAEO,OAAA,KAAA,CAAA;AACT,CAAA;;"}
@@ -4,7 +4,7 @@ const POE_WATTAGE_REGEX = /poe:(\d+)w/i;
4
4
  const getPoeWattageFromTag = tagName => {
5
5
  if (!tagName) return void 0;
6
6
  const wattage = POE_WATTAGE_REGEX.exec(tagName)?.[1];
7
- if (!wattage || !wattage.length) return void 0;
7
+ if (!wattage?.length) return void 0;
8
8
  return `${wattage}W`;
9
9
  };
10
10
  const getPoeWattageFromTags = tags => {
@@ -1 +1 @@
1
- {"version":3,"file":"wattage.mjs","sources":["../../src/utils/wattage.ts"],"sourcesContent":["// #############################################################################\n// PoE Wattage Tags\n// #############################################################################\n\nconst POE_WATTAGE_REGEX = /poe:(\\d+)w/i;\n\n/**\n * Get the PoE wattage from a tag\n * @example \"poe:100w\" => \"100W\"\n */\nexport const getPoeWattageFromTag = (tagName: string | undefined) => {\n // If there is no wattage tag, return undefined\n if (!tagName) return undefined;\n\n // Get the wattage from the tag\n const wattage = POE_WATTAGE_REGEX.exec(tagName)?.[1];\n\n // If there is no wattage, return undefined\n if (!wattage || !wattage.length) return undefined;\n\n // Return the wattage\n return `${wattage}W`;\n};\n\n/**\n * Finds first PoE wattage tag and returns the wattage\n */\nexport const getPoeWattageFromTags = (\n tags: { name: string }[],\n): string | undefined => {\n for (const tag of tags) {\n const watts = getPoeWattageFromTag(tag.name);\n\n if (watts) return watts;\n }\n\n return undefined;\n};\n"],"names":["POE_WATTAGE_REGEX","getPoeWattageFromTag","tagName","wattage","exec","length","getPoeWattageFromTags","tags","tag","watts","name"],"mappings":";;AAIA,MAAMA,iBAAoB,GAAA,aAAA;AAMb,MAAAC,oBAAA,GAAwBC,OAAgC,IAAA;EAE/D,IAAA,CAACA,SAAgB,OAAA,KAAA,CAAA;EAGrB,MAAMC,OAAU,GAAAH,iBAAA,CAAkBI,IAAK,CAAAF,OAAO,IAAI,CAAC,CAAA;EAGnD,IAAI,CAACC,OAAA,IAAW,CAACA,OAAA,CAAQE,QAAe,OAAA,KAAA,CAAA;EAGxC,UAAUF,OAAO,GAAA;AACnB,CAAA;AAKa,MAAAG,qBAAA,GACXC,IACuB,IAAA;EACvB,KAAA,MAAWC,OAAOD,IAAM,EAAA;IAChB,MAAAE,KAAA,GAAQR,oBAAqB,CAAAO,GAAA,CAAIE,IAAI,CAAA;IAE3C,IAAID,OAAc,OAAAA,KAAA;EACpB;EAEO,OAAA,KAAA,CAAA;AACT,CAAA;"}
1
+ {"version":3,"file":"wattage.mjs","sources":["../../src/utils/wattage.ts"],"sourcesContent":["// #############################################################################\n// PoE Wattage Tags\n// #############################################################################\n\nconst POE_WATTAGE_REGEX = /poe:(\\d+)w/i;\n\n/**\n * Get the PoE wattage from a tag\n * @example \"poe:100w\" => \"100W\"\n */\nexport const getPoeWattageFromTag = (tagName: string | undefined) => {\n // If there is no wattage tag, return undefined\n if (!tagName) return undefined;\n\n // Get the wattage from the tag\n const wattage = POE_WATTAGE_REGEX.exec(tagName)?.[1];\n\n // If there is no wattage, return undefined\n if (!wattage?.length) return undefined;\n\n // Return the wattage\n return `${wattage}W`;\n};\n\n/**\n * Finds first PoE wattage tag and returns the wattage\n */\nexport const getPoeWattageFromTags = (\n tags: { name: string }[],\n): string | undefined => {\n for (const tag of tags) {\n const watts = getPoeWattageFromTag(tag.name);\n\n if (watts) return watts;\n }\n\n return undefined;\n};\n"],"names":["POE_WATTAGE_REGEX","getPoeWattageFromTag","tagName","wattage","exec","length","getPoeWattageFromTags","tags","tag","watts","name"],"mappings":";;AAIA,MAAMA,iBAAoB,GAAA,aAAA;AAMb,MAAAC,oBAAA,GAAwBC,OAAgC,IAAA;EAE/D,IAAA,CAACA,SAAgB,OAAA,KAAA,CAAA;EAGrB,MAAMC,OAAU,GAAAH,iBAAA,CAAkBI,IAAK,CAAAF,OAAO,IAAI,CAAC,CAAA;EAG/C,IAAA,CAACC,OAAS,EAAAE,MAAA,EAAe,OAAA,KAAA,CAAA;EAG7B,UAAUF,OAAO,GAAA;AACnB,CAAA;AAKa,MAAAG,qBAAA,GACXC,IACuB,IAAA;EACvB,KAAA,MAAWC,OAAOD,IAAM,EAAA;IAChB,MAAAE,KAAA,GAAQR,oBAAqB,CAAAO,GAAA,CAAIE,IAAI,CAAA;IAE3C,IAAID,OAAc,OAAAA,KAAA;EACpB;EAEO,OAAA,KAAA,CAAA;AACT,CAAA;"}
package/package.json CHANGED
@@ -102,5 +102,5 @@
102
102
  "test": "echo 'Hi from @ubnt/store.core 👋'"
103
103
  },
104
104
  "sideEffects": false,
105
- "version": "9.24.0-alpha.2"
105
+ "version": "9.24.0-alpha.3"
106
106
  }