@ubnt/store.core 9.27.0-beta.1 → 9.27.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 (129) hide show
  1. package/CHANGELOG.md +3 -27
  2. package/lib/_virtual/_virtual_multi-entry.js +2 -15
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +0 -2
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/udmPro.jpg +0 -0
  7. package/lib/assets/udmPro2.jpg +0 -0
  8. package/lib/assets/udmProSpecial.jpg +0 -0
  9. package/lib/assets/udmProSpecial2.jpg +0 -0
  10. package/lib/components/Button/CartButton.d.ts +11 -1
  11. package/lib/components/Button/CartButton.js +43 -5
  12. package/lib/components/Button/CartButton.js.map +1 -1
  13. package/lib/components/Button/CartButton.mjs +43 -5
  14. package/lib/components/Button/CartButton.mjs.map +1 -1
  15. package/lib/components/Header/CartModalV2/Item/Item.styles.d.ts +1 -1
  16. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
  17. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
  18. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
  19. package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
  20. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
  21. package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
  22. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
  23. package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
  24. package/lib/components/ModelCompareV3/data/CloudGateways.js +6 -6
  25. package/lib/components/ModelCompareV3/data/CloudGateways.mjs +4 -4
  26. package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
  27. package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
  28. package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
  29. package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +1 -1
  30. package/lib/constants/proStoreCategories/mapping/index.d.ts +0 -2
  31. package/lib/constants/proStoreCategories/mapping/index.js +54 -48
  32. package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
  33. package/lib/constants/proStoreCategories/mapping/index.mjs +54 -48
  34. package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
  35. package/lib/constants/proStoreCategories/mapping/redirects.js +1 -9
  36. package/lib/constants/proStoreCategories/mapping/redirects.js.map +1 -1
  37. package/lib/constants/proStoreCategories/mapping/redirects.mjs +1 -9
  38. package/lib/constants/proStoreCategories/mapping/redirects.mjs.map +1 -1
  39. package/lib/constants/proStoreCategories/mapping/unifi.d.ts +4 -4
  40. package/lib/constants/proStoreCategories/mapping/unifi.js +3 -3
  41. package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
  42. package/lib/constants/proStoreCategories/mapping/unifi.mjs +3 -3
  43. package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
  44. package/lib/constants/proStoreCategories/translations/ar.json.js +1 -2
  45. package/lib/constants/proStoreCategories/translations/ar.json.js.map +1 -1
  46. package/lib/constants/proStoreCategories/translations/ar.json.mjs +1 -2
  47. package/lib/constants/proStoreCategories/translations/ar.json.mjs.map +1 -1
  48. package/lib/constants/proStoreCategories/translations/de.json.js +1 -2
  49. package/lib/constants/proStoreCategories/translations/de.json.js.map +1 -1
  50. package/lib/constants/proStoreCategories/translations/de.json.mjs +1 -2
  51. package/lib/constants/proStoreCategories/translations/de.json.mjs.map +1 -1
  52. package/lib/constants/proStoreCategories/translations/el.json.js +1 -2
  53. package/lib/constants/proStoreCategories/translations/el.json.js.map +1 -1
  54. package/lib/constants/proStoreCategories/translations/el.json.mjs +1 -2
  55. package/lib/constants/proStoreCategories/translations/el.json.mjs.map +1 -1
  56. package/lib/constants/proStoreCategories/translations/en.json.js +0 -4
  57. package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
  58. package/lib/constants/proStoreCategories/translations/en.json.mjs +1 -4
  59. package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
  60. package/lib/constants/proStoreCategories/translations/es.json.js +1 -2
  61. package/lib/constants/proStoreCategories/translations/es.json.js.map +1 -1
  62. package/lib/constants/proStoreCategories/translations/es.json.mjs +1 -2
  63. package/lib/constants/proStoreCategories/translations/es.json.mjs.map +1 -1
  64. package/lib/constants/proStoreCategories/translations/fr.json.js +2 -3
  65. package/lib/constants/proStoreCategories/translations/fr.json.js.map +1 -1
  66. package/lib/constants/proStoreCategories/translations/fr.json.mjs +2 -3
  67. package/lib/constants/proStoreCategories/translations/fr.json.mjs.map +1 -1
  68. package/lib/constants/proStoreCategories/translations/it.json.js +1 -2
  69. package/lib/constants/proStoreCategories/translations/it.json.js.map +1 -1
  70. package/lib/constants/proStoreCategories/translations/it.json.mjs +1 -2
  71. package/lib/constants/proStoreCategories/translations/it.json.mjs.map +1 -1
  72. package/lib/constants/proStoreCategories/translations/ja.json.js +1 -2
  73. package/lib/constants/proStoreCategories/translations/ja.json.js.map +1 -1
  74. package/lib/constants/proStoreCategories/translations/ja.json.mjs +1 -2
  75. package/lib/constants/proStoreCategories/translations/ja.json.mjs.map +1 -1
  76. package/lib/constants/proStoreCategories/translations/pt-BR.json.js +1 -2
  77. package/lib/constants/proStoreCategories/translations/pt-BR.json.js.map +1 -1
  78. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs +1 -2
  79. package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs.map +1 -1
  80. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +2 -3
  81. package/lib/constants/proStoreCategories/translations/zh-Hans.json.js.map +1 -1
  82. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +2 -3
  83. package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs.map +1 -1
  84. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +2 -3
  85. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js.map +1 -1
  86. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +2 -3
  87. package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs.map +1 -1
  88. package/lib/helpers/index.d.ts +0 -1
  89. package/lib/helpers/index.js +0 -11
  90. package/lib/helpers/index.js.map +1 -1
  91. package/lib/helpers/index.mjs +0 -1
  92. package/lib/helpers/index.mjs.map +1 -1
  93. package/lib/types/index.d.ts +0 -1
  94. package/lib/types/index.js +0 -2
  95. package/lib/types/index.js.map +1 -1
  96. package/lib/types/index.mjs +0 -1
  97. package/lib/types/index.mjs.map +1 -1
  98. package/lib/utils/array.d.ts +0 -4
  99. package/lib/utils/array.js +0 -10
  100. package/lib/utils/array.js.map +1 -1
  101. package/lib/utils/array.mjs +1 -10
  102. package/lib/utils/array.mjs.map +1 -1
  103. package/lib/utils/money/constants.d.ts +0 -7
  104. package/lib/utils/money/constants.js +1 -9
  105. package/lib/utils/money/constants.js.map +1 -1
  106. package/lib/utils/money/constants.mjs +2 -10
  107. package/lib/utils/money/constants.mjs.map +1 -1
  108. package/lib/utils/money/tax.private.d.ts +8 -0
  109. package/lib/utils/money/tax.private.js +14 -5
  110. package/lib/utils/money/tax.private.js.map +1 -1
  111. package/lib/utils/money/tax.private.mjs +16 -8
  112. package/lib/utils/money/tax.private.mjs.map +1 -1
  113. package/package.json +51 -51
  114. package/lib/helpers/product.d.ts +0 -87
  115. package/lib/helpers/product.js +0 -346
  116. package/lib/helpers/product.js.map +0 -1
  117. package/lib/helpers/product.mjs +0 -335
  118. package/lib/helpers/product.mjs.map +0 -1
  119. package/lib/helpers/product.test.d.ts +0 -1
  120. package/lib/types/product.d.ts +0 -87
  121. package/lib/types/product.js +0 -14
  122. package/lib/types/product.js.map +0 -1
  123. package/lib/types/product.mjs +0 -13
  124. package/lib/types/product.mjs.map +0 -1
  125. package/lib/utils/productSort.d.ts +0 -41
  126. package/lib/utils/productSort.js +0 -67
  127. package/lib/utils/productSort.js.map +0 -1
  128. package/lib/utils/productSort.mjs +0 -60
  129. package/lib/utils/productSort.mjs.map +0 -1
@@ -22,7 +22,7 @@ var Installations = "安装";
22
22
  var Intercoms = "对讲机";
23
23
  var Kits = "套件";
24
24
  var Mounting = "安装方式";
25
- var NAS = "NAS";
25
+ var NAS = "网络附加存储";
26
26
  var Other = "其他";
27
27
  var Outdoor = "室外";
28
28
  var PTZ = "PTZ";
@@ -142,8 +142,7 @@ var zhHans = {
142
142
  "airMAX 2.4 GHz": "airMAX 2.4 GHz",
143
143
  "airMAX 3 GHz": "airMAX 3 GHz",
144
144
  "airMAX 5 GHz": "airMAX 5 GHz",
145
- "airMAX 60 GHz": "airMAX 60 GHz",
146
- "Enterprise Campus": "企业校园"
145
+ "airMAX 60 GHz": "airMAX 60 GHz"
147
146
  };
148
147
  export { ATA, Accessories, Aggregation, All, Antennas, Apparel, Bullet, Cabling, Compact, Converters, Dome, Doorbells, Enterprise, Ethernet, Executive, Express, Fiber, Flagship, GPON, Hubs, Installations, Intercoms, Kits, Mounting, NAS, Other, Outdoor, PTZ, Professional, Readers, Standard, Storage, Switching, Theta, Ultra, Utility, Wall, WiFi, Wired, Wireless, zhHans as default };
149
148
  //# sourceMappingURL=zh-Hans.json.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"zh-Hans.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"zh-Hans.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -27,7 +27,7 @@ var Installations = "安裝配件";
27
27
  var Intercoms = "對講機";
28
28
  var Kits = "套組";
29
29
  var Mounting = "安裝配件";
30
- var NAS = "NAS";
30
+ var NAS = "網路附加儲存";
31
31
  var Other = "其他";
32
32
  var Outdoor = "戶外適用";
33
33
  var PTZ = "PTZ";
@@ -147,8 +147,7 @@ var zhHantTW = {
147
147
  "airMAX 2.4 GHz": "airMAX 2.4 GHz",
148
148
  "airMAX 3 GHz": "airMAX 3 GHz",
149
149
  "airMAX 5 GHz": "airMAX 5 GHz",
150
- "airMAX 60 GHz": "airMAX 60 GHz",
151
- "Enterprise Campus": "企業校園"
150
+ "airMAX 60 GHz": "airMAX 60 GHz"
152
151
  };
153
152
  exports.ATA = ATA;
154
153
  exports.Accessories = Accessories;
@@ -1 +1 @@
1
- {"version":3,"file":"zh-Hant-TW.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"zh-Hant-TW.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -22,7 +22,7 @@ var Installations = "安裝配件";
22
22
  var Intercoms = "對講機";
23
23
  var Kits = "套組";
24
24
  var Mounting = "安裝配件";
25
- var NAS = "NAS";
25
+ var NAS = "網路附加儲存";
26
26
  var Other = "其他";
27
27
  var Outdoor = "戶外適用";
28
28
  var PTZ = "PTZ";
@@ -142,8 +142,7 @@ var zhHantTW = {
142
142
  "airMAX 2.4 GHz": "airMAX 2.4 GHz",
143
143
  "airMAX 3 GHz": "airMAX 3 GHz",
144
144
  "airMAX 5 GHz": "airMAX 5 GHz",
145
- "airMAX 60 GHz": "airMAX 60 GHz",
146
- "Enterprise Campus": "企業校園"
145
+ "airMAX 60 GHz": "airMAX 60 GHz"
147
146
  };
148
147
  export { ATA, Accessories, Aggregation, All, Antennas, Apparel, Bullet, Cabling, Compact, Converters, Dome, Doorbells, Enterprise, Ethernet, Executive, Express, Fiber, Flagship, GPON, Hubs, Installations, Intercoms, Kits, Mounting, NAS, Other, Outdoor, PTZ, Professional, Readers, Standard, Storage, Switching, Theta, Ultra, Utility, Wall, WiFi, Wired, Wireless, zhHantTW as default };
149
148
  //# sourceMappingURL=zh-Hant-TW.json.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"zh-Hant-TW.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"zh-Hant-TW.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,2 +1 @@
1
1
  export * from "./proStoreCategories";
2
- export * from "./product";
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var proStoreCategories = require('./proStoreCategories.js');
4
- var product = require('./product.js');
5
4
  "use strict";
6
5
  exports.getCategoriesBySubcategory = proStoreCategories.getCategoriesBySubcategory;
7
6
  exports.getLocalizedCategories = proStoreCategories.getLocalizedCategories;
@@ -11,14 +10,4 @@ exports.getSubCategoryIdByCollectionSlug = proStoreCategories.getSubCategoryIdBy
11
10
  exports.isValidSubCategory = proStoreCategories.isValidSubCategory;
12
11
  exports.parseCategories = proStoreCategories.parseCategories;
13
12
  exports.useTranslatedCategories = proStoreCategories.useTranslatedCategories;
14
- exports.COLLECTION_SECTION_OTHER_ID = product.COLLECTION_SECTION_OTHER_ID;
15
- exports.HDDProductSlugs = product.HDDProductSlugs;
16
- exports.MagicCollectionTags = product.MagicCollectionTags;
17
- exports.ProductOptions = product.ProductOptions;
18
- exports.createSectionHierarchy = product.createSectionHierarchy;
19
- exports.getProStoreCategory = product.getProStoreCategory;
20
- exports.getProductGroups = product.getProductGroups;
21
- exports.getStoreProducts = product.getStoreProducts;
22
- exports.isNonNullish = product.isNonNullish;
23
- exports.removeExcludedProducts = product.removeExcludedProducts;
24
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -1,4 +1,3 @@
1
1
  export { getCategoriesBySubcategory, getLocalizedCategories, getProductLineByCategory, getProductLineBySubcategory, getSubCategoryIdByCollectionSlug, isValidSubCategory, parseCategories, useTranslatedCategories } from './proStoreCategories.mjs';
2
- export { COLLECTION_SECTION_OTHER_ID, HDDProductSlugs, MagicCollectionTags, ProductOptions, createSectionHierarchy, getProStoreCategory, getProductGroups, getStoreProducts, isNonNullish, removeExcludedProducts } from './product.mjs';
3
2
  "use strict";
4
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -3,4 +3,3 @@ export * from "./constants";
3
3
  export * from "./generated";
4
4
  export * from "./object";
5
5
  export * from "./utils";
6
- export * from "./product";
@@ -5,7 +5,6 @@ var constants = require('./constants.js');
5
5
  var generated = require('./generated.js');
6
6
  require('./object.js');
7
7
  require('./utils.js');
8
- var product = require('./product.js');
9
8
  "use strict";
10
9
  exports.AddressUsageType = constants.AddressUsageType;
11
10
  exports.Language = constants.Language;
@@ -19,5 +18,4 @@ exports.Unit = generated.Unit;
19
18
  exports.UnitSystem = generated.UnitSystem;
20
19
  exports.UserAssignedCountryCode = generated.UserAssignedCountryCode;
21
20
  exports.ValidateTaxStatus = generated.ValidateTaxStatus;
22
- exports.DisplayProductStatus = product.DisplayProductStatus;
23
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
@@ -3,6 +3,5 @@ export { AddressUsageType, Language } from './constants.mjs';
3
3
  export { AddressType, CountryCode, Currency, GlobalStoreId, ProductLine, StoreId, Unit, UnitSystem, UserAssignedCountryCode, ValidateTaxStatus } from './generated.mjs';
4
4
  import './object.mjs';
5
5
  import './utils.mjs';
6
- export { DisplayProductStatus } from './product.mjs';
7
6
  "use strict";
8
7
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -28,7 +28,3 @@ export declare const arraySafeIndexFind: <T>(array: T[], index: number) => T | u
28
28
  * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts
29
29
  */
30
30
  export declare const normalizeSortResult: (sortResult: number) => number;
31
- /**
32
- * Combine multiple sort functions into one
33
- */
34
- export declare const combineSorts: <T>(sorts: ((a: T, b: T) => number)[]) => ((a: T, b: T) => number);
@@ -24,19 +24,9 @@ const arraySafeIndexFind = (array, index) => {
24
24
  return array[safeIndex];
25
25
  };
26
26
  const normalizeSortResult = sortResult => number.clamp(sortResult, -1, 1);
27
- const combineSorts = sorts => (a, b) => {
28
- for (const sort of sorts) {
29
- const result = sort(a, b);
30
- if (result !== 0) {
31
- return result;
32
- }
33
- }
34
- return 0;
35
- };
36
27
  exports.areEqualArrays = areEqualArrays;
37
28
  exports.arraySafeIndex = arraySafeIndex;
38
29
  exports.arraySafeIndexFind = arraySafeIndexFind;
39
- exports.combineSorts = combineSorts;
40
30
  exports.dedupe = dedupe;
41
31
  exports.ensureArray = ensureArray;
42
32
  exports.normalizeSortResult = normalizeSortResult;
@@ -1 +1 @@
1
- {"version":3,"file":"array.js","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n\n/**\n * Combine multiple sort functions into one\n */\nexport const combineSorts =\n <T>(sorts: ((a: T, b: T) => number)[]): ((a: T, b: T) => number) =>\n (a, b) => {\n for (const sort of sorts) {\n const result = sort(a, b);\n\n if (result !== 0) {\n return result;\n }\n }\n\n return 0;\n };\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp","combineSorts","sorts","sort","result"],"mappings":";;;;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAS,CAAAD,EAAE,CAAC,CAAA,GAAI,KAAQ,GAAA,IAAA;AACpD,CAAA;AAOa,MAAAE,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAA0B,KAAA;EACtE,MAAMC,YAAYF,KAAM,CAAAL,MAAA;EAEf,OAAA,CAAAM,KAAA,GAAQC,YAAaA,SAAa,IAAAA,SAAA;AAC7C,CAAA;AAEa,MAAAC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KACkB,KAAA;EACZ,MAAAG,SAAA,GAAYL,cAAe,CAAAC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,MAAAA,CAAAA,KAAM,CAAAD,UAAA,EAAY,IAAI,CAAC,CAAA;AAKlB,MAAME,YACX,GAAIC,KACJ,IAAA,CAAChB,GAAGC,CAAM,KAAA;EACR,KAAA,MAAWgB,QAAQD,KAAO,EAAA;IAClB,MAAAE,MAAA,GAASD,IAAK,CAAAjB,CAAA,EAAGC,CAAC,CAAA;IAExB,IAAIiB,WAAW,CAAG,EAAA;MACT,OAAAA,MAAA;IACT;EACF;EAEO,OAAA,CAAA;AACT,CAAA;;;;;;;"}
1
+ {"version":3,"file":"array.js","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp"],"mappings":";;;;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAS,CAAAD,EAAE,CAAC,CAAA,GAAI,KAAQ,GAAA,IAAA;AACpD,CAAA;AAOa,MAAAE,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAA0B,KAAA;EACtE,MAAMC,YAAYF,KAAM,CAAAL,MAAA;EAEf,OAAA,CAAAM,KAAA,GAAQC,YAAaA,SAAa,IAAAA,SAAA;AAC7C,CAAA;AAEa,MAAAC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KACkB,KAAA;EACZ,MAAAG,SAAA,GAAYL,cAAe,CAAAC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,MAAAA,CAAAA,KAAM,CAAAD,UAAA,EAAY,IAAI,CAAC,CAAA;;;;;;"}
@@ -22,14 +22,5 @@ const arraySafeIndexFind = (array, index) => {
22
22
  return array[safeIndex];
23
23
  };
24
24
  const normalizeSortResult = sortResult => clamp(sortResult, -1, 1);
25
- const combineSorts = sorts => (a, b) => {
26
- for (const sort of sorts) {
27
- const result = sort(a, b);
28
- if (result !== 0) {
29
- return result;
30
- }
31
- }
32
- return 0;
33
- };
34
- export { areEqualArrays, arraySafeIndex, arraySafeIndexFind, combineSorts, dedupe, ensureArray, normalizeSortResult };
25
+ export { areEqualArrays, arraySafeIndex, arraySafeIndexFind, dedupe, ensureArray, normalizeSortResult };
35
26
  //# sourceMappingURL=array.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.mjs","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n\n/**\n * Combine multiple sort functions into one\n */\nexport const combineSorts =\n <T>(sorts: ((a: T, b: T) => number)[]): ((a: T, b: T) => number) =>\n (a, b) => {\n for (const sort of sorts) {\n const result = sort(a, b);\n\n if (result !== 0) {\n return result;\n }\n }\n\n return 0;\n };\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp","combineSorts","sorts","sort","result"],"mappings":";;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAS,CAAAD,EAAE,CAAC,CAAA,GAAI,KAAQ,GAAA,IAAA;AACpD,CAAA;AAOa,MAAAE,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAA0B,KAAA;EACtE,MAAMC,YAAYF,KAAM,CAAAL,MAAA;EAEf,OAAA,CAAAM,KAAA,GAAQC,YAAaA,SAAa,IAAAA,SAAA;AAC7C,CAAA;AAEa,MAAAC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KACkB,KAAA;EACZ,MAAAG,SAAA,GAAYL,cAAe,CAAAC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,KAAM,CAAAD,UAAA,EAAY,IAAI,CAAC,CAAA;AAKlB,MAAME,YACX,GAAIC,KACJ,IAAA,CAAChB,GAAGC,CAAM,KAAA;EACR,KAAA,MAAWgB,QAAQD,KAAO,EAAA;IAClB,MAAAE,MAAA,GAASD,IAAK,CAAAjB,CAAA,EAAGC,CAAC,CAAA;IAExB,IAAIiB,WAAW,CAAG,EAAA;MACT,OAAAA,MAAA;IACT;EACF;EAEO,OAAA,CAAA;AACT,CAAA;"}
1
+ {"version":3,"file":"array.mjs","sources":["../../src/utils/array.ts"],"sourcesContent":["import { clamp } from \"./number\";\n\n/**\n * Make sure the element is an array\n * If it's not, make it an array of one element\n */\nexport function ensureArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Utility to quickly remove duplicates from an array.\n *\n * Similar to lodash's `uniq`, but doesn't require lodash as dependency.\n */\nexport const dedupe = <T>(arr: T[]) => [...new Set(arr)];\n\n/**\n * Utility function check if given arrays contain same elements (regardless the order)\n *\n * @example\n * areArraysEqual([1, 2, 3], [3, 2, 1]) // true\n * areArraysEqual([1, 2, 3], [3, 2, 1, 4]) // false\n */\nexport const areEqualArrays = (a: string[], b: string[]): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n if (!a.every((el) => b.includes(el))) {\n return false;\n }\n return !b.every((el) => a.includes(el)) ? false : true;\n};\n\n/**\n * Function to get array index by positive and negative wrap-around offsets\n *\n * @see https://dirask.com/posts/JavaScript-positive-and-negative-around-index-wrapping-overlapping-to-address-items-in-array-pVyrnD\n */\nexport const arraySafeIndex = <T>(array: T[], index: number): number => {\n const indexSize = array.length;\n\n return ((index % indexSize) + indexSize) % indexSize;\n};\n\nexport const arraySafeIndexFind = <T>(\n array: T[],\n index: number,\n): T | undefined => {\n const safeIndex = arraySafeIndex(array, index);\n\n return array[safeIndex];\n};\n\n/**\n * Normalise sort result to be in range of -1 to 1 so that we can easily combine multiple sorts\n */\nexport const normalizeSortResult = (sortResult: number): number =>\n clamp(sortResult, -1, 1);\n"],"names":["ensureArray","value","Array","isArray","dedupe","arr","Set","areEqualArrays","a","b","length","every","el","includes","arraySafeIndex","array","index","indexSize","arraySafeIndexFind","safeIndex","normalizeSortResult","sortResult","clamp"],"mappings":";;AAMO,SAASA,YAAeC,KAAqB,EAAA;EAClD,OAAOC,MAAMC,OAAQ,CAAAF,KAAK,CAAI,GAAAA,KAAA,GAAQ,CAACA,KAAK,CAAA;AAC9C;AAOa,MAAAG,MAAA,GAAaC,GAAa,IAAA,CAAC,GAAG,IAAIC,GAAA,CAAID,GAAG,CAAC,CAAA;AAS1C,MAAAE,cAAA,GAAiBA,CAACC,CAAA,EAAaC,CAAyB,KAAA;EAC/D,IAAAD,CAAA,CAAEE,MAAW,KAAAD,CAAA,CAAEC,MAAQ,EAAA;IAClB,OAAA,KAAA;EACT;EACI,IAAA,CAACF,EAAEG,KAAM,CAACC,MAAOH,CAAE,CAAAI,QAAA,CAASD,EAAE,CAAC,CAAG,EAAA;IAC7B,OAAA,KAAA;EACT;EACO,OAAA,CAACH,CAAE,CAAAE,KAAA,CAAOC,EAAA,IAAOJ,EAAEK,QAAS,CAAAD,EAAE,CAAC,CAAA,GAAI,KAAQ,GAAA,IAAA;AACpD,CAAA;AAOa,MAAAE,cAAA,GAAiBA,CAAIC,KAAA,EAAYC,KAA0B,KAAA;EACtE,MAAMC,YAAYF,KAAM,CAAAL,MAAA;EAEf,OAAA,CAAAM,KAAA,GAAQC,YAAaA,SAAa,IAAAA,SAAA;AAC7C,CAAA;AAEa,MAAAC,kBAAA,GAAqBA,CAChCH,KAAA,EACAC,KACkB,KAAA;EACZ,MAAAG,SAAA,GAAYL,cAAe,CAAAC,KAAA,EAAOC,KAAK,CAAA;EAE7C,OAAOD,MAAMI,SAAS,CAAA;AACxB,CAAA;AAKO,MAAMC,sBAAuBC,UAAA,IAClCC,KAAM,CAAAD,UAAA,EAAY,IAAI,CAAC,CAAA;"}
@@ -18,13 +18,6 @@ export declare const Round: {
18
18
  *
19
19
  * If you really want to get knee-deep in the rounding subject, you can read the following:
20
20
  * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
21
- *
22
- * !!!!!!!!!!!!!!
23
- * ! Update 2024
24
- * ! We ar changing from `halfEven` (bankers rounding) to `halfAwayFromZero` (symmetric rounding) to match Avalara tax
25
- * @see https://knowledge.avalara.com/bundle/dqa1657870670369_dqa1657870670369/page/Change_how_AvaTax_rounds_the_tax_amount.html
26
- * @see https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639
27
- * !!!!!!!!!!!!!!
28
21
  */
29
22
  Financial: import("@dinero.js/core").RoundingMode;
30
23
  Shipping: import("@dinero.js/core").RoundingMode;
@@ -22,16 +22,8 @@ const Round = {
22
22
  *
23
23
  * If you really want to get knee-deep in the rounding subject, you can read the following:
24
24
  * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
25
- *
26
- * !!!!!!!!!!!!!!
27
- * ! Update 2024
28
- * ! We ar changing from `halfEven` (bankers rounding) to `halfAwayFromZero` (symmetric rounding) to match Avalara tax
29
- * @see https://knowledge.avalara.com/bundle/dqa1657870670369_dqa1657870670369/page/Change_how_AvaTax_rounds_the_tax_amount.html
30
- * @see https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639
31
- * !!!!!!!!!!!!!!
32
25
  */
33
- Financial: dinero_js.halfAwayFromZero,
34
- // https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639
26
+ Financial: dinero_js.halfEven,
35
27
  // TODO: maybe we should have separate rounding functions depending on the input value?
36
28
  // Reading from wiki "Round half toward zero" is better if the value is already "normalized to cents"
37
29
  // But the "Round half to even" seems better for when working with float like values
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfAwayFromZero, halfUp } from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { Currency } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\nexport const Round = {\n /**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n *\n * !!!!!!!!!!!!!!\n * ! Update 2024\n * ! We ar changing from `halfEven` (bankers rounding) to `halfAwayFromZero` (symmetric rounding) to match Avalara tax\n * @see https://knowledge.avalara.com/bundle/dqa1657870670369_dqa1657870670369/page/Change_how_AvaTax_rounds_the_tax_amount.html\n * @see https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\n * !!!!!!!!!!!!!!\n */\n Financial: halfAwayFromZero,\n // https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\n // TODO: maybe we should have separate rounding functions depending on the input value?\n // Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n // But the \"Round half to even\" seems better for when working with float like values\n // financialRound = Math.round;\n Shipping: down,\n Prettify: down,\n Subunit: halfUp,\n} satisfies Record<string, RoundingFn>;\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of dinero code to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<string, [Cents, RoundingFn]>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, Round.Subunit]],\n]);\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const localizedCurrencyLookup = new Map<Currency, LocalizedCurrency>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n\n// #############################################################################\n// Tax Rate\n// #############################################################################\n/**\n * List of stores that require calculating per single item qty and then combining them to get the total tax amount for a\n * single line. Rest of the stores inherit default behavior that tax calculated on whole line item\n *\n * ! IMPORTANT: When changing need to sync that store.backend `AVATAX_CUSTOM_COMPANY_CODES` is updated to reflect the change\n *\n * FIXME: as PR for the change as unfinished currently disabled to enable the functionality that calculates tax per single item as requires\n * specific testing both for our custom tax and Avalara stores that use custom company codes. So the groundwork for\n * different tax calculations is there just need to enable on the share side and test if it works\n */\nexport const storesWithPerItemTaxRate = new Set([\n // #############################################################################\n // Stores with custom tax rates\n // #############################################################################\n // StoreId.Br,\n // StoreId.Tw,\n // #############################################################################\n // Stores with Avalara, but will have custom company codes to handle per-item tax rate\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n] as StoreId[]);\n\n/**\n * Dinero currency option block for working with tax rates within dinero\n */\nexport const TAX_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We expect the tax rate to be in the range of 0..1\n * 0 --> 0%\n * 1 --> 100%\n * 0.21 --> 21%\n * 0.2169 --> 21.69%\n * 0.12345678 --> 12.345678%\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 8,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n\n// #############################################################################\n// Exchange Rate\n// #############################################################################\n\nexport const EXCHANGE_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We support having certain decimal places for exchange rates\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 6,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n"],"names":["Round","Financial","halfAwayFromZero","Shipping","down","Prettify","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN","storesWithPerItemTaxRate","Set","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;;;AAuCO,MAAMA,KAAQ,GAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAyBnBC,SA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AA;AAMO,MAAMsD,6BAAgC,GAAA;EAC3CF,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;EAKNC,QAAU,EAAA,CAAA;EACVrD,IAAM,EAAA;EAAA;AACR,CAAA;;;;;;;"}
1
+ {"version":3,"file":"constants.js","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfEven, halfUp } from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { Currency } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\nexport const Round = {\n /**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n */\n Financial: halfEven,\n // TODO: maybe we should have separate rounding functions depending on the input value?\n // Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n // But the \"Round half to even\" seems better for when working with float like values\n // financialRound = Math.round;\n Shipping: down,\n Prettify: down,\n Subunit: halfUp,\n} satisfies Record<string, RoundingFn>;\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of dinero code to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<string, [Cents, RoundingFn]>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, Round.Subunit]],\n]);\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const localizedCurrencyLookup = new Map<Currency, LocalizedCurrency>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n\n// #############################################################################\n// Tax Rate\n// #############################################################################\n/**\n * List of stores that require calculating per single item qty and then combining them to get the total tax amount for a\n * single line. Rest of the stores inherit default behavior that tax calculated on whole line item\n *\n * ! IMPORTANT: When changing need to sync that store.backend `AVATAX_CUSTOM_COMPANY_CODES` is updated to reflect the change\n *\n * FIXME: as PR for the change as unfinished currently disabled to enable the functionality that calculates tax per single item as requires\n * specific testing both for our custom tax and Avalara stores that use custom company codes. So the groundwork for\n * different tax calculations is there just need to enable on the share side and test if it works\n */\nexport const storesWithPerItemTaxRate = new Set([\n // #############################################################################\n // Stores with custom tax rates\n // #############################################################################\n // StoreId.Br,\n // StoreId.Tw,\n // #############################################################################\n // Stores with Avalara, but will have custom company codes to handle per-item tax rate\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n] as StoreId[]);\n\n/**\n * Dinero currency option block for working with tax rates within dinero\n */\nexport const TAX_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We expect the tax rate to be in the range of 0..1\n * 0 --> 0%\n * 1 --> 100%\n * 0.21 --> 21%\n * 0.2169 --> 21.69%\n * 0.12345678 --> 12.345678%\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 8,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n\n// #############################################################################\n// Exchange Rate\n// #############################################################################\n\nexport const EXCHANGE_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We support having certain decimal places for exchange rates\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 6,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n"],"names":["Round","Financial","halfEven","Shipping","down","Prettify","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN","storesWithPerItemTaxRate","Set","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;;;AAuCO,MAAMA,KAAQ,GAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAkBnBC,SAAW,EAAAC,SAAA,CAAAA,QAAA;EAAA;EAAA;EAAA;EAAA;EAKXC,QAAU,EAAAC,SAAA,CAAAA,IAAA;EACVC,QAAU,EAAAD,SAAA,CAAAA,IAAA;EACVE,OAAS,EAAAC,SAAA,CAAAA;AACX,CAAA;AAKa,MAAAC,mBAAA,GAAA,mBAA0BC,GAAI,CAAA,CACzC,CAACC,UAAI,CAAAA,GAAA,CAAAC,IAAA,EAAM,EAAE,CAAA,EACb,CAACC,UAAI,CAAAA,GAAA,CAAAD,IAAA,EAAM,EAAE,CAAA,EACb,CAACE,UAAI,CAAAA,GAAA,CAAAF,IAAA,EAAM,EAAE,CAAA,EACb,CAACG,UAAI,CAAAA,GAAA,CAAAH,IAAA,EAAM,EAAE,CAAA,EACb,CAACI,UAAI,CAAAA,GAAA,CAAAJ,IAAA,EAAM,EAAE,CAAA;AAAA;AAEb,CAACK,UAAI,CAAAA,GAAA,CAAAL,IAAA,EAAM,EAAE,CAAA,CACd,CAAA;AAKY,MAAAM,qBAAA,GAAA,mBAA4BR,GAAiC,CAAA;AAAA;AAAA;AAAA;AAIxE,CAACS,UAAAA,CAAAA,GAAI,CAAAP,IAAA,EAAM,CAAC,CAAG,EAAAX,KAAA,CAAMM,OAAO,CAAC,CAAA,CAC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AQ;CAAS,CAAA,EACjD,CAACH,SAAAA,CAAAA,SAASsC,GAAK,EAAA;EAAEpC,UAAUqC,UAAAA,CAAAA,GAAK;EAAApC,MAAA,EAAQ;CAAS,CAAA,CAClD,CAAA;AAeY,MAAAqC,wBAAA,GAAA,mBAA+BC,GAAI,CAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA,CAWlC,CAAA;AAKP,MAAMC,wBAA2B,GAAA;EACtCC,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAUNC,QAAU,EAAA,CAAA;EACVrD,IAAM,EAAA;EAAA;AACR,CAAA;AAMO,MAAMsD,6BAAgC,GAAA;EAC3CF,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;EAKNC,QAAU,EAAA,CAAA;EACVrD,IAAM,EAAA;EAAA;AACR,CAAA;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { USD, CAD, EUR, GBP, AED, ZAR, TWD, BGN, CHF, CZK, DKK, HRK, HUF, NOK, PLN, RON, SEK, INR, SGD, BRL, JPY, MXN } from '@dinero.js/currencies';
2
- import { halfAwayFromZero, down, halfUp } from 'dinero.js';
2
+ import { halfEven, down, halfUp } from 'dinero.js';
3
3
  import '../../types/index.mjs';
4
4
  import { Currency } from '../../types/generated.mjs';
5
5
  "use strict";
@@ -20,16 +20,8 @@ const Round = {
20
20
  *
21
21
  * If you really want to get knee-deep in the rounding subject, you can read the following:
22
22
  * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero
23
- *
24
- * !!!!!!!!!!!!!!
25
- * ! Update 2024
26
- * ! We ar changing from `halfEven` (bankers rounding) to `halfAwayFromZero` (symmetric rounding) to match Avalara tax
27
- * @see https://knowledge.avalara.com/bundle/dqa1657870670369_dqa1657870670369/page/Change_how_AvaTax_rounds_the_tax_amount.html
28
- * @see https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639
29
- * !!!!!!!!!!!!!!
30
23
  */
31
- Financial: halfAwayFromZero,
32
- // https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639
24
+ Financial: halfEven,
33
25
  // TODO: maybe we should have separate rounding functions depending on the input value?
34
26
  // Reading from wiki "Round half toward zero" is better if the value is already "normalized to cents"
35
27
  // But the "Round half to even" seems better for when working with float like values
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfAwayFromZero, halfUp } from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { Currency } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\nexport const Round = {\n /**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n *\n * !!!!!!!!!!!!!!\n * ! Update 2024\n * ! We ar changing from `halfEven` (bankers rounding) to `halfAwayFromZero` (symmetric rounding) to match Avalara tax\n * @see https://knowledge.avalara.com/bundle/dqa1657870670369_dqa1657870670369/page/Change_how_AvaTax_rounds_the_tax_amount.html\n * @see https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\n * !!!!!!!!!!!!!!\n */\n Financial: halfAwayFromZero,\n // https://ui.slack.com/archives/C07P7L7S3CP/p1728313196140639\n // TODO: maybe we should have separate rounding functions depending on the input value?\n // Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n // But the \"Round half to even\" seems better for when working with float like values\n // financialRound = Math.round;\n Shipping: down,\n Prettify: down,\n Subunit: halfUp,\n} satisfies Record<string, RoundingFn>;\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of dinero code to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<string, [Cents, RoundingFn]>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, Round.Subunit]],\n]);\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const localizedCurrencyLookup = new Map<Currency, LocalizedCurrency>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n\n// #############################################################################\n// Tax Rate\n// #############################################################################\n/**\n * List of stores that require calculating per single item qty and then combining them to get the total tax amount for a\n * single line. Rest of the stores inherit default behavior that tax calculated on whole line item\n *\n * ! IMPORTANT: When changing need to sync that store.backend `AVATAX_CUSTOM_COMPANY_CODES` is updated to reflect the change\n *\n * FIXME: as PR for the change as unfinished currently disabled to enable the functionality that calculates tax per single item as requires\n * specific testing both for our custom tax and Avalara stores that use custom company codes. So the groundwork for\n * different tax calculations is there just need to enable on the share side and test if it works\n */\nexport const storesWithPerItemTaxRate = new Set([\n // #############################################################################\n // Stores with custom tax rates\n // #############################################################################\n // StoreId.Br,\n // StoreId.Tw,\n // #############################################################################\n // Stores with Avalara, but will have custom company codes to handle per-item tax rate\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n] as StoreId[]);\n\n/**\n * Dinero currency option block for working with tax rates within dinero\n */\nexport const TAX_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We expect the tax rate to be in the range of 0..1\n * 0 --> 0%\n * 1 --> 100%\n * 0.21 --> 21%\n * 0.2169 --> 21.69%\n * 0.12345678 --> 12.345678%\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 8,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n\n// #############################################################################\n// Exchange Rate\n// #############################################################################\n\nexport const EXCHANGE_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We support having certain decimal places for exchange rates\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 6,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n"],"names":["Round","Financial","halfAwayFromZero","Shipping","down","Prettify","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN","storesWithPerItemTaxRate","Set","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;AAuCO,MAAMA,KAAQ,GAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAyBnBC,SAAW,EAAAC,gBAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAMXC,QAAU,EAAAC,IAAA;EACVC,QAAU,EAAAD,IAAA;EACVE,OAAS,EAAAC;AACX,CAAA;AAKa,MAAAC,mBAAA,GAAA,mBAA0BC,GAAI,CAAA,CACzC,CAACC,GAAI,CAAAC,IAAA,EAAM,EAAE,CAAA,EACb,CAACC,GAAI,CAAAD,IAAA,EAAM,EAAE,CAAA,EACb,CAACE,GAAI,CAAAF,IAAA,EAAM,EAAE,CAAA,EACb,CAACG,GAAI,CAAAH,IAAA,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A;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAUNC,QAAU,EAAA,CAAA;EACVrD,IAAM,EAAA;EAAA;AACR,CAAA;AAMO,MAAMsD,6BAAgC,GAAA;EAC3CF,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;EAKNC,QAAU,EAAA,CAAA;EACVrD,IAAM,EAAA;EAAA;AACR,CAAA;"}
1
+ {"version":3,"file":"constants.mjs","sources":["../../../src/utils/money/constants.ts"],"sourcesContent":["import {\n AED,\n BGN,\n BRL,\n CAD,\n CHF,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PLN,\n RON,\n SEK,\n SGD,\n TWD,\n USD,\n ZAR,\n} from \"@dinero.js/currencies\";\nimport { down, halfEven, halfUp } from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { Currency } from \"../../types\";\nimport type {\n Cents,\n DinoCurrency,\n LocalizedCurrency,\n RoundingFn,\n} from \"./types\";\n\n// #############################################################################\n// Constants\n// #############################################################################\n\nexport const Round = {\n /**\n * ⚠️ Instead of using Math.round, we HAVE to use this method to round the financial numbers everywhere where we CAN'T\n * deal with dinero.js (Dinero.js should be the priority). But often for converting from API requests we have to\n * normalise the values so we use this method.\n *\n * It just a re-export of the dinero.js halfEven (a.k.a bankers rounding) method which is the default rounding method.\n * @see https://github.com/dinerojs/dinero.js/blob/main/packages/core/src/round/halfEven.ts\n * @see\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behaviour based on if the rounded\n * number would be an even number. So 1.5 would round to 2 while 2.5 would round to 2.\n * See the youtube link below for a brief exclamation on why it's important to use this method over regular rounding (half-up):\n * https://youtu.be/yuRdYlZvs1E\n *\n * If you really want to get knee-deep in the rounding subject, you can read the following:\n * https://en.wikipedia.org/wiki/Rounding#Round_half_toward_zero\n */\n Financial: halfEven,\n // TODO: maybe we should have separate rounding functions depending on the input value?\n // Reading from wiki \"Round half toward zero\" is better if the value is already \"normalized to cents\"\n // But the \"Round half to even\" seems better for when working with float like values\n // financialRound = Math.round;\n Shipping: down,\n Prettify: down,\n Subunit: halfUp,\n} satisfies Record<string, RoundingFn>;\n\n/**\n * Mapping of how prices should be rounded down to \"whole numbers\" after certain threshold\n */\nexport const prettifyPriceLookup = new Map([\n [USD.code, 20],\n [CAD.code, 20],\n [EUR.code, 20],\n [GBP.code, 20],\n [AED.code, 50],\n // Approximately every price above ~1.1 usd will be rounded in ZAR\n [ZAR.code, 20],\n]);\n\n/**\n * Map of dinero code to subunit digit count.\n */\nexport const smallestSubunitLookup = new Map<string, [Cents, RoundingFn]>([\n /**\n * TWD does not use subunits at all in day to day transactions.\n */\n [TWD.code, [0, Round.Subunit]],\n]);\n\n/**\n * Precompiled list for faster currency and locale lookups\n */\nexport const localizedCurrencyLookup = new Map<Currency, LocalizedCurrency>([\n [Currency.Aed, { currency: AED, locale: \"ar-AE\" }],\n [Currency.Bgn, { currency: BGN, locale: \"bg-BG\" }],\n [Currency.Cad, { currency: CAD, locale: \"en-CA\" }],\n [Currency.Chf, { currency: CHF, locale: \"it-CH\" }],\n [Currency.Czk, { currency: CZK, locale: \"cs-CZ\" }],\n [Currency.Dkk, { currency: DKK, locale: \"da-DK\" }],\n [Currency.Eur, { currency: EUR, locale: \"de-DE\" }],\n [Currency.Gbp, { currency: GBP, locale: \"en-GB\" }],\n [Currency.Hrk, { currency: HRK, locale: \"hr-HR\" }],\n [Currency.Huf, { currency: HUF, locale: \"hu-HU\" }],\n [Currency.Nok, { currency: NOK, locale: \"no-NO\" }],\n [Currency.Pln, { currency: PLN, locale: \"pl-PL\" }],\n [Currency.Ron, { currency: RON, locale: \"ro-RO\" }],\n [Currency.Sek, { currency: SEK, locale: \"sv-SE\" }],\n [Currency.Usd, { currency: USD, locale: \"en-US\" }],\n [Currency.Zar, { currency: ZAR, locale: \"en-ZA\" }],\n [Currency.Inr, { currency: INR, locale: \"en-IN\" }],\n [Currency.Sgd, { currency: SGD, locale: \"en-SG\" }],\n [Currency.Brl, { currency: BRL, locale: \"pt-BR\" }],\n // NOTE: en-JP Doesn't exist\n [Currency.Jpy, { currency: JPY, locale: \"en-JP\" }],\n // NOTE: en-TW Doesn't exist\n [Currency.Twd, { currency: TWD, locale: \"en-TW\" }],\n [Currency.Mxn, { currency: MXN, locale: \"es-MX\" }],\n]);\n\n// #############################################################################\n// Tax Rate\n// #############################################################################\n/**\n * List of stores that require calculating per single item qty and then combining them to get the total tax amount for a\n * single line. Rest of the stores inherit default behavior that tax calculated on whole line item\n *\n * ! IMPORTANT: When changing need to sync that store.backend `AVATAX_CUSTOM_COMPANY_CODES` is updated to reflect the change\n *\n * FIXME: as PR for the change as unfinished currently disabled to enable the functionality that calculates tax per single item as requires\n * specific testing both for our custom tax and Avalara stores that use custom company codes. So the groundwork for\n * different tax calculations is there just need to enable on the share side and test if it works\n */\nexport const storesWithPerItemTaxRate = new Set([\n // #############################################################################\n // Stores with custom tax rates\n // #############################################################################\n // StoreId.Br,\n // StoreId.Tw,\n // #############################################################################\n // Stores with Avalara, but will have custom company codes to handle per-item tax rate\n // #############################################################################\n // StoreId.Jp,\n // StoreId.Sg,\n] as StoreId[]);\n\n/**\n * Dinero currency option block for working with tax rates within dinero\n */\nexport const TAX_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We expect the tax rate to be in the range of 0..1\n * 0 --> 0%\n * 1 --> 100%\n * 0.21 --> 21%\n * 0.2169 --> 21.69%\n * 0.12345678 --> 12.345678%\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 8,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n\n// #############################################################################\n// Exchange Rate\n// #############################################################################\n\nexport const EXCHANGE_RATE_DINERO_CURRENCY = {\n base: 10,\n /**\n * We support having certain decimal places for exchange rates\n * !!! Don't change as this value is tied to store.backend DB schema !!!\n */\n exponent: 6,\n code: \"\", // Not important\n} satisfies DinoCurrency;\n"],"names":["Round","Financial","halfEven","Shipping","down","Prettify","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","CAD","EUR","GBP","AED","ZAR","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","Gbp","Hrk","HRK","Huf","HUF","Nok","NOK","Pln","PLN","Ron","RON","Sek","SEK","Usd","Zar","Inr","INR","Sgd","SGD","Brl","BRL","Jpy","JPY","Twd","Mxn","MXN","storesWithPerItemTaxRate","Set","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;AAuCO,MAAMA,KAAQ,GAAA;EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;EAkBnBC,SAAW,EAAAC,QAAA;EAAA;EAAA;EAAA;EAAA;EAKXC,QAAU,EAAAC,IAAA;EACVC,QAAU,EAAAD,IAAA;EACVE,OAAS,EAAAC;AACX,CAAA;AAKa,MAAAC,mBAAA,GAAA,mBAA0BC,GAAI,CAAA,CACzC,CAACC,GAAI,CAAAC,IAAA,EAAM,EAAE,CAAA,EACb,CAACC,GAAI,CAAAD,IAAA,EAAM,EAAE,CAAA,EACb,CAACE,GAAI,CAAAF,IAAA,EAAM,EAAE,CAAA,EACb,CAACG,GAAI,CAAAH,IAAA,EAAM,EAAE,CAAA,EACb,CAACI,GAAI,CAAAJ,IAAA,EAAM,EAAE,CAAA;AAAA;AAEb,CAACK,GAAI,CAAAL,IAAA,EAAM,EAAE,CAAA,CACd,CAAA;AAKY,MAAAM,qBAAA,GAAA,mBAA4BR,GAAiC,CAAA;AAAA;AAAA;AAAA;AAIxE,CAACS,GAAI,CAAAP,IAAA,EAAM,CAAC,CAAG,EAAAX,KAAA,CAAMM,OAAO,CAAC,CAAA,CAC9B,CAAA;AAKY,MAAAa,uBAAA,GAAA,mBAA8BV,GAAiC,CAAA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
+ * Private helper to convert a floating number to a dinero friendly allocation integer pair
5
+ * @see https://v2.dinerojs.com/docs/api/mutations/allocate
6
+ * @example
7
+ * taxRateToDineroAllocation(0.1) // [1, 9]
8
+ * taxRateToDineroAllocation(0.5) // [5, 5]
9
+ */
10
+ export declare const taxRateToDineroAllocation: (taxRate: TaxRate) => [number, number];
3
11
  /**
4
12
  * Reverse engineer the taxable amount from "whole item" taxable amount into "per item" taxable amount for custom tax
5
13
  * rate calculations
@@ -1,10 +1,19 @@
1
1
  'use strict';
2
2
 
3
3
  var dinero_js = require('dinero.js');
4
+ var errors = require('../errors.js');
4
5
  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
+ };
8
17
  const allocatePerItemTaxableAmount = itemSummary => {
9
18
  if (itemSummary.quantity === 1) {
10
19
  return [itemSummary];
@@ -33,10 +42,9 @@ const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
33
42
  if (taxRate === 0) {
34
43
  return misc.getDinero(0, itemSummary.currency);
35
44
  }
36
- return dinero_js.dinero({
37
- amount: constants.Round.Financial(itemSummary.taxableAmount * taxRate),
38
- currency: misc.getDineroCurrency(itemSummary.currency)
39
- });
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;
40
48
  };
41
49
  const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
42
50
  if (taxRate === 0) {
@@ -53,4 +61,5 @@ const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
53
61
  exports.allocatePerItemTaxableAmount = allocatePerItemTaxableAmount;
54
62
  exports.calculatePerQtyLineItemTax = calculatePerQtyLineItemTax;
55
63
  exports.calculateWholeQtyLineItemTax = calculateWholeQtyLineItemTax;
64
+ exports.taxRateToDineroAllocation = taxRateToDineroAllocation;
56
65
  //# 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, 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,M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AYM,QAAQ,CAAA;EAC1C;EAMA,OAAOgB,gBAAO,CAAA;IACZV,MAAQ,EAAAW,SAAAA,CAAAA,KAAA,CAAMC,SAAU,CAAAxB,WAAA,CAAYK,gBAAgBgB,OAAO,CAAA;IAC3Df,QAAA,EAAUmB,IAAAA,CAAAA,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,cAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGM,MAAAqB,mBAAA,GAAsB5B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI4B,cAAiB,GAAAxB,IAAA,CAAAA,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,SAAA,CAAAA,GAAA,CAAIyB,gBAAgBE,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAF,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, 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,MAA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@@
1
- import { add, subtract, dinero } from 'dinero.js';
1
+ import { add, subtract, allocate } from 'dinero.js';
2
+ import { assert } from '../errors.mjs';
2
3
  import { FixedAmountAllocator } from './allocators/fixedAmount.mjs';
3
- import { Round } from './constants.mjs';
4
- import { getDinero, amount, getDineroCurrency } from './misc.mjs';
4
+ import { getDinero, amount } 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
+ };
6
15
  const allocatePerItemTaxableAmount = itemSummary => {
7
16
  if (itemSummary.quantity === 1) {
8
17
  return [itemSummary];
@@ -31,10 +40,9 @@ const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
31
40
  if (taxRate === 0) {
32
41
  return getDinero(0, itemSummary.currency);
33
42
  }
34
- return dinero({
35
- amount: Round.Financial(itemSummary.taxableAmount * taxRate),
36
- currency: getDineroCurrency(itemSummary.currency)
37
- });
43
+ const [taxAmount] = allocate(getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRateToDineroAllocation(taxRate));
44
+ assert(taxAmount !== void 0, "taxAmount is undefined");
45
+ return taxAmount;
38
46
  };
39
47
  const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
40
48
  if (taxRate === 0) {
@@ -48,5 +56,5 @@ const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
48
56
  });
49
57
  return totalTaxAmount;
50
58
  };
51
- export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax };
59
+ export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax, taxRateToDineroAllocation };
52
60
  //# sourceMappingURL=tax.private.mjs.map