@ubnt/store.core 11.28.0 → 11.29.0-custom-tax.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 (221) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/lib/_virtual/_virtual_multi-entry.js +64 -64
  3. package/lib/_virtual/_virtual_multi-entry.mjs +64 -64
  4. package/lib/assets/ai-360.jpg +0 -0
  5. package/lib/assets/ai-3602.jpg +0 -0
  6. package/lib/assets/attention.svg +1 -1
  7. package/lib/assets/attention2.svg +1 -1
  8. package/lib/assets/door-hub-mini.jpg +0 -0
  9. package/lib/assets/door-hub-mini2.jpg +0 -0
  10. package/lib/assets/door-hub.jpg +0 -0
  11. package/lib/assets/door-hub2.jpg +0 -0
  12. package/lib/assets/g2-reader.jpg +0 -0
  13. package/lib/assets/g2-reader2.jpg +0 -0
  14. package/lib/assets/g3-reader-flex.jpg +0 -0
  15. package/lib/assets/g3-reader-flex2.jpg +0 -0
  16. package/lib/assets/g3-reader-pro.jpg +0 -0
  17. package/lib/assets/g3-reader-pro2.jpg +0 -0
  18. package/lib/assets/g3-starter-kit-pro.jpg +0 -0
  19. package/lib/assets/g3-starter-kit-pro2.jpg +0 -0
  20. package/lib/assets/g5-dome-ultra.jpg +0 -0
  21. package/lib/assets/g5-dome-ultra2.jpg +0 -0
  22. package/lib/assets/g5-dome.jpg +0 -0
  23. package/lib/assets/g5-dome2.jpg +0 -0
  24. package/lib/assets/g5-ptz.jpg +0 -0
  25. package/lib/assets/g5-ptz2.jpg +0 -0
  26. package/lib/assets/interior-design.svg +1 -1
  27. package/lib/assets/interior-design2.svg +1 -1
  28. package/lib/assets/minus4.svg +1 -1
  29. package/lib/assets/minus5.svg +1 -1
  30. package/lib/assets/plus4.svg +1 -1
  31. package/lib/assets/plus5.svg +1 -1
  32. package/lib/assets/udr2.jpg +0 -0
  33. package/lib/assets/udr3.jpg +0 -0
  34. package/lib/assets/video-recorders.png +0 -0
  35. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  36. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  37. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  38. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  39. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  40. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  41. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  42. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  43. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  44. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  45. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  46. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  47. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  48. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  49. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  50. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  51. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  52. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  53. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  54. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  55. package/lib/components/index.d.ts +4 -4
  56. package/lib/components/index.js +64 -64
  57. package/lib/components/index.mjs +64 -64
  58. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr.jpg.js +5 -5
  59. package/lib/constants/modelCompareData/assets/Consoles/bigCompare/udr.jpg.mjs +2 -2
  60. package/lib/constants/modelCompareData/assets/Consoles/udr.jpg.js +1 -1
  61. package/lib/constants/modelCompareData/assets/Consoles/udr.jpg.mjs +2 -2
  62. package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.js +1 -1
  63. package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.mjs +2 -2
  64. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome-ultra.jpg.js +1 -1
  65. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome-ultra.jpg.mjs +2 -2
  66. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.js +1 -1
  67. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.mjs +2 -2
  68. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub-mini.jpg.js +1 -1
  69. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub-mini.jpg.mjs +2 -2
  70. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub.jpg.js +1 -1
  71. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub.jpg.mjs +2 -2
  72. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.js +1 -1
  73. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.mjs +2 -2
  74. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-flex.jpg.js +1 -1
  75. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-flex.jpg.mjs +2 -2
  76. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-pro.jpg.js +1 -1
  77. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-pro.jpg.mjs +2 -2
  78. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.js +1 -1
  79. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.mjs +2 -2
  80. package/lib/constants/modelCompareData/assets/PTZ/g5-ptz.jpg.js +1 -1
  81. package/lib/constants/modelCompareData/assets/PTZ/g5-ptz.jpg.mjs +2 -2
  82. package/lib/constants/modelCompareData/assets/interior-design.svg.js +1 -1
  83. package/lib/constants/modelCompareData/assets/interior-design.svg.mjs +2 -2
  84. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.js +1 -1
  85. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.mjs +2 -2
  86. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome-ultra.jpg.js +1 -1
  87. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome-ultra.jpg.mjs +2 -2
  88. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.js +1 -1
  89. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.mjs +2 -2
  90. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub-mini.jpg.js +1 -1
  91. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub-mini.jpg.mjs +2 -2
  92. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub.jpg.js +1 -1
  93. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub.jpg.mjs +2 -2
  94. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.js +1 -1
  95. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.mjs +2 -2
  96. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-flex.jpg.js +1 -1
  97. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-flex.jpg.mjs +2 -2
  98. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-pro.jpg.js +1 -1
  99. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-pro.jpg.mjs +2 -2
  100. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.js +1 -1
  101. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.mjs +2 -2
  102. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g5-ptz.jpg.js +1 -1
  103. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g5-ptz.jpg.mjs +2 -2
  104. package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.js +1 -1
  105. package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.mjs +2 -2
  106. package/lib/constants/modelCompareData/data/DreamMachineConsolev4.js +3 -3
  107. package/lib/constants/modelCompareData/data/DreamMachineConsolev4.mjs +2 -2
  108. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.js +1 -1
  109. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.mjs +1 -1
  110. package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.js +1 -1
  111. package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.mjs +1 -1
  112. package/lib/constants/modelCompareData/data/products/ai360.js +2 -2
  113. package/lib/constants/modelCompareData/data/products/ai360.mjs +2 -2
  114. package/lib/constants/modelCompareData/data/products/doorHub.js +2 -2
  115. package/lib/constants/modelCompareData/data/products/doorHub.mjs +2 -2
  116. package/lib/constants/modelCompareData/data/products/doorHubMini.js +2 -2
  117. package/lib/constants/modelCompareData/data/products/doorHubMini.mjs +2 -2
  118. package/lib/constants/modelCompareData/data/products/g2Reader.js +2 -2
  119. package/lib/constants/modelCompareData/data/products/g2Reader.mjs +2 -2
  120. package/lib/constants/modelCompareData/data/products/g3ReaderFlex.js +2 -2
  121. package/lib/constants/modelCompareData/data/products/g3ReaderFlex.mjs +2 -2
  122. package/lib/constants/modelCompareData/data/products/g3ReaderPro.js +2 -2
  123. package/lib/constants/modelCompareData/data/products/g3ReaderPro.mjs +2 -2
  124. package/lib/constants/modelCompareData/data/products/g3StarterKitPro.js +2 -2
  125. package/lib/constants/modelCompareData/data/products/g3StarterKitPro.mjs +2 -2
  126. package/lib/constants/modelCompareData/data/products/g5Dome.js +2 -2
  127. package/lib/constants/modelCompareData/data/products/g5Dome.mjs +2 -2
  128. package/lib/constants/modelCompareData/data/products/g5DomeUltra.js +2 -2
  129. package/lib/constants/modelCompareData/data/products/g5DomeUltra.mjs +2 -2
  130. package/lib/constants/modelCompareData/data/products/g5Ptz.js +2 -2
  131. package/lib/constants/modelCompareData/data/products/g5Ptz.mjs +2 -2
  132. package/lib/constants/modelCompareData/data/products/udr.js +1 -1
  133. package/lib/constants/modelCompareData/data/products/udr.mjs +1 -1
  134. package/lib/constants/proStoreCategories/mapping/index.js +1 -1
  135. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  136. package/lib/constants/proStoreCategories/mapping/index.mjs +1 -1
  137. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  138. package/lib/contexts/MicrositeMenuContext/translations/ar.json.js +1 -1
  139. package/lib/contexts/MicrositeMenuContext/translations/ar.json.mjs +1 -1
  140. package/lib/contexts/MicrositeMenuContext/translations/ca.json.js +1 -1
  141. package/lib/contexts/MicrositeMenuContext/translations/ca.json.mjs +1 -1
  142. package/lib/contexts/MicrositeMenuContext/translations/cs.json.js +1 -1
  143. package/lib/contexts/MicrositeMenuContext/translations/cs.json.mjs +1 -1
  144. package/lib/contexts/MicrositeMenuContext/translations/da.json.js +1 -1
  145. package/lib/contexts/MicrositeMenuContext/translations/da.json.mjs +1 -1
  146. package/lib/contexts/MicrositeMenuContext/translations/de.json.js +1 -1
  147. package/lib/contexts/MicrositeMenuContext/translations/de.json.mjs +1 -1
  148. package/lib/contexts/MicrositeMenuContext/translations/el.json.js +1 -1
  149. package/lib/contexts/MicrositeMenuContext/translations/el.json.mjs +1 -1
  150. package/lib/contexts/MicrositeMenuContext/translations/en.json.js +1 -1
  151. package/lib/contexts/MicrositeMenuContext/translations/en.json.mjs +1 -1
  152. package/lib/contexts/MicrositeMenuContext/translations/es-ES.json.js +1 -1
  153. package/lib/contexts/MicrositeMenuContext/translations/es-ES.json.mjs +1 -1
  154. package/lib/contexts/MicrositeMenuContext/translations/es-MX.json.js +1 -1
  155. package/lib/contexts/MicrositeMenuContext/translations/es-MX.json.mjs +1 -1
  156. package/lib/contexts/MicrositeMenuContext/translations/fr.json.js +1 -1
  157. package/lib/contexts/MicrositeMenuContext/translations/fr.json.mjs +1 -1
  158. package/lib/contexts/MicrositeMenuContext/translations/it.json.js +1 -1
  159. package/lib/contexts/MicrositeMenuContext/translations/it.json.mjs +1 -1
  160. package/lib/contexts/MicrositeMenuContext/translations/ja.json.js +1 -1
  161. package/lib/contexts/MicrositeMenuContext/translations/ja.json.mjs +1 -1
  162. package/lib/contexts/MicrositeMenuContext/translations/ko.json.js +1 -1
  163. package/lib/contexts/MicrositeMenuContext/translations/ko.json.mjs +1 -1
  164. package/lib/contexts/MicrositeMenuContext/translations/nl.json.js +1 -1
  165. package/lib/contexts/MicrositeMenuContext/translations/nl.json.mjs +1 -1
  166. package/lib/contexts/MicrositeMenuContext/translations/no.json.js +1 -1
  167. package/lib/contexts/MicrositeMenuContext/translations/no.json.mjs +1 -1
  168. package/lib/contexts/MicrositeMenuContext/translations/pl.json.js +1 -1
  169. package/lib/contexts/MicrositeMenuContext/translations/pl.json.mjs +1 -1
  170. package/lib/contexts/MicrositeMenuContext/translations/pt-BR.json.js +1 -1
  171. package/lib/contexts/MicrositeMenuContext/translations/pt-BR.json.mjs +1 -1
  172. package/lib/contexts/MicrositeMenuContext/translations/pt-PT.json.js +1 -1
  173. package/lib/contexts/MicrositeMenuContext/translations/pt-PT.json.mjs +1 -1
  174. package/lib/contexts/MicrositeMenuContext/translations/ru.json.js +1 -1
  175. package/lib/contexts/MicrositeMenuContext/translations/ru.json.mjs +1 -1
  176. package/lib/contexts/MicrositeMenuContext/translations/sv.json.js +1 -1
  177. package/lib/contexts/MicrositeMenuContext/translations/sv.json.mjs +1 -1
  178. package/lib/contexts/MicrositeMenuContext/translations/tr.json.js +1 -1
  179. package/lib/contexts/MicrositeMenuContext/translations/tr.json.mjs +1 -1
  180. package/lib/contexts/MicrositeMenuContext/translations/zh-Hans.json.js +1 -1
  181. package/lib/contexts/MicrositeMenuContext/translations/zh-Hans.json.mjs +1 -1
  182. package/lib/contexts/MicrositeMenuContext/translations/zh-Hant-TW.json.js +1 -1
  183. package/lib/contexts/MicrositeMenuContext/translations/zh-Hant-TW.json.mjs +1 -1
  184. package/lib/utils/money/allocators/totalAmount.d.ts +17 -0
  185. package/lib/utils/money/allocators/totalAmount.js +40 -0
  186. package/lib/utils/money/allocators/totalAmount.js.map +1 -0
  187. package/lib/utils/money/allocators/totalAmount.mjs +38 -0
  188. package/lib/utils/money/allocators/totalAmount.mjs.map +1 -0
  189. package/lib/utils/money/allocators/totalAmount.test.d.ts +1 -0
  190. package/lib/utils/money/index.d.ts +1 -0
  191. package/lib/utils/money/index.js +2 -0
  192. package/lib/utils/money/index.js.map +1 -1
  193. package/lib/utils/money/index.mjs +1 -0
  194. package/lib/utils/money/index.mjs.map +1 -1
  195. package/lib/utils/money/tax.d.ts +6 -3
  196. package/lib/utils/money/tax.js +3 -10
  197. package/lib/utils/money/tax.js.map +1 -1
  198. package/lib/utils/money/tax.mjs +6 -13
  199. package/lib/utils/money/tax.mjs.map +1 -1
  200. package/lib/utils/money/tax.private.d.ts +7 -2
  201. package/lib/utils/money/tax.private.js +21 -6
  202. package/lib/utils/money/tax.private.js.map +1 -1
  203. package/lib/utils/money/tax.private.mjs +22 -8
  204. package/lib/utils/money/tax.private.mjs.map +1 -1
  205. package/package.json +1 -1
  206. package/lib/components/BackInStock/BackInStock.d.ts +0 -2
  207. package/lib/components/BackInStock/BackInStock.js +0 -52
  208. package/lib/components/BackInStock/BackInStock.js.map +0 -1
  209. package/lib/components/BackInStock/BackInStock.mjs +0 -50
  210. package/lib/components/BackInStock/BackInStock.mjs.map +0 -1
  211. package/lib/components/BackInStock/BackInStock.styles.d.ts +0 -13
  212. package/lib/components/BackInStock/BackInStock.styles.js +0 -53
  213. package/lib/components/BackInStock/BackInStock.styles.js.map +0 -1
  214. package/lib/components/BackInStock/BackInStock.styles.mjs +0 -46
  215. package/lib/components/BackInStock/BackInStock.styles.mjs.map +0 -1
  216. package/lib/components/BackInStock/BackInStock.types.d.ts +0 -27
  217. package/lib/components/BackInStock/index.d.ts +0 -1
  218. package/lib/components/BackInStock/index.js +0 -6
  219. package/lib/components/BackInStock/index.js.map +0 -1
  220. package/lib/components/BackInStock/index.mjs +0 -3
  221. package/lib/components/BackInStock/index.mjs.map +0 -1
@@ -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 { 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 Dino,\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): Dino => {\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): Dino => {\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":";;;;;;;AAoBO,MAAMA,4BAAA,GACXC,WAAA,IAC4B;EAI5B,IAAIA,WAAA,CAAYC,aAAa,CAAA,EAAG;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAA,GAAoBC,SAAAA,CAAAA,GAAA,CACxBC,IAAAA,CAAAA,SAAA,CAAUJ,WAAA,CAAYK,aAAA,EAAeL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,IAAAA,CAAAA,SAAA,CAAUJ,WAAA,CAAYO,cAAA,EAAgBP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEA,MAAME,SAAA,GAAY,IAAIC,gCAAA,CAAqB;IACzCC,uBAAuBV,WAAA,CAAYO,cAAA;IACnCI,kBAAA,EAAoBC,IAAAA,CAAAA,OAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAA,CAAYM;EAAA,CACvB,CAAA;EAGD,OAAOO,MAAMC,IAAA,CAAK;IAAEC,QAAQf,WAAA,CAAYC;EAAA,GAAY,MAAM;IACxD,MAAMe,0BAA0BR,SAAA,CAAUS,QAAA,CACxCjB,WAAA,CAAYkB,SAAA,EACZlB,WAAA,CAAYM,QAAA,CACd;IAEA,MAAMD,aAAA,GAAgBc,SAAA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AA,GAAiBzB,SAAAA,CAAAA,GAAA,CAAIyB,gBAAgBE,SAAS,CAAA;EAChD,CAAC,CAAA;EAED,OAAOF,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 { add, dinero, subtract, toSnapshot } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Dino,\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\nconst calculateTaxOnTaxableAmount = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\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 getTaxFromFinalAmount = (\n amountWithTax: Dino,\n taxRate: TaxRate,\n) => {\n const snapshot = toSnapshot(amountWithTax);\n\n // Calculate the tax amount and apply rounding on it so that behavior for reverse process is consistent\n const taxAmount = Round.Financial(\n snapshot.amount - snapshot.amount / (1 + taxRate),\n );\n\n return dinero({ ...snapshot, amount: taxAmount });\n};\n\nconst calculateTaxFromTaxIncludedPrice = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n) => {\n return getTaxFromFinalAmount(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n taxRate,\n );\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n options: { hasTaxIncludedPrice: boolean },\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n return options.hasTaxIncludedPrice\n ? calculateTaxFromTaxIncludedPrice(itemSummary, taxRate)\n : calculateTaxOnTaxableAmount(itemSummary, taxRate);\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n options: { hasTaxIncludedPrice: boolean },\n): Dino => {\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(\n itemSummary,\n taxRate,\n options,\n );\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","calculateTaxOnTaxableAmount","taxRate","dinero","Round","Financial","getDineroCurrency","getTaxFromFinalAmount","amountWithTax","snapshot","toSnapshot","taxAmount","calculateTaxFromTaxIncludedPrice","calculateWholeQtyLineItemTax","options","hasTaxIncludedPrice","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach"],"mappings":";;;;;;;AAoBO,MAAMA,4BAAA,GACXC,WAAA,IAC4B;EAI5B,IAAIA,WAAA,CAAYC,aAAa,CAAA,EAAG;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAA,GAAoBC,SAAAA,CAAAA,GAAA,CACxBC,IAAAA,CAAAA,SAAA,CAAUJ,WAAA,CAAYK,aAAA,EAAeL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,IAAAA,CAAAA,SAAA,CAAUJ,WAAA,CAAYO,cAAA,EAAgBP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEA,MAAME,SAAA,GAAY,IAAIC,gCAAA,CAAqB;IACzCC,uBAAuBV,WAAA,CAAYO,cAAA;IACnCI,kBAAA,EAAoBC,IAAAA,CAAAA,OAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAA,CAAYM;EAAA,CACvB,CAAA;EAGD,OAAOO,MAAMC,IAAA,CAAK;IAAEC,QAAQf,WAAA,CAAYC;EAAA,GAAY,MAAM;IACxD,MAAMe,0BAA0BR,SAAA,CAAUS,QAAA,CACxCjB,WAAA,CAAYkB,SAAA,EACZlB,WAAA,CAAYM,QAAA,CACd;IAEA,MAAMD,aAAA,GAAgB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F,CAAA;AAEO,MAAMW,4BAAA,GAA+BA,CAC1ChC,WAAA,EACAqB,OAAA,EACAY,OAAA,KACS;EAET,IAAIZ,YAAY,CAAA,EAAG;IACjB,OAAOjB,cAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAEA,OAAO2B,OAAA,CAAQC,sBACXH,gCAAA,CAAiC/B,WAAA,EAAaqB,OAAO,CAAA,GACrDD,2BAAA,CAA4BpB,aAAaqB,OAAO,CAAA;AACtD,CAAA;AAEO,MAAMc,0BAAA,GAA6BA,CACxCnC,WAAA,EACAqB,OAAA,EACAY,OAAA,KACS;EAET,IAAIZ,YAAY,CAAA,EAAG;IACjB,OAAOjB,cAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGA,MAAM8B,mBAAA,GAAsBrC,6BAA6BC,WAAW,CAAA;EAGpE,IAAIqC,cAAA,GAAiBjC,IAAAA,CAAAA,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAEtD8B,mBAAA,CAAoBE,OAAA,CAAStC,YAAAA,IAAgB;IAG3C,MAAM8B,SAAA,GAAYE,4BAAA,CAChBhC,YAAAA,EACAqB,OAAA,EACAY,OAAA,CACF;IACAI,cAAA,GAAiBlC,SAAAA,CAAAA,GAAA,CAAIkC,gBAAgBP,SAAS,CAAA;EAChD,CAAC,CAAA;EAED,OAAOO,cAAA;AACT,CAAA;;;;"}
@@ -1,4 +1,4 @@
1
- import { add, subtract, dinero } from 'dinero.js';
1
+ import { add, subtract, dinero, toSnapshot } from 'dinero.js';
2
2
  import { FixedAmountAllocator } from './allocators/fixedAmount.mjs';
3
3
  import { Round } from './constants.mjs';
4
4
  import { getDinero, amount, getDineroCurrency } from './misc.mjs';
@@ -27,26 +27,40 @@ const allocatePerItemTaxableAmount = itemSummary => {
27
27
  };
28
28
  });
29
29
  };
30
- const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
31
- if (taxRate === 0) {
32
- return getDinero(0, itemSummary.currency);
33
- }
30
+ const calculateTaxOnTaxableAmount = (itemSummary, taxRate) => {
34
31
  return dinero({
35
32
  amount: Round.Financial(itemSummary.taxableAmount * taxRate),
36
33
  currency: getDineroCurrency(itemSummary.currency)
37
34
  });
38
35
  };
39
- const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
36
+ const getTaxFromFinalAmount = (amountWithTax, taxRate) => {
37
+ const snapshot = toSnapshot(amountWithTax);
38
+ const taxAmount = Round.Financial(snapshot.amount - snapshot.amount / (1 + taxRate));
39
+ return dinero({
40
+ ...snapshot,
41
+ amount: taxAmount
42
+ });
43
+ };
44
+ const calculateTaxFromTaxIncludedPrice = (itemSummary, taxRate) => {
45
+ return getTaxFromFinalAmount(getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRate);
46
+ };
47
+ const calculateWholeQtyLineItemTax = (itemSummary, taxRate, options) => {
48
+ if (taxRate === 0) {
49
+ return getDinero(0, itemSummary.currency);
50
+ }
51
+ return options.hasTaxIncludedPrice ? calculateTaxFromTaxIncludedPrice(itemSummary, taxRate) : calculateTaxOnTaxableAmount(itemSummary, taxRate);
52
+ };
53
+ const calculatePerQtyLineItemTax = (itemSummary, taxRate, options) => {
40
54
  if (taxRate === 0) {
41
55
  return getDinero(0, itemSummary.currency);
42
56
  }
43
57
  const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
44
58
  let totalTaxAmount = getDinero(0, itemSummary.currency);
45
59
  singleItemSummaries.forEach(itemSummary2 => {
46
- const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
60
+ const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate, options);
47
61
  totalTaxAmount = add(totalTaxAmount, taxAmount);
48
62
  });
49
63
  return totalTaxAmount;
50
64
  };
51
- export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax };
65
+ export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax, getTaxFromFinalAmount };
52
66
  //# 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 { 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 Dino,\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): Dino => {\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): Dino => {\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":";;;;;AAoBO,MAAMA,4BAAA,GACXC,WAAA,IAC4B;EAI5B,IAAIA,WAAA,CAAYC,aAAa,CAAA,EAAG;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAA,GAAoBC,GAAA,CACxBC,SAAA,CAAUJ,WAAA,CAAYK,aAAA,EAAeL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,SAAA,CAAUJ,WAAA,CAAYO,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AA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGA,MAAMqB,mBAAA,GAAsB5B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI4B,cAAA,GAAiBxB,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAEtDqB,mBAAA,CAAoBE,OAAA,CAAS7B,YAAAA,IAAgB;IAG3C,MAAM8B,SAAA,GAAYV,4BAAA,CAA6BpB,YAAAA,EAAaqB,OAAO,CAAA;IACnEO,cAAA,GAAiBzB,GAAA,CAAIyB,gBAAgBE,SAAS,CAAA;EAChD,CAAC,CAAA;EAED,OAAOF,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 { add, dinero, subtract, toSnapshot } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Dino,\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\nconst calculateTaxOnTaxableAmount = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\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 getTaxFromFinalAmount = (\n amountWithTax: Dino,\n taxRate: TaxRate,\n) => {\n const snapshot = toSnapshot(amountWithTax);\n\n // Calculate the tax amount and apply rounding on it so that behavior for reverse process is consistent\n const taxAmount = Round.Financial(\n snapshot.amount - snapshot.amount / (1 + taxRate),\n );\n\n return dinero({ ...snapshot, amount: taxAmount });\n};\n\nconst calculateTaxFromTaxIncludedPrice = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n) => {\n return getTaxFromFinalAmount(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n taxRate,\n );\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n options: { hasTaxIncludedPrice: boolean },\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n return options.hasTaxIncludedPrice\n ? calculateTaxFromTaxIncludedPrice(itemSummary, taxRate)\n : calculateTaxOnTaxableAmount(itemSummary, taxRate);\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n options: { hasTaxIncludedPrice: boolean },\n): Dino => {\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(\n itemSummary,\n taxRate,\n options,\n );\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","calculateTaxOnTaxableAmount","taxRate","dinero","Round","Financial","getDineroCurrency","getTaxFromFinalAmount","amountWithTax","snapshot","toSnapshot","taxAmount","calculateTaxFromTaxIncludedPrice","calculateWholeQtyLineItemTax","options","hasTaxIncludedPrice","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach"],"mappings":";;;;;AAoBO,MAAMA,4BAAA,GACXC,WAAA,IAC4B;EAI5B,IAAIA,WAAA,CAAYC,aAAa,CAAA,EAAG;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAA,GAAoBC,GAAA,CACxBC,SAAA,CAAUJ,WAAA,CAAYK,aAAA,EAAeL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,SAAA,CAAUJ,WAAA,CAAYO,cAAA,EAAgBP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEA,MAAME,SAAA,GAAY,IAAIC,oBAAA,CAAqB;IACzCC,uBAAuBV,WAAA,CAAYO,cAAA;IACnCI,kBAAA,EAAoBC,OAAOV,iBAAiB,C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H,OAAOK,qBAAA,CACLtB,SAAA,CAAUJ,WAAA,CAAYK,aAAA,EAAeL,WAAA,CAAYM,QAAQ,CAAA,EACzDe,OAAA,CACF;AACF,CAAA;AAEO,MAAMW,4BAAA,GAA+BA,CAC1ChC,WAAA,EACAqB,OAAA,EACAY,OAAA,KACS;EAET,IAAIZ,YAAY,CAAA,EAAG;IACjB,OAAOjB,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAEA,OAAO2B,OAAA,CAAQC,sBACXH,gCAAA,CAAiC/B,WAAA,EAAaqB,OAAO,CAAA,GACrDD,2BAAA,CAA4BpB,aAAaqB,OAAO,CAAA;AACtD,CAAA;AAEO,MAAMc,0BAAA,GAA6BA,CACxCnC,WAAA,EACAqB,OAAA,EACAY,OAAA,KACS;EAET,IAAIZ,YAAY,CAAA,EAAG;IACjB,OAAOjB,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGA,MAAM8B,mBAAA,GAAsBrC,6BAA6BC,WAAW,CAAA;EAGpE,IAAIqC,cAAA,GAAiBjC,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAEtD8B,mBAAA,CAAoBE,OAAA,CAAStC,YAAAA,IAAgB;IAG3C,MAAM8B,SAAA,GAAYE,4BAAA,CAChBhC,YAAAA,EACAqB,OAAA,EACAY,OAAA,CACF;IACAI,cAAA,GAAiBlC,GAAA,CAAIkC,gBAAgBP,SAAS,CAAA;EAChD,CAAC,CAAA;EAED,OAAOO,cAAA;AACT,CAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubnt/store.core",
3
- "version": "11.28.0",
3
+ "version": "11.29.0-custom-tax.0",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "scripts": {
@@ -1,2 +0,0 @@
1
- import type { BackInStockProps } from "./BackInStock.types";
2
- export declare const BackInStock: ({ className, isLoggedIn, translations, estimatedAvailability, availableInStore, disabled, isSubscribed, onLogIn, onLearnMore, onSubscribedChange, }: BackInStockProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,52 +0,0 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var BackInStock_styles = require('./BackInStock.styles.js');
5
- "use strict";
6
- const BackInStock = function BackInStock2({
7
- className,
8
- isLoggedIn,
9
- translations,
10
- estimatedAvailability,
11
- availableInStore,
12
- disabled,
13
- isSubscribed,
14
- onLogIn,
15
- onLearnMore,
16
- onSubscribedChange
17
- }) {
18
- const renderLogin = () => {
19
- return /* @__PURE__ */jsxRuntime.jsxs(BackInStock_styles.Login, {
20
- children: [/* @__PURE__ */jsxRuntime.jsx(BackInStock_styles.Button, {
21
- variant: "link",
22
- onClick: onLogIn,
23
- children: translations.logIn
24
- }), estimatedAvailability && /* @__PURE__ */jsxRuntime.jsx(BackInStock_styles.EstimatedAvailability, {
25
- children: estimatedAvailability
26
- }), translations.requiresLogin]
27
- });
28
- };
29
- const renderAvailabilityAndSubscription = () => {
30
- return /* @__PURE__ */jsxRuntime.jsxs(BackInStock_styles.AvailabilityAndSubscription, {
31
- onClick: !disabled && isLoggedIn ? onSubscribedChange : void 0,
32
- children: [/* @__PURE__ */jsxRuntime.jsx(BackInStock_styles.Checkbox, {
33
- disabled: disabled || !isLoggedIn,
34
- checked: isSubscribed,
35
- name: "backInStock",
36
- variant: "primary"
37
- }), availableInStore ? translations.notifyWhenAvailableInStore : translations.notifyWhenAvailable, estimatedAvailability && /* @__PURE__ */jsxRuntime.jsx(BackInStock_styles.EstimatedAvailability, {
38
- children: estimatedAvailability
39
- }), onLearnMore && /* @__PURE__ */jsxRuntime.jsx(BackInStock_styles.Button, {
40
- variant: "link",
41
- onClick: onLearnMore,
42
- children: translations.learnMore
43
- })]
44
- });
45
- };
46
- return /* @__PURE__ */jsxRuntime.jsx(BackInStock_styles.Wrap, {
47
- className,
48
- children: isLoggedIn ? renderAvailabilityAndSubscription() : renderLogin()
49
- });
50
- };
51
- exports.BackInStock = BackInStock;
52
- //# sourceMappingURL=BackInStock.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BackInStock.js","sources":["../../../src/components/BackInStock/BackInStock.tsx"],"sourcesContent":["import * as S from \"./BackInStock.styles\";\nimport type { BackInStockProps } from \"./BackInStock.types\";\n\nexport const BackInStock = function BackInStock({\n className,\n isLoggedIn,\n translations,\n estimatedAvailability,\n availableInStore,\n disabled,\n isSubscribed,\n onLogIn,\n onLearnMore,\n onSubscribedChange,\n}: BackInStockProps) {\n const renderLogin = () => {\n return (\n <S.Login>\n <S.Button variant=\"link\" onClick={onLogIn}>\n {translations.logIn}\n </S.Button>\n {estimatedAvailability && (\n <S.EstimatedAvailability>\n {estimatedAvailability}\n </S.EstimatedAvailability>\n )}\n {translations.requiresLogin}\n </S.Login>\n );\n };\n const renderAvailabilityAndSubscription = () => {\n return (\n <S.AvailabilityAndSubscription\n onClick={!disabled && isLoggedIn ? onSubscribedChange : undefined}\n >\n <S.Checkbox\n disabled={disabled || !isLoggedIn}\n checked={isSubscribed}\n name=\"backInStock\"\n variant=\"primary\"\n />\n {availableInStore\n ? translations.notifyWhenAvailableInStore\n : translations.notifyWhenAvailable}\n {estimatedAvailability && (\n <S.EstimatedAvailability>\n {estimatedAvailability}\n </S.EstimatedAvailability>\n )}\n {onLearnMore && (\n <S.Button variant=\"link\" onClick={onLearnMore}>\n {translations.learnMore}\n </S.Button>\n )}\n </S.AvailabilityAndSubscription>\n );\n };\n\n // #############################################################################\n // Render\n // #############################################################################\n return (\n <S.Wrap className={className}>\n {isLoggedIn ? renderAvailabilityAndSubscription() : renderLogin()}\n </S.Wrap>\n );\n};\n"],"names":["BackInStock","className","isLoggedIn","translations","estimatedAvailability","availableInStore","disabled","isSubscribed","onLogIn","onLearnMore","onSubscribedChange","renderLogin","jsxs","S.Login","children","jsx","S.Button","variant","onClick","logIn","S.EstimatedAvailability","requiresLogin","renderAvailabilityAndSubscription","S.AvailabilityAndSubscription","S.Checkbox","checked","name","notifyWhenAvailableInStore","notifyWhenAvailable","learnMore","S.Wrap"],"mappings":";;;;;AAGO,MAAMA,WAAA,GAAc,SAASA,YAAAA,CAAY;EAC9CC,SAAA;EACAC,UAAA;EACAC,YAAA;EACAC,qBAAA;EACAC,gBAAA;EACAC,QAAA;EACAC,YAAA;EACAC,OAAA;EACAC,WAAA;EACAC;AACF,CAAA,EAAqB;EACnB,MAAMC,cAAcA,CAAA,KAAM;IACxB,sBACEC,UAAAA,CAAAA,IAAA,CAACC,wBAAE,EAAF;MACCC,QAAA,EAAA,CAAA,eAAAC,cAAA,CAACC,kBAAAA,CAAAA,QAAA;QAASC,OAAA,EAAQ;QAAOC,OAAA,EAASV,OAAA;QAC/BM,uBAAaK;OAChB,CAAA,EACCf,qBAAA,IAAA,eACCW,UAAAA,CAAAA,GAAA,CAACK,kBAAAA,CAAAA,qBAAE,EAAF;QACEN,QAAA,EAAAV;MAAA,CACH,CAAA,EAEDD,YAAA,CAAakB,aAAA;KAChB,CAAA;EAEJ,CAAA;EACA,MAAMC,oCAAoCA,CAAA,KAAM;IAC9C,sBACEV,UAAAA,CAAAA,IAAA,CAACW,kBAAAA,CAAAA,2BAAE,EAAF;MACCL,OAAA,EAAS,CAACZ,QAAA,IAAYJ,UAAA,GAAaQ,kBAAA,GAAqB,KAAA,CAAA;MAExDI,QAAA,EAAA,CAAA,eAAAC,UAAAA,CAAAA,GAAA,CAACS,kBAAAA,CAAAA,QAAE,EAAF;QACClB,QAAA,EAAUA,YAAY,CAACJ,UAAA;QACvBuB,OAAA,EAASlB,YAAA;QACTmB,IAAA,EAAK,aAAA;QACLT,OAAA,EAAQ;MAAA,CAAA,CACV,EACCZ,gBAAA,GACGF,YAAA,CAAawB,0BAAA,GACbxB,YAAA,CAAayB,mBAAA,EAChBxB,qBAAA,IAAA,eACCW,UAAAA,CAAAA,GAAA,CAACK,kBAAAA,CAAAA,qBAAE,EAAF;QACEN,QAAA,EAAAV;MAAA,CACH,CAAA,EAEDK,WAAA,mBACCM,UAAAA,CAAAA,GAAA,CAACC,yBAAE,EAAF;QAASC,SAAQ,MAAA;QAAOC,OAAA,EAAST,WAAA;QAC/BK,QAAA,EAAAX,YAAA,CAAa0B;MAAA,CAChB,CAAA;IAAA,CAAA,CAEJ;EAEJ,CAAA;EAKA,sBACEd,UAAAA,CAAAA,GAAA,CAACe,uBAAE,EAAF;IAAO7B;IACLa,QAAA,EAAAZ,UAAA,GAAaoB,iCAAA,CAAA,CAAkC,GAAIX,WAAA,CAAA;GACtD,CAAA;AAEJ,CAAA;"}
@@ -1,50 +0,0 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { Login, Button, EstimatedAvailability, AvailabilityAndSubscription, Checkbox, Wrap } from './BackInStock.styles.mjs';
3
- "use strict";
4
- const BackInStock = function BackInStock2({
5
- className,
6
- isLoggedIn,
7
- translations,
8
- estimatedAvailability,
9
- availableInStore,
10
- disabled,
11
- isSubscribed,
12
- onLogIn,
13
- onLearnMore,
14
- onSubscribedChange
15
- }) {
16
- const renderLogin = () => {
17
- return /* @__PURE__ */jsxs(Login, {
18
- children: [/* @__PURE__ */jsx(Button, {
19
- variant: "link",
20
- onClick: onLogIn,
21
- children: translations.logIn
22
- }), estimatedAvailability && /* @__PURE__ */jsx(EstimatedAvailability, {
23
- children: estimatedAvailability
24
- }), translations.requiresLogin]
25
- });
26
- };
27
- const renderAvailabilityAndSubscription = () => {
28
- return /* @__PURE__ */jsxs(AvailabilityAndSubscription, {
29
- onClick: !disabled && isLoggedIn ? onSubscribedChange : void 0,
30
- children: [/* @__PURE__ */jsx(Checkbox, {
31
- disabled: disabled || !isLoggedIn,
32
- checked: isSubscribed,
33
- name: "backInStock",
34
- variant: "primary"
35
- }), availableInStore ? translations.notifyWhenAvailableInStore : translations.notifyWhenAvailable, estimatedAvailability && /* @__PURE__ */jsx(EstimatedAvailability, {
36
- children: estimatedAvailability
37
- }), onLearnMore && /* @__PURE__ */jsx(Button, {
38
- variant: "link",
39
- onClick: onLearnMore,
40
- children: translations.learnMore
41
- })]
42
- });
43
- };
44
- return /* @__PURE__ */jsx(Wrap, {
45
- className,
46
- children: isLoggedIn ? renderAvailabilityAndSubscription() : renderLogin()
47
- });
48
- };
49
- export { BackInStock };
50
- //# sourceMappingURL=BackInStock.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BackInStock.mjs","sources":["../../../src/components/BackInStock/BackInStock.tsx"],"sourcesContent":["import * as S from \"./BackInStock.styles\";\nimport type { BackInStockProps } from \"./BackInStock.types\";\n\nexport const BackInStock = function BackInStock({\n className,\n isLoggedIn,\n translations,\n estimatedAvailability,\n availableInStore,\n disabled,\n isSubscribed,\n onLogIn,\n onLearnMore,\n onSubscribedChange,\n}: BackInStockProps) {\n const renderLogin = () => {\n return (\n <S.Login>\n <S.Button variant=\"link\" onClick={onLogIn}>\n {translations.logIn}\n </S.Button>\n {estimatedAvailability && (\n <S.EstimatedAvailability>\n {estimatedAvailability}\n </S.EstimatedAvailability>\n )}\n {translations.requiresLogin}\n </S.Login>\n );\n };\n const renderAvailabilityAndSubscription = () => {\n return (\n <S.AvailabilityAndSubscription\n onClick={!disabled && isLoggedIn ? onSubscribedChange : undefined}\n >\n <S.Checkbox\n disabled={disabled || !isLoggedIn}\n checked={isSubscribed}\n name=\"backInStock\"\n variant=\"primary\"\n />\n {availableInStore\n ? translations.notifyWhenAvailableInStore\n : translations.notifyWhenAvailable}\n {estimatedAvailability && (\n <S.EstimatedAvailability>\n {estimatedAvailability}\n </S.EstimatedAvailability>\n )}\n {onLearnMore && (\n <S.Button variant=\"link\" onClick={onLearnMore}>\n {translations.learnMore}\n </S.Button>\n )}\n </S.AvailabilityAndSubscription>\n );\n };\n\n // #############################################################################\n // Render\n // #############################################################################\n return (\n <S.Wrap className={className}>\n {isLoggedIn ? renderAvailabilityAndSubscription() : renderLogin()}\n </S.Wrap>\n );\n};\n"],"names":["BackInStock","className","isLoggedIn","translations","estimatedAvailability","availableInStore","disabled","isSubscribed","onLogIn","onLearnMore","onSubscribedChange","renderLogin","jsxs","S.Login","children","jsx","S.Button","variant","onClick","logIn","S.EstimatedAvailability","requiresLogin","renderAvailabilityAndSubscription","S.AvailabilityAndSubscription","S.Checkbox","checked","name","notifyWhenAvailableInStore","notifyWhenAvailable","learnMore","S.Wrap"],"mappings":";;;AAGO,MAAMA,WAAA,GAAc,SAASA,YAAAA,CAAY;EAC9CC,SAAA;EACAC,UAAA;EACAC,YAAA;EACAC,qBAAA;EACAC,gBAAA;EACAC,QAAA;EACAC,YAAA;EACAC,OAAA;EACAC,WAAA;EACAC;AACF,CAAA,EAAqB;EACnB,MAAMC,cAAcA,CAAA,KAAM;IACxB,sBACEC,IAAA,CAACC,KAAE,EAAF;MACCC,QAAA,EAAA,CAAA,eAAAC,GAAA,CAACC,QAAA;QAASC,OAAA,EAAQ;QAAOC,OAAA,EAASV,OAAA;QAC/BM,uBAAaK;OAChB,CAAA,EACCf,qBAAA,IAAA,eACCW,GAAA,CAACK,qBAAE,EAAF;QACEN,QAAA,EAAAV;MAAA,CACH,CAAA,EAEDD,YAAA,CAAakB,aAAA;KAChB,CAAA;EAEJ,CAAA;EACA,MAAMC,oCAAoCA,CAAA,KAAM;IAC9C,sBACEV,IAAA,CAACW,2BAAE,EAAF;MACCL,OAAA,EAAS,CAACZ,QAAA,IAAYJ,UAAA,GAAaQ,kBAAA,GAAqB,KAAA,CAAA;MAExDI,QAAA,EAAA,CAAA,eAAAC,GAAA,CAACS,QAAE,EAAF;QACClB,QAAA,EAAUA,YAAY,CAACJ,UAAA;QACvBuB,OAAA,EAASlB,YAAA;QACTmB,IAAA,EAAK,aAAA;QACLT,OAAA,EAAQ;MAAA,CAAA,CACV,EACCZ,gBAAA,GACGF,YAAA,CAAawB,0BAAA,GACbxB,YAAA,CAAayB,mBAAA,EAChBxB,qBAAA,IAAA,eACCW,GAAA,CAACK,qBAAE,EAAF;QACEN,QAAA,EAAAV;MAAA,CACH,CAAA,EAEDK,WAAA,mBACCM,GAAA,CAACC,MAAE,EAAF;QAASC,SAAQ,MAAA;QAAOC,OAAA,EAAST,WAAA;QAC/BK,QAAA,EAAAX,YAAA,CAAa0B;MAAA,CAChB,CAAA;IAAA,CAAA,CAEJ;EAEJ,CAAA;EAKA,sBACEd,GAAA,CAACe,IAAE,EAAF;IAAO7B;IACLa,QAAA,EAAAZ,UAAA,GAAaoB,iCAAA,CAAA,CAAkC,GAAIX,WAAA,CAAA;GACtD,CAAA;AAEJ,CAAA;"}
@@ -1,13 +0,0 @@
1
- export declare const Wrap: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
2
- export declare const Button: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("../Button/Button.types").ButtonProps & {
3
- children?: import("react").ReactNode | undefined;
4
- } & import("react").RefAttributes<HTMLAnchorElement | HTMLButtonElement | HTMLSpanElement | null>, never>> & string & Omit<import("react").ForwardRefExoticComponent<import("../Button/Button.types").ButtonProps & {
5
- children?: import("react").ReactNode | undefined;
6
- } & import("react").RefAttributes<HTMLAnchorElement | HTMLButtonElement | HTMLSpanElement | null>>, keyof import("react").Component<any, {}, any>>;
7
- export declare const AvailabilityAndSubscription: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
8
- export declare const Login: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
9
- export declare const EstimatedAvailability: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
10
- export declare const Checkbox: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<Omit<import("@ubnt/ui-components").CheckboxProps, "id"> & {
11
- name: string;
12
- radio?: boolean;
13
- }, never>> & string & Omit<({ radio, ...props }: import("../Checkbox/Checkbox.types").CheckboxProps) => import("react/jsx-runtime").JSX.Element, keyof import("react").Component<any, {}, any>>;
@@ -1,53 +0,0 @@
1
- 'use strict';
2
-
3
- var styledComponents = require('styled-components');
4
- var theme = require('../../constants/theme.js');
5
- require('../Button/index.js');
6
- require('../Checkbox/index.js');
7
- var Button$1 = require('../Button/Button.js');
8
- var Checkbox$1 = require('../Checkbox/Checkbox.js');
9
- "use strict";
10
- const cssText = styledComponents.css`
11
- font-size: ${theme.theme.font.size14};
12
- line-height: 1.22; /* 17/14 */
13
- letter-spacing: -0.02em;
14
- color: ${theme.theme.colors.black45};
15
- `;
16
- const Wrap = styledComponents.styled.div``;
17
- const Button = styledComponents.styled(Button$1.Button)`
18
- ${cssText}
19
-
20
- color: ${theme.theme.colors.primaryBlue};
21
- `;
22
- const AvailabilityAndSubscription = styledComponents.styled.div`
23
- ${cssText}
24
-
25
- display: flex;
26
- align-items: center;
27
- gap: 8px;
28
- height: 40px;
29
-
30
- cursor: ${({
31
- onClick
32
- }) => onClick ? "pointer" : "default"};
33
- `;
34
- const Login = styledComponents.styled.div`
35
- ${cssText}
36
-
37
- display: flex;
38
- flex-direction: column;
39
- align-items: flex-start;
40
- justify-content: center;
41
- gap: 2px;
42
- `;
43
- const EstimatedAvailability = styledComponents.styled.div``;
44
- const Checkbox = styledComponents.styled(Checkbox$1.Checkbox)`
45
- margin: 10px 0;
46
- `;
47
- exports.AvailabilityAndSubscription = AvailabilityAndSubscription;
48
- exports.Button = Button;
49
- exports.Checkbox = Checkbox;
50
- exports.EstimatedAvailability = EstimatedAvailability;
51
- exports.Login = Login;
52
- exports.Wrap = Wrap;
53
- //# sourceMappingURL=BackInStock.styles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BackInStock.styles.js","sources":["../../../src/components/BackInStock/BackInStock.styles.ts"],"sourcesContent":["import { css, styled } from \"styled-components\";\n\nimport { theme } from \"../../constants/theme\";\nimport { Button as ButtonBase } from \"../Button\";\nimport { Checkbox as CheckboxBase } from \"../Checkbox\";\n\nconst cssText = css`\n font-size: ${theme.font.size14};\n line-height: 1.22; /* 17/14 */\n letter-spacing: -0.02em;\n color: ${theme.colors.black45};\n`;\n\nexport const Wrap = styled.div``;\n\nexport const Button = styled(ButtonBase)`\n ${cssText}\n\n color: ${theme.colors.primaryBlue};\n`;\n\nexport const AvailabilityAndSubscription = styled.div`\n ${cssText}\n\n display: flex;\n align-items: center;\n gap: 8px;\n height: 40px;\n\n cursor: ${({ onClick }) => (onClick ? \"pointer\" : \"default\")};\n`;\n\nexport const Login = styled.div`\n ${cssText}\n\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n justify-content: center;\n gap: 2px;\n`;\n\nexport const EstimatedAvailability = styled.div``;\n\nexport const Checkbox = styled(CheckboxBase)`\n margin: 10px 0;\n`;\n"],"names":["cssText","css","theme","font","size14","colors","black45","Wrap","styled","div","Button","ButtonBase","primaryBlue","AvailabilityAndSubscription","onClick","Login","EstimatedAvailability","Checkbox","CheckboxBase"],"mappings":";;;;;;;;;AAMA,MAAMA,OAAA,GAAUC,gBAAAA,CAAAA,GAAA;AAAA,eACDC,KAAAA,CAAAA,KAAA,CAAMC,KAAKC,MAAM;AAAA;AAAA;AAAA,WAGrBF,KAAAA,CAAAA,KAAA,CAAMG,OAAOC,OAAO;AAAA,CAAA;AAGxB,MAAMC,OAAOC,gBAAAA,CAAAA,MAAA,CAAOC,GAAA,EAAA;AAEpB,MAAMC,MAAA,GAASF,gBAAAA,CAAAA,OAAOG,eAAU,CAAA;AAAA,IACnCX,OAAO;;AAAA,WAEAE,KAAAA,CAAAA,KAAA,CAAMG,OAAOO,WAAW;AAAA,CAAA;AAG5B,MAAMC,8BAA8BL,gBAAAA,CAAAA,MAAA,CAAOC,GAAA;AAAA,IAC9CT,OAAO;;AAAA;AAAA;AAAA;AAAA;;AAAA,YAOC,CAAC;EAAEc;AAAA,CAAQ,KAAOA,OAAA,GAAU,YAAY,SAAU;AAAA,CAAA;AAGvD,MAAMC,QAAQP,gBAAAA,CAAAA,MAAA,CAAOC,GAAA;AAAA,IACxBT,OAAO;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA;AASJ,MAAMgB,wBAAwBR,gBAAAA,CAAAA,MAAA,CAAOC,GAAA,EAAA;AAErC,MAAMQ,QAAA,GAAWT,gBAAAA,CAAAA,OAAOU,mBAAY,CAAA;AAAA;AAAA,CAAA;;;;;;"}
@@ -1,46 +0,0 @@
1
- import { css, styled } from 'styled-components';
2
- import { theme } from '../../constants/theme.mjs';
3
- import '../Button/index.mjs';
4
- import '../Checkbox/index.mjs';
5
- import { Button as Button$1 } from '../Button/Button.mjs';
6
- import { Checkbox as Checkbox$1 } from '../Checkbox/Checkbox.mjs';
7
- "use strict";
8
- const cssText = css`
9
- font-size: ${theme.font.size14};
10
- line-height: 1.22; /* 17/14 */
11
- letter-spacing: -0.02em;
12
- color: ${theme.colors.black45};
13
- `;
14
- const Wrap = styled.div``;
15
- const Button = styled(Button$1)`
16
- ${cssText}
17
-
18
- color: ${theme.colors.primaryBlue};
19
- `;
20
- const AvailabilityAndSubscription = styled.div`
21
- ${cssText}
22
-
23
- display: flex;
24
- align-items: center;
25
- gap: 8px;
26
- height: 40px;
27
-
28
- cursor: ${({
29
- onClick
30
- }) => onClick ? "pointer" : "default"};
31
- `;
32
- const Login = styled.div`
33
- ${cssText}
34
-
35
- display: flex;
36
- flex-direction: column;
37
- align-items: flex-start;
38
- justify-content: center;
39
- gap: 2px;
40
- `;
41
- const EstimatedAvailability = styled.div``;
42
- const Checkbox = styled(Checkbox$1)`
43
- margin: 10px 0;
44
- `;
45
- export { AvailabilityAndSubscription, Button, Checkbox, EstimatedAvailability, Login, Wrap };
46
- //# sourceMappingURL=BackInStock.styles.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BackInStock.styles.mjs","sources":["../../../src/components/BackInStock/BackInStock.styles.ts"],"sourcesContent":["import { css, styled } from \"styled-components\";\n\nimport { theme } from \"../../constants/theme\";\nimport { Button as ButtonBase } from \"../Button\";\nimport { Checkbox as CheckboxBase } from \"../Checkbox\";\n\nconst cssText = css`\n font-size: ${theme.font.size14};\n line-height: 1.22; /* 17/14 */\n letter-spacing: -0.02em;\n color: ${theme.colors.black45};\n`;\n\nexport const Wrap = styled.div``;\n\nexport const Button = styled(ButtonBase)`\n ${cssText}\n\n color: ${theme.colors.primaryBlue};\n`;\n\nexport const AvailabilityAndSubscription = styled.div`\n ${cssText}\n\n display: flex;\n align-items: center;\n gap: 8px;\n height: 40px;\n\n cursor: ${({ onClick }) => (onClick ? \"pointer\" : \"default\")};\n`;\n\nexport const Login = styled.div`\n ${cssText}\n\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n justify-content: center;\n gap: 2px;\n`;\n\nexport const EstimatedAvailability = styled.div``;\n\nexport const Checkbox = styled(CheckboxBase)`\n margin: 10px 0;\n`;\n"],"names":["cssText","css","theme","font","size14","colors","black45","Wrap","styled","div","Button","ButtonBase","primaryBlue","AvailabilityAndSubscription","onClick","Login","EstimatedAvailability","Checkbox","CheckboxBase"],"mappings":";;;;;;;AAMA,MAAMA,OAAA,GAAUC,GAAA;AAAA,eACDC,KAAA,CAAMC,KAAKC,MAAM;AAAA;AAAA;AAAA,WAGrBF,KAAA,CAAMG,OAAOC,OAAO;AAAA,CAAA;AAGxB,MAAMC,OAAOC,MAAA,CAAOC,GAAA,EAAA;AAEpB,MAAMC,MAAA,GAASF,OAAOG,QAAU,CAAA;AAAA,IACnCX,OAAO;;AAAA,WAEAE,KAAA,CAAMG,OAAOO,WAAW;AAAA,CAAA;AAG5B,MAAMC,8BAA8BL,MAAA,CAAOC,GAAA;AAAA,IAC9CT,OAAO;;AAAA;AAAA;AAAA;AAAA;;AAAA,YAOC,CAAC;EAAEc;AAAA,CAAQ,KAAOA,OAAA,GAAU,YAAY,SAAU;AAAA,CAAA;AAGvD,MAAMC,QAAQP,MAAA,CAAOC,GAAA;AAAA,IACxBT,OAAO;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA;AASJ,MAAMgB,wBAAwBR,MAAA,CAAOC,GAAA,EAAA;AAErC,MAAMQ,QAAA,GAAWT,OAAOU,UAAY,CAAA;AAAA;AAAA,CAAA;"}
@@ -1,27 +0,0 @@
1
- import type { StoreId } from "../../types";
2
- export interface BackInStockProps {
3
- className?: string;
4
- isLoggedIn: boolean;
5
- translations: BackInStockTranslations;
6
- estimatedAvailability?: React.ReactNode | string;
7
- disabled?: boolean;
8
- onLogIn: () => void;
9
- onLearnMore?: () => void;
10
- onSubscribedChange: () => Promise<void>;
11
- isSubscribed: boolean;
12
- availableInStore?: {
13
- currentStoreName: string;
14
- storeName: string;
15
- storeId: StoreId;
16
- url: string;
17
- };
18
- loading?: boolean;
19
- }
20
- interface BackInStockTranslations {
21
- logIn: string;
22
- requiresLogin: string;
23
- notifyWhenAvailable: string;
24
- notifyWhenAvailableInStore: string | React.ReactNode;
25
- learnMore: string;
26
- }
27
- export {};
@@ -1 +0,0 @@
1
- export * from "./BackInStock";
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- var BackInStock = require('./BackInStock.js');
4
- "use strict";
5
- exports.BackInStock = BackInStock.BackInStock;
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,3 +0,0 @@
1
- export { BackInStock } from './BackInStock.mjs';
2
- "use strict";
3
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}