@ubnt/store.core 9.45.0-beta.7 → 9.45.0-beta.9

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 (92) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/_virtual/_virtual_multi-entry.js +4 -0
  3. package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
  4. package/lib/_virtual/_virtual_multi-entry.mjs +1 -0
  5. package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
  6. package/lib/assets/close2.svg +2 -3
  7. package/lib/assets/close3.svg +3 -2
  8. package/lib/assets/minus4.svg +8 -8
  9. package/lib/assets/minus5.svg +8 -8
  10. package/lib/assets/plus5.svg +9 -9
  11. package/lib/assets/plus6.svg +9 -9
  12. package/lib/assets/poe2.svg +3 -2
  13. package/lib/assets/poe3.svg +2 -3
  14. package/lib/assets/port.svg +4 -2
  15. package/lib/assets/port2.svg +2 -4
  16. package/lib/components/FeaturesSection_deprecated/FeaturesSection.js +1 -1
  17. package/lib/components/FeaturesSection_deprecated/FeaturesSection.mjs +1 -1
  18. package/lib/components/FeaturesSection_deprecated/assets/close.svg.js +1 -1
  19. package/lib/components/FeaturesSection_deprecated/assets/close.svg.mjs +2 -2
  20. package/lib/components/ModelCompareV3/assets/poe.svg.js +1 -1
  21. package/lib/components/ModelCompareV3/assets/poe.svg.mjs +2 -2
  22. package/lib/components/ModelCompareV3/assets/port.svg.js +1 -1
  23. package/lib/components/ModelCompareV3/assets/port.svg.mjs +2 -2
  24. package/lib/components/ModelCompareV3/data/properties/powerMethodPoe.js +1 -1
  25. package/lib/components/ModelCompareV3/data/properties/powerMethodPoe.mjs +1 -1
  26. package/lib/components/ModelCompareV3/data/properties/readerPowerMethod.js +1 -1
  27. package/lib/components/ModelCompareV3/data/properties/readerPowerMethod.mjs +1 -1
  28. package/lib/components/ModelCompareV3/data/properties/redundantRj45Port.js +1 -1
  29. package/lib/components/ModelCompareV3/data/properties/redundantRj45Port.mjs +1 -1
  30. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  31. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  32. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  33. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  34. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  35. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  36. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  37. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  38. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  39. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  40. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  41. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  42. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/RecommendedPoeSwitches.js +2 -2
  43. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/RecommendedPoeSwitches.mjs +2 -2
  44. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/assets/poe.svg.js +1 -1
  45. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/assets/poe.svg.mjs +2 -2
  46. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/assets/port.svg.js +1 -1
  47. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/RecommendedPoeSwitches/assets/port.svg.mjs +2 -2
  48. package/lib/components/VideoPlayerNew/VideoPlayer.js +1 -1
  49. package/lib/components/VideoPlayerNew/VideoPlayer.mjs +1 -1
  50. package/lib/components/VideoPlayerNew/assets/close.svg.js +1 -1
  51. package/lib/components/VideoPlayerNew/assets/close.svg.mjs +2 -2
  52. package/lib/constants/icons/options/colors/black.svg.js +5 -5
  53. package/lib/constants/icons/options/colors/index.js +3 -3
  54. package/lib/constants/icons/options/styles/black.svg.js +5 -5
  55. package/lib/constants/icons/options/styles/index.js +3 -3
  56. package/lib/constants/optionIcons.js +6 -6
  57. package/lib/constants/optionIcons.mjs +4 -4
  58. package/lib/contexts/MenuContext/presets.d.ts +8 -0
  59. package/lib/contexts/MenuContext/presets.js +6 -0
  60. package/lib/contexts/MenuContext/presets.js.map +1 -1
  61. package/lib/contexts/MenuContext/presets.mjs +6 -0
  62. package/lib/contexts/MenuContext/presets.mjs.map +1 -1
  63. package/lib/helpers/ux.js +49 -0
  64. package/lib/helpers/ux.js.map +1 -0
  65. package/lib/helpers/ux.mjs +46 -0
  66. package/lib/helpers/ux.mjs.map +1 -0
  67. package/lib/types/generated.d.ts +3 -1
  68. package/lib/types/generated.js +1 -0
  69. package/lib/types/generated.js.map +1 -1
  70. package/lib/types/generated.mjs +1 -0
  71. package/lib/types/generated.mjs.map +1 -1
  72. package/lib/utils/money/constants.js +3 -0
  73. package/lib/utils/money/constants.js.map +1 -1
  74. package/lib/utils/money/constants.mjs +4 -1
  75. package/lib/utils/money/constants.mjs.map +1 -1
  76. package/lib/utils/product.js +1 -0
  77. package/lib/utils/product.js.map +1 -1
  78. package/lib/utils/product.mjs +1 -0
  79. package/lib/utils/product.mjs.map +1 -1
  80. package/lib/utils/sales.js +1 -0
  81. package/lib/utils/sales.js.map +1 -1
  82. package/lib/utils/sales.mjs +1 -0
  83. package/lib/utils/sales.mjs.map +1 -1
  84. package/lib/utils/shipping.js +1 -0
  85. package/lib/utils/shipping.js.map +1 -1
  86. package/lib/utils/shipping.mjs +1 -0
  87. package/lib/utils/shipping.mjs.map +1 -1
  88. package/lib/utils/tax/index.js +1 -0
  89. package/lib/utils/tax/index.js.map +1 -1
  90. package/lib/utils/tax/index.mjs +1 -0
  91. package/lib/utils/tax/index.mjs.map +1 -1
  92. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { USD, AED, ZAR, TWD, BGN, CAD, CHF, CZK, DKK, EUR, GBP, HRK, HUF, NOK, PLN, RON, SEK, INR, SGD, BRL, JPY, MXN, PHP } from '@dinero.js/currencies';
1
+ import { USD, AED, ZAR, TWD, BGN, CAD, CHF, CZK, DKK, EUR, GBP, HRK, HUF, NOK, PLN, RON, SEK, INR, SGD, BRL, JPY, MXN, PHP, CNY } from '@dinero.js/currencies';
2
2
  import { halfAwayFromZero, down, halfUp } from 'dinero.js';
3
3
  import '../../types/index.mjs';
4
4
  import { Currency } from '../../types/generated.mjs';
@@ -167,6 +167,9 @@ const localizedCurrencyLookup = /* @__PURE__ */new Map([[Currency.Aed, {
167
167
  }], [Currency.Php, {
168
168
  currency: PHP,
169
169
  locale: "en-PH"
170
+ }], [Currency.Cny, {
171
+ currency: CNY,
172
+ locale: "zh-CN"
170
173
  }]]);
171
174
  const storesWithPerItemTaxRate = /* @__PURE__ */new Set([
172
175
  // #############################################################################
@@ -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 PHP,\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\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to nearest FULL 0/5/9 (and strip cents)\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestFull059: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-5.00\n if (input <= 5) {\n return 5;\n }\n\n /**\n * Input comes as float, for this rounding we don't need cents, so round\n * to nearest full number\n */\n const roundedNumber = Math.round(input);\n\n // Determine nearest rounding value\n const remainder = roundedNumber % 10;\n if (remainder <= 2) {\n // Round down to nearest 0\n return roundedNumber - remainder;\n } else if (remainder <= 7) {\n // Round to nearest 5\n return roundedNumber - remainder + 5;\n } else {\n // Round up to nearest 9\n return roundedNumber - remainder + 9;\n }\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest decimal cent. e.g. 1.53 = 1.50 / 1.57 = 1.60\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestDecimalCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.09\n if (input <= 0.1) {\n return 0.1;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n */\n return parseFloat((Math.round(input * 10) / 10).toFixed(1));\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest .50 or .00. e.g. 11.22 = 11 / 11.55 = 11.50 / 11.90 = 12\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestHalfUnitCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.5\n if (input <= 0.5) {\n return 0.5;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n *\n * Multiply by 2, round to the nearest integer, then divide by 2 to get the nearest .5 or .0\n * Return with fixed precision to avoid floating-point artifacts\n */\n return parseFloat((Math.round(input * 2) / 2).toFixed(2));\n};\n\nexport const Round = {\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 * OLD: halfEven docs\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 * normalize 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/v2.0.0-alpha.8/packages/core/src/round/halfEven.ts\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behavior\n * based on if the rounded 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\n * (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: 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 /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyFull059: roundToNearestFull059,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyDecimalCents: roundToNearestDecimalCent,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyHalfUnitCents: roundToNearestHalfUnitCent,\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 [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 [Currency.Php, { currency: PHP, locale: \"en-PH\" }],\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":["roundToNearestFull059","input","roundedNumber","Math","round","remainder","roundToNearestDecimalCent","parseFloat","toFixed","roundToNearestHalfUnitCent","Round","Financial","halfAwayFromZero","Shipping","down","Prettify","PrettifyFull059","PrettifyDecimalCents","PrettifyHalfUnitCents","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","AED","ZAR","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","CAD","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","EUR","Gbp","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","Php","PHP","storesWithPerItemTaxRate","Set","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;AA8Ca,MAAAA,qBAAA,GAAqCC,KAAkB,IAAA;EAClE,IAAIA,UAAU,CAAG,EAAA;IACR,OAAA,CAAA;EACT;EAGA,IAAIA,SAAS,CAAG,EAAA;IACP,OAAA,CAAA;EACT;EAMM,MAAAC,aAAA,GAAgBC,IAAK,CAAAC,KAAA,CAAMH,KAAK,CAAA;EAGtC,MAAMI,YAAYH,aAAgB,GAAA,EAAA;EAClC,IAAIG,aAAa,CAAG,EAAA;IAElB,OAAOH,aAAgB,GAAAG,SAAA;EAAA,CACzB,MAAA,IAAWA,aAAa,CAAG,EAAA;IAEzB,OAAOH,gBAAgBG,SAAY,GAAA,CAAA;EAAA,CAC9B,MAAA;IAEL,OAAOH,gBAAgBG,SAAY,GAAA,CAAA;EACrC;AACF,CAAA;AASa,MAAAC,yBAAA,GAAyCL,KAAkB,IAAA;EACtE,IAAIA,UAAU,CAAG,EAAA;IACR,OAAA,CAAA;EACT;EAGA,IAAIA,SAAS,GAAK,EAAA;IACT,OAAA,GAAA;EACT;EAMO,OAAAM,UAAA,CAAA,CAAYJ,K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EAAA,CAAA;EACVvD,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 CNY,\n CZK,\n DKK,\n EUR,\n GBP,\n HRK,\n HUF,\n INR,\n JPY,\n MXN,\n NOK,\n PHP,\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\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to nearest FULL 0/5/9 (and strip cents)\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestFull059: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-5.00\n if (input <= 5) {\n return 5;\n }\n\n /**\n * Input comes as float, for this rounding we don't need cents, so round\n * to nearest full number\n */\n const roundedNumber = Math.round(input);\n\n // Determine nearest rounding value\n const remainder = roundedNumber % 10;\n if (remainder <= 2) {\n // Round down to nearest 0\n return roundedNumber - remainder;\n } else if (remainder <= 7) {\n // Round to nearest 5\n return roundedNumber - remainder + 5;\n } else {\n // Round up to nearest 9\n return roundedNumber - remainder + 9;\n }\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest decimal cent. e.g. 1.53 = 1.50 / 1.57 = 1.60\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestDecimalCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.09\n if (input <= 0.1) {\n return 0.1;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n */\n return parseFloat((Math.round(input * 10) / 10).toFixed(1));\n};\n\n/**\n * Custom rounding method to be used with dinero.js\n * This rounding method will round to\n * nearest .50 or .00. e.g. 11.22 = 11 / 11.55 = 11.50 / 11.90 = 12\n *\n * @see: https://ubiquiti.atlassian.net/browse/NEP-3846\n */\nexport const roundToNearestHalfUnitCent: RoundingFn = (input: number) => {\n if (input === 0) {\n return 0;\n }\n\n // Special handling of 0.01-0.5\n if (input <= 0.5) {\n return 0.5;\n }\n\n /**\n * Input comes as float, just to be on the safe side use toFixed to mitigate\n * risk of running to floating point precision issues\n *\n * Multiply by 2, round to the nearest integer, then divide by 2 to get the nearest .5 or .0\n * Return with fixed precision to avoid floating-point artifacts\n */\n return parseFloat((Math.round(input * 2) / 2).toFixed(2));\n};\n\nexport const Round = {\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 * OLD: halfEven docs\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 * normalize 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/v2.0.0-alpha.8/packages/core/src/round/halfEven.ts\n *\n * Compared to Math.round (arithmetic rounding) it differentiates that it changes the `.5` round up or down behavior\n * based on if the rounded 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\n * (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: 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 /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyFull059: roundToNearestFull059,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyDecimalCents: roundToNearestDecimalCent,\n /**\n * ! Disclaimer may not work for \"weird\" currencies as expected\n */\n PrettifyHalfUnitCents: roundToNearestHalfUnitCent,\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 [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 [Currency.Php, { currency: PHP, locale: \"en-PH\" }],\n [Currency.Cny, { currency: CNY, locale: \"zh-CN\" }],\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":["roundToNearestFull059","input","roundedNumber","Math","round","remainder","roundToNearestDecimalCent","parseFloat","toFixed","roundToNearestHalfUnitCent","Round","Financial","halfAwayFromZero","Shipping","down","Prettify","PrettifyFull059","PrettifyDecimalCents","PrettifyHalfUnitCents","Subunit","halfUp","prettifyPriceLookup","Map","USD","code","AED","ZAR","smallestSubunitLookup","TWD","localizedCurrencyLookup","Currency","Aed","currency","locale","Bgn","BGN","Cad","CAD","Chf","CHF","Czk","CZK","Dkk","DKK","Eur","EUR","Gbp","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","Php","PHP","Cny","CNY","storesWithPerItemTaxRate","Set","TAX_RATE_DINERO_CURRENCY","base","exponent","EXCHANGE_RATE_DINERO_CURRENCY"],"mappings":";;;;;AA+Ca,MAAAA,qBAAA,GAAqCC,KAAkB,IAAA;EAClE,IAAIA,UAAU,CAAG,EAAA;IACR,OAAA,CAAA;EACT;EAGA,IAAIA,SAAS,CAAG,EAAA;IACP,OAAA,CAAA;EACT;EAMM,MAAAC,aAAA,GAAgBC,IAAK,CAAAC,KAAA,CAAMH,KAAK,CAAA;EAGtC,MAAMI,YAAYH,aAAgB,GAAA,EAAA;EAClC,IAAIG,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CAACH,SAAS6C,GAAK,EAAA;EAAE3C,UAAU4C,GAAK;EAAA3C,MAAA,EAAQ;CAAS,CAAA,CAClD,CAAA;AAeY,MAAA4C,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;EACVzD,IAAM,EAAA;EAAA;AACR,CAAA;AAMO,MAAM0D,6BAAgC,GAAA;EAC3CF,IAAM,EAAA,EAAA;EAAA;AAAA;AAAA;AAAA;EAKNC,QAAU,EAAA,CAAA;EACVzD,IAAM,EAAA;EAAA;AACR,CAAA;"}
@@ -22,6 +22,7 @@ const getSortWeightTagRegex = (site, store) => {
22
22
  case generated.StoreId.Us:
23
23
  return /pro-sort-weight:(-?\d+)/;
24
24
  case generated.StoreId.Ca:
25
+ case generated.StoreId.Cn:
25
26
  case generated.StoreId.Eu:
26
27
  case generated.StoreId.Me:
27
28
  case generated.StoreId.Uk:
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sources":["../../src/utils/product.ts"],"sourcesContent":["import type { Nullish } from \"../types\";\nimport { StoreId } from \"../types\";\nimport { normalizeSortResult } from \"./array\";\nimport { checkUnreachable } from \"./errors\";\n\nexport enum SortSiteId {\n /**\n * Store.ui.com\n */\n Store = \"store\",\n /**\n * Techspecs.ui.com\n */\n Techspecs = \"techspecs\",\n}\n\n/**\n * Get correct sort weight tag regex based on site in which\n * the product is being displayed and the store\n */\nconst getSortWeightTagRegex = (\n site: SortSiteId,\n store: Nullish<StoreId>,\n): RegExp | null => {\n switch (site) {\n case SortSiteId.Techspecs: {\n return /techspecs-sort-weight:(-?\\d+)/;\n }\n case SortSiteId.Store: {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (store) {\n case StoreId.Us:\n return /pro-sort-weight:(-?\\d+)/;\n case StoreId.Ca:\n case StoreId.Eu:\n case StoreId.Me:\n case StoreId.Uk:\n case StoreId.Za:\n case StoreId.In:\n case StoreId.Sg:\n case StoreId.Jp:\n case StoreId.Br:\n case StoreId.Tw:\n case StoreId.Mx:\n case StoreId.Ph:\n return /pro-sort-weight:(-?\\d+):other/;\n case null:\n case undefined: {\n return null;\n }\n default:\n checkUnreachable(store);\n return null;\n }\n }\n\n default: {\n checkUnreachable(site);\n return null;\n }\n }\n};\n\n/**\n * Get sort weight from product tags\n */\nexport const getTagsSortWeight = <\n T extends {\n name: string;\n },\n>(\n tags: T[],\n site: SortSiteId,\n store: Nullish<StoreId>,\n): number | undefined => {\n let regExp = getSortWeightTagRegex(site, store);\n\n // Attempt to find a tag matching the regular expression\n let tag = regExp ? tags.find((tag) => regExp?.test(tag.name)) : undefined;\n\n // If no tag is found and store is not US, retry with StoreId.Us\n if (!tag && store !== StoreId.Us) {\n regExp = getSortWeightTagRegex(site, StoreId.Us);\n\n // If no regular expression is returned, exit early\n if (!regExp) {\n return undefined;\n }\n\n tag = tags.find((tag) => regExp?.test(tag.name));\n }\n\n if (!tag || !regExp) {\n return undefined;\n }\n\n const match = regExp.exec(tag.name)?.[1];\n\n return match ? parseInt(match) : undefined;\n};\n\n/**\n * Sort by tag weight which can be used in `Array.sort(sortByTagWeight(site, store))`\n */\nexport const sortByTagWeight =\n (site: SortSiteId, store?: Nullish<StoreId>) =>\n <T extends { tags: { name: string }[] }>(current: T, next: T): number => {\n // Fallback to \"-1\" to group them in to the back\n const currentSortWeight =\n getTagsSortWeight(current.tags, site, store) ?? -1;\n const nextSortWeight = getTagsSortWeight(next.tags, site, store) ?? -1;\n return normalizeSortResult(nextSortWeight - currentSortWeight);\n };\n"],"names":["SortSiteId","getSortWeightTagRegex","site","store","StoreId","Us","Ca","Eu","Me","Uk","Za","In","Sg","Jp","Br","Tw","Mx","Ph","checkUnreachable","getTagsSortWeight","tags","regExp","tag","find","test","name","match","exec","parseInt","sortByTagWeight","current","next","currentSortWeight","nextSortWeight","normalizeSortResult"],"mappings":";;;;;;;AAKY,IAAAA,UAAA,GAAA,gBAAAA,WAAL,IAAA;EAILA,YAAA,OAAQ,CAAA,GAAA,OAAA;EAIRA,YAAA,WAAY,CAAA,GAAA,WAAA;EARFA,OAAAA,WAAAA;AAAA,CAAA,EAAAA,UAAA,IAAA,CAAA,CAAA,CAAA;AAeZ,MAAMC,qBAAA,GAAwBA,CAC5BC,IAAA,EACAC,KACkB,KAAA;EAClB,QAAQD,IAAM;IACZ,KAAK,WAAsB,CAAA;MAAA;QAClB,OAAA,+BAAA;MACT;IACA,KAAK,OAAkB,CAAA;MAAA;QAErB,QAAQC,KAAO;UACb,KAAKC,SAAQ,CAAAA,OAAA,CAAAC,EAAA;YACJ,OAAA,yBAAA;UACT,KAAKD,SAAAA,CAAAA,OAAQ,CAAAE,EAAA;UACb,KAAKF,SAAAA,CAAAA,OAAQ,CAAAG,EAAA;UACb,KAAKH,SAAAA,CAAAA,OAAQ,CAAAI,EAAA;UACb,KAAKJ,SAAAA,CAAAA,OAAQ,CAAAK,EAAA;UACb,KAAKL,SAAAA,CAAAA,OAAQ,CAAAM,EAAA;UACb,KAAKN,SAAAA,CAAAA,OAAQ,CAAAO,EAAA;UACb,KAAKP,SAAAA,CAAAA,OAAQ,CAAAQ,EAAA;UACb,KAAKR,SAAAA,CAAAA,OAAQ,CAAAS,EAAA;UACb,KAAKT,SAAAA,CAAAA,OAAQ,CAAAU,EAAA;UACb,KAAKV,SAAAA,CAAAA,OAAQ,CAAAW,EAAA;UACb,KAAKX,SAAAA,CAAAA,OAAQ,CAAAY,EAAA;UACb,KAAKZ,SAAQ,CAAAA,OAAA,CAAAa,EAAA;YACJ,OAAA,+BAAA;UACT,KAAK,IAAA;UACL,KAAK,KAAW,CAAA;YAAA;cACP,OAAA,IAAA;YACT;UACA;YACEC,MAAA,CAAAA,gBAAA,CAAiBf,KAA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ClD,MAAM8B,iBAAiBd,iBAAkB,CAAAY,IAAA,CAAKX,IAAM,EAAAlB,IAAA,EAAMC,KAAK,CAAK,IAAA,CAAA,CAAA;EAC7D,OAAA+B,KAAA,CAAAA,mBAAA,CAAoBD,iBAAiBD,iBAAiB,CAAA;AAC/D,CAAA;;;"}
1
+ {"version":3,"file":"product.js","sources":["../../src/utils/product.ts"],"sourcesContent":["import type { Nullish } from \"../types\";\nimport { StoreId } from \"../types\";\nimport { normalizeSortResult } from \"./array\";\nimport { checkUnreachable } from \"./errors\";\n\nexport enum SortSiteId {\n /**\n * Store.ui.com\n */\n Store = \"store\",\n /**\n * Techspecs.ui.com\n */\n Techspecs = \"techspecs\",\n}\n\n/**\n * Get correct sort weight tag regex based on site in which\n * the product is being displayed and the store\n */\nconst getSortWeightTagRegex = (\n site: SortSiteId,\n store: Nullish<StoreId>,\n): RegExp | null => {\n switch (site) {\n case SortSiteId.Techspecs: {\n return /techspecs-sort-weight:(-?\\d+)/;\n }\n case SortSiteId.Store: {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (store) {\n case StoreId.Us:\n return /pro-sort-weight:(-?\\d+)/;\n case StoreId.Ca:\n case StoreId.Cn:\n case StoreId.Eu:\n case StoreId.Me:\n case StoreId.Uk:\n case StoreId.Za:\n case StoreId.In:\n case StoreId.Sg:\n case StoreId.Jp:\n case StoreId.Br:\n case StoreId.Tw:\n case StoreId.Mx:\n case StoreId.Ph:\n return /pro-sort-weight:(-?\\d+):other/;\n case null:\n case undefined: {\n return null;\n }\n default:\n checkUnreachable(store);\n return null;\n }\n }\n\n default: {\n checkUnreachable(site);\n return null;\n }\n }\n};\n\n/**\n * Get sort weight from product tags\n */\nexport const getTagsSortWeight = <\n T extends {\n name: string;\n },\n>(\n tags: T[],\n site: SortSiteId,\n store: Nullish<StoreId>,\n): number | undefined => {\n let regExp = getSortWeightTagRegex(site, store);\n\n // Attempt to find a tag matching the regular expression\n let tag = regExp ? tags.find((tag) => regExp?.test(tag.name)) : undefined;\n\n // If no tag is found and store is not US, retry with StoreId.Us\n if (!tag && store !== StoreId.Us) {\n regExp = getSortWeightTagRegex(site, StoreId.Us);\n\n // If no regular expression is returned, exit early\n if (!regExp) {\n return undefined;\n }\n\n tag = tags.find((tag) => regExp?.test(tag.name));\n }\n\n if (!tag || !regExp) {\n return undefined;\n }\n\n const match = regExp.exec(tag.name)?.[1];\n\n return match ? parseInt(match) : undefined;\n};\n\n/**\n * Sort by tag weight which can be used in `Array.sort(sortByTagWeight(site, store))`\n */\nexport const sortByTagWeight =\n (site: SortSiteId, store?: Nullish<StoreId>) =>\n <T extends { tags: { name: string }[] }>(current: T, next: T): number => {\n // Fallback to \"-1\" to group them in to the back\n const currentSortWeight =\n getTagsSortWeight(current.tags, site, store) ?? -1;\n const nextSortWeight = getTagsSortWeight(next.tags, site, store) ?? -1;\n return normalizeSortResult(nextSortWeight - currentSortWeight);\n };\n"],"names":["SortSiteId","getSortWeightTagRegex","site","store","StoreId","Us","Ca","Cn","Eu","Me","Uk","Za","In","Sg","Jp","Br","Tw","Mx","Ph","checkUnreachable","getTagsSortWeight","tags","regExp","tag","find","test","name","match","exec","parseInt","sortByTagWeight","current","next","currentSortWeight","nextSortWeight","normalizeSortResult"],"mappings":";;;;;;;AAKY,IAAAA,UAAA,GAAA,gBAAAA,WAAL,IAAA;EAILA,YAAA,OAAQ,CAAA,GAAA,OAAA;EAIRA,YAAA,WAAY,CAAA,GAAA,WAAA;EARFA,OAAAA,WAAAA;AAAA,CAAA,EAAAA,UAAA,IAAA,CAAA,CAAA,CAAA;AAeZ,MAAMC,qBAAA,GAAwBA,CAC5BC,IAAA,EACAC,KACkB,KAAA;EAClB,QAAQD,IAAM;IACZ,KAAK,WAAsB,CAAA;MAAA;QAClB,OAAA,+BAAA;MACT;IACA,KAAK,OAAkB,CAAA;MAAA;QAErB,QAAQC,KAAO;UACb,KAAKC,SAAQ,CAAAA,OAAA,CAAAC,EAAA;YACJ,OAAA,yBAAA;UACT,KA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AA,OAAA,CAAQC,EAAI,EAAA;IACvBiB,MAAA,GAAArB,qBAAA,CAAsBC,IAAM,EAAAE,SAAA,CAAAA,OAAA,CAAQC,EAAE,CAAA;IAG/C,IAAI,CAACiB,MAAQ,EAAA;MACJ,OAAA,KAAA,CAAA;IACT;IAEMC,GAAA,GAAAF,IAAA,CAAKG,KAAMD,IAAAA,IAAQD,QAAQG,IAAKF,CAAAA,IAAAA,CAAIG,IAAI,CAAC,CAAA;EACjD;EAEI,IAAA,CAACH,GAAO,IAAA,CAACD,MAAQ,EAAA;IACZ,OAAA,KAAA,CAAA;EACT;EAEA,MAAMK,QAAQL,MAAO,CAAAM,IAAA,CAAKL,GAAI,CAAAG,IAAI,IAAI,CAAC,CAAA;EAEhC,OAAAC,KAAA,GAAQE,QAAS,CAAAF,KAAK,CAAI,GAAA,KAAA,CAAA;AACnC,CAAA;AAKO,MAAMG,kBACXA,CAAC5B,IAAA,EAAkBC,KACnB,KAAA,CAAyC4B,SAAYC,IAAoB,KAAA;EAEvE,MAAMC,oBACJb,iBAAkB,CAAAW,OAAA,CAAQV,IAAM,EAAAnB,IAAA,EAAMC,KAAK,CAAK,IAAA,CAAA,CAAA;EAClD,MAAM+B,iBAAiBd,iBAAkB,CAAAY,IAAA,CAAKX,IAAM,EAAAnB,IAAA,EAAMC,KAAK,CAAK,IAAA,CAAA,CAAA;EAC7D,OAAAgC,KAAA,CAAAA,mBAAA,CAAoBD,iBAAiBD,iBAAiB,CAAA;AAC/D,CAAA;;;"}
@@ -20,6 +20,7 @@ const getSortWeightTagRegex = (site, store) => {
20
20
  case StoreId.Us:
21
21
  return /pro-sort-weight:(-?\d+)/;
22
22
  case StoreId.Ca:
23
+ case StoreId.Cn:
23
24
  case StoreId.Eu:
24
25
  case StoreId.Me:
25
26
  case StoreId.Uk:
@@ -1 +1 @@
1
- {"version":3,"file":"product.mjs","sources":["../../src/utils/product.ts"],"sourcesContent":["import type { Nullish } from \"../types\";\nimport { StoreId } from \"../types\";\nimport { normalizeSortResult } from \"./array\";\nimport { checkUnreachable } from \"./errors\";\n\nexport enum SortSiteId {\n /**\n * Store.ui.com\n */\n Store = \"store\",\n /**\n * Techspecs.ui.com\n */\n Techspecs = \"techspecs\",\n}\n\n/**\n * Get correct sort weight tag regex based on site in which\n * the product is being displayed and the store\n */\nconst getSortWeightTagRegex = (\n site: SortSiteId,\n store: Nullish<StoreId>,\n): RegExp | null => {\n switch (site) {\n case SortSiteId.Techspecs: {\n return /techspecs-sort-weight:(-?\\d+)/;\n }\n case SortSiteId.Store: {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (store) {\n case StoreId.Us:\n return /pro-sort-weight:(-?\\d+)/;\n case StoreId.Ca:\n case StoreId.Eu:\n case StoreId.Me:\n case StoreId.Uk:\n case StoreId.Za:\n case StoreId.In:\n case StoreId.Sg:\n case StoreId.Jp:\n case StoreId.Br:\n case StoreId.Tw:\n case StoreId.Mx:\n case StoreId.Ph:\n return /pro-sort-weight:(-?\\d+):other/;\n case null:\n case undefined: {\n return null;\n }\n default:\n checkUnreachable(store);\n return null;\n }\n }\n\n default: {\n checkUnreachable(site);\n return null;\n }\n }\n};\n\n/**\n * Get sort weight from product tags\n */\nexport const getTagsSortWeight = <\n T extends {\n name: string;\n },\n>(\n tags: T[],\n site: SortSiteId,\n store: Nullish<StoreId>,\n): number | undefined => {\n let regExp = getSortWeightTagRegex(site, store);\n\n // Attempt to find a tag matching the regular expression\n let tag = regExp ? tags.find((tag) => regExp?.test(tag.name)) : undefined;\n\n // If no tag is found and store is not US, retry with StoreId.Us\n if (!tag && store !== StoreId.Us) {\n regExp = getSortWeightTagRegex(site, StoreId.Us);\n\n // If no regular expression is returned, exit early\n if (!regExp) {\n return undefined;\n }\n\n tag = tags.find((tag) => regExp?.test(tag.name));\n }\n\n if (!tag || !regExp) {\n return undefined;\n }\n\n const match = regExp.exec(tag.name)?.[1];\n\n return match ? parseInt(match) : undefined;\n};\n\n/**\n * Sort by tag weight which can be used in `Array.sort(sortByTagWeight(site, store))`\n */\nexport const sortByTagWeight =\n (site: SortSiteId, store?: Nullish<StoreId>) =>\n <T extends { tags: { name: string }[] }>(current: T, next: T): number => {\n // Fallback to \"-1\" to group them in to the back\n const currentSortWeight =\n getTagsSortWeight(current.tags, site, store) ?? -1;\n const nextSortWeight = getTagsSortWeight(next.tags, site, store) ?? -1;\n return normalizeSortResult(nextSortWeight - currentSortWeight);\n };\n"],"names":["SortSiteId","getSortWeightTagRegex","site","store","StoreId","Us","Ca","Eu","Me","Uk","Za","In","Sg","Jp","Br","Tw","Mx","Ph","checkUnreachable","getTagsSortWeight","tags","regExp","tag","find","test","name","match","exec","parseInt","sortByTagWeight","current","next","currentSortWeight","nextSortWeight","normalizeSortResult"],"mappings":";;;;;AAKY,IAAAA,UAAA,GAAA,gBAAAA,WAAL,IAAA;EAILA,YAAA,OAAQ,CAAA,GAAA,OAAA;EAIRA,YAAA,WAAY,CAAA,GAAA,WAAA;EARFA,OAAAA,WAAAA;AAAA,CAAA,EAAAA,UAAA,IAAA,CAAA,CAAA,CAAA;AAeZ,MAAMC,qBAAA,GAAwBA,CAC5BC,IAAA,EACAC,KACkB,KAAA;EAClB,QAAQD,IAAM;IACZ,KAAK,WAAsB,CAAA;MAAA;QAClB,OAAA,+BAAA;MACT;IACA,KAAK,OAAkB,CAAA;MAAA;QAErB,QAAQC,KAAO;UACb,KAAKC,OAAQ,CAAAC,EAAA;YACJ,OAAA,yBAAA;UACT,KAAKD,OAAQ,CAAAE,EAAA;UACb,KAAKF,OAAQ,CAAAG,EAAA;UACb,KAAKH,OAAQ,CAAAI,EAAA;UACb,KAAKJ,OAAQ,CAAAK,EAAA;UACb,KAAKL,OAAQ,CAAAM,EAAA;UACb,KAAKN,OAAQ,CAAAO,EAAA;UACb,KAAKP,OAAQ,CAAAQ,EAAA;UACb,KAAKR,OAAQ,CAAAS,EAAA;UACb,KAAKT,OAAQ,CAAAU,EAAA;UACb,KAAKV,OAAQ,CAAAW,EAAA;UACb,K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C2B,SAAYC,IAAoB,KAAA;EAEvE,MAAMC,oBACJb,iBAAkB,CAAAW,OAAA,CAAQV,IAAM,EAAAlB,IAAA,EAAMC,KAAK,CAAK,IAAA,CAAA,CAAA;EAClD,MAAM8B,iBAAiBd,iBAAkB,CAAAY,IAAA,CAAKX,IAAM,EAAAlB,IAAA,EAAMC,KAAK,CAAK,IAAA,CAAA,CAAA;EAC7D,OAAA+B,mBAAA,CAAoBD,iBAAiBD,iBAAiB,CAAA;AAC/D,CAAA;"}
1
+ {"version":3,"file":"product.mjs","sources":["../../src/utils/product.ts"],"sourcesContent":["import type { Nullish } from \"../types\";\nimport { StoreId } from \"../types\";\nimport { normalizeSortResult } from \"./array\";\nimport { checkUnreachable } from \"./errors\";\n\nexport enum SortSiteId {\n /**\n * Store.ui.com\n */\n Store = \"store\",\n /**\n * Techspecs.ui.com\n */\n Techspecs = \"techspecs\",\n}\n\n/**\n * Get correct sort weight tag regex based on site in which\n * the product is being displayed and the store\n */\nconst getSortWeightTagRegex = (\n site: SortSiteId,\n store: Nullish<StoreId>,\n): RegExp | null => {\n switch (site) {\n case SortSiteId.Techspecs: {\n return /techspecs-sort-weight:(-?\\d+)/;\n }\n case SortSiteId.Store: {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (store) {\n case StoreId.Us:\n return /pro-sort-weight:(-?\\d+)/;\n case StoreId.Ca:\n case StoreId.Cn:\n case StoreId.Eu:\n case StoreId.Me:\n case StoreId.Uk:\n case StoreId.Za:\n case StoreId.In:\n case StoreId.Sg:\n case StoreId.Jp:\n case StoreId.Br:\n case StoreId.Tw:\n case StoreId.Mx:\n case StoreId.Ph:\n return /pro-sort-weight:(-?\\d+):other/;\n case null:\n case undefined: {\n return null;\n }\n default:\n checkUnreachable(store);\n return null;\n }\n }\n\n default: {\n checkUnreachable(site);\n return null;\n }\n }\n};\n\n/**\n * Get sort weight from product tags\n */\nexport const getTagsSortWeight = <\n T extends {\n name: string;\n },\n>(\n tags: T[],\n site: SortSiteId,\n store: Nullish<StoreId>,\n): number | undefined => {\n let regExp = getSortWeightTagRegex(site, store);\n\n // Attempt to find a tag matching the regular expression\n let tag = regExp ? tags.find((tag) => regExp?.test(tag.name)) : undefined;\n\n // If no tag is found and store is not US, retry with StoreId.Us\n if (!tag && store !== StoreId.Us) {\n regExp = getSortWeightTagRegex(site, StoreId.Us);\n\n // If no regular expression is returned, exit early\n if (!regExp) {\n return undefined;\n }\n\n tag = tags.find((tag) => regExp?.test(tag.name));\n }\n\n if (!tag || !regExp) {\n return undefined;\n }\n\n const match = regExp.exec(tag.name)?.[1];\n\n return match ? parseInt(match) : undefined;\n};\n\n/**\n * Sort by tag weight which can be used in `Array.sort(sortByTagWeight(site, store))`\n */\nexport const sortByTagWeight =\n (site: SortSiteId, store?: Nullish<StoreId>) =>\n <T extends { tags: { name: string }[] }>(current: T, next: T): number => {\n // Fallback to \"-1\" to group them in to the back\n const currentSortWeight =\n getTagsSortWeight(current.tags, site, store) ?? -1;\n const nextSortWeight = getTagsSortWeight(next.tags, site, store) ?? -1;\n return normalizeSortResult(nextSortWeight - currentSortWeight);\n };\n"],"names":["SortSiteId","getSortWeightTagRegex","site","store","StoreId","Us","Ca","Cn","Eu","Me","Uk","Za","In","Sg","Jp","Br","Tw","Mx","Ph","checkUnreachable","getTagsSortWeight","tags","regExp","tag","find","test","name","match","exec","parseInt","sortByTagWeight","current","next","currentSortWeight","nextSortWeight","normalizeSortResult"],"mappings":";;;;;AAKY,IAAAA,UAAA,GAAA,gBAAAA,WAAL,IAAA;EAILA,YAAA,OAAQ,CAAA,GAAA,OAAA;EAIRA,YAAA,WAAY,CAAA,GAAA,WAAA;EARFA,OAAAA,WAAAA;AAAA,CAAA,EAAAA,UAAA,IAAA,CAAA,CAAA,CAAA;AAeZ,MAAMC,qBAAA,GAAwBA,CAC5BC,IAAA,EACAC,KACkB,KAAA;EAClB,QAAQD,IAAM;IACZ,KAAK,WAAsB,CAAA;MAAA;QAClB,OAAA,+BAAA;MACT;I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ACiB,MAAQ,EAAA;MACJ,OAAA,KAAA,CAAA;IACT;IAEMC,GAAA,GAAAF,IAAA,CAAKG,KAAMD,IAAAA,IAAQD,QAAQG,IAAKF,CAAAA,IAAAA,CAAIG,IAAI,CAAC,CAAA;EACjD;EAEI,IAAA,CAACH,GAAO,IAAA,CAACD,MAAQ,EAAA;IACZ,OAAA,KAAA,CAAA;EACT;EAEA,MAAMK,QAAQL,MAAO,CAAAM,IAAA,CAAKL,GAAI,CAAAG,IAAI,IAAI,CAAC,CAAA;EAEhC,OAAAC,KAAA,GAAQE,QAAS,CAAAF,KAAK,CAAI,GAAA,KAAA,CAAA;AACnC,CAAA;AAKO,MAAMG,kBACXA,CAAC5B,IAAA,EAAkBC,KACnB,KAAA,CAAyC4B,SAAYC,IAAoB,KAAA;EAEvE,MAAMC,oBACJb,iBAAkB,CAAAW,OAAA,CAAQV,IAAM,EAAAnB,IAAA,EAAMC,KAAK,CAAK,IAAA,CAAA,CAAA;EAClD,MAAM+B,iBAAiBd,iBAAkB,CAAAY,IAAA,CAAKX,IAAM,EAAAnB,IAAA,EAAMC,KAAK,CAAK,IAAA,CAAA,CAAA;EAC7D,OAAAgC,mBAAA,CAAoBD,iBAAiBD,iBAAiB,CAAA;AAC/D,CAAA;"}
@@ -48,6 +48,7 @@ const getStoreTimeZone = storeId => {
48
48
  label: "SGT",
49
49
  timezone: "Asia/Singapore"
50
50
  };
51
+ case generated.StoreId.Cn:
51
52
  case generated.StoreId.Tw:
52
53
  return {
53
54
  label: "CST",
@@ -1 +1 @@
1
- {"version":3,"file":"sales.js","sources":["../../src/utils/sales.ts"],"sourcesContent":["import dayjs, { extend } from \"dayjs\";\nimport duration from \"dayjs/plugin/duration\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\n\nimport { StoreId } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\n\nextend(timezone);\nextend(duration);\nextend(utc);\n\n/**\n * Returns label and timezone for a given store according\n * to IANA timezone database\n * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\n */\nexport const getStoreTimeZone = (\n storeId: StoreId,\n): {\n label: string;\n timezone: string;\n} => {\n switch (storeId) {\n case StoreId.Br:\n return {\n label: \"UTC-3\",\n timezone: \"America/Fortaleza\",\n };\n case StoreId.Uk:\n return {\n label: \"GMT\",\n timezone: \"Etc/GMT\",\n };\n case StoreId.Eu:\n case StoreId.Za:\n return {\n label: \"EET\",\n timezone: \"EET\",\n };\n case StoreId.Me:\n return {\n label: \"GST\",\n timezone: \"Asia/Dubai\",\n };\n case StoreId.Sg:\n return {\n label: \"SGT\",\n timezone: \"Asia/Singapore\",\n };\n case StoreId.Tw:\n return {\n label: \"CST\",\n timezone: \"Asia/Shanghai\",\n };\n case StoreId.Jp:\n return {\n label: \"JST\",\n timezone: \"Asia/Tokyo\",\n };\n case StoreId.Ca:\n case StoreId.Us:\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n case StoreId.Mx:\n return {\n label: \"CST\",\n timezone: \"America/Mexico_City\",\n };\n case StoreId.In:\n return {\n label: \"IST\",\n timezone: \"Asia/Kolkata\",\n };\n case StoreId.Ph:\n return {\n label: \"PHT\",\n timezone: \"Asia/Manila\",\n };\n default:\n checkUnreachable(storeId);\n // Fallback to US/CA timezone\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n }\n};\n\nexport interface TimeLeft {\n days: number;\n hours: number;\n minutes: number;\n seconds: number;\n}\n\nexport type SaleEndMethod = (storeId: StoreId) => TimeLeft | null;\n\n/**\n * Returns the time left until the end of the sale for a given store\n * @returns {SaleEndMethod} TimeLeft object if the sale is still active, null otherwise\n */\nexport const getSaleEndMethod =\n (saleEndDatetime: string): SaleEndMethod =>\n (storeId: StoreId): TimeLeft | null => {\n const { timezone: storeTimezone } = getStoreTimeZone(storeId);\n\n const now = dayjs().tz(storeTimezone); // Current time in the store's timezone\n\n const endOfSaleDatetime = dayjs.tz(saleEndDatetime, storeTimezone); // The sale's end datetime in the store's timezone\n\n // If it is passed the end of sale datetime, return null\n if (now.isAfter(endOfSaleDatetime)) {\n return null;\n }\n\n const diff = dayjs.duration(endOfSaleDatetime.diff(now));\n\n return {\n days: diff.days(),\n hours: diff.hours(),\n minutes: diff.minutes(),\n seconds: diff.seconds(),\n };\n };\n\n// #############################################################################\n// Sales methods\n// #############################################################################\n/**\n * Black Friday Sale\n * Returns the time left until the end of Black Friday for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Black Friday, null otherwise\n */\nexport const getTimeUntilEndOfBlackFridayByStore = getSaleEndMethod(\n \"2024-12-02 23:59:59\",\n);\n\n/**\n * Holiday Sale\n * Returns the time left until the end of Holiday Sale for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Holiday Sale, null otherwise\n */\nexport const getTimeUntilEndOfHolidaySaleByStore = getSaleEndMethod(\n \"2024-12-27 23:59:59\",\n);\n"],"names":["extend","timezone","duration","utc","getStoreTimeZone","storeId","StoreId","Br","label","Uk","Eu","Za","Me","Sg","Tw","Jp","Ca","Us","Mx","In","Ph","checkUnreachable","getSaleEndMethod","saleEndDatetime","storeTimezone","now","dayjs","tz","endOfSaleDatetime","isAfter","diff","days","hours","minutes","seconds","getTimeUntilEndOfBlackFridayByStore","getTimeUntilEndOfHolidaySaleByStore"],"mappings":";;;;;;;;;;;;;;;;;;;AAQAA,KAAA,CAAAA,MAAA,CAAOC,iBAAQ,CAAA,SAAA,CAAA,CAAA;AACfD,KAAA,CAAAA,MAAA,CAAOE,iBAAQ,CAAA,SAAA,CAAA,CAAA;AACfF,KAAA,CAAAA,MAAA,CAAOG,YAAG,CAAA,SAAA,CAAA,CAAA;AAOG,MAAAC,gBAAA,GACXC,OAIG,IAAA;EACH,QAAQA,OAAS;IACf,KAAKC,SAAQ,CAAAA,OAAA,CAAAC,EAAA;MACJ,OAAA;QACLC,KAAO,EAAA,OAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,SAAQ,CAAAA,OAAA,CAAA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A;MAEjB,OAAA;QACLG,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;EACJ;AACF,CAAA;AAeO,MAAMqB,gBACX,GAACC,eACD,IAAClB,OAAsC,IAAA;EACrC,MAAM;IAAEJ,QAAA,EAAUuB;EAAc,CAAA,GAAIpB,iBAAiBC,OAAO,CAAA;EAE5D,MAAMoB,GAAM,GAAAC,cAAA,CAAA,SAAA,CAAA,CAAA,CAAQ,CAAAC,EAAA,CAAGH,aAAa,CAAA;EAEpC,MAAMI,iBAAoB,GAAAF,cAAA,CAAA,SAAA,CAAA,CAAMC,EAAG,CAAAJ,eAAA,EAAiBC,aAAa,CAAA;EAG7D,IAAAC,GAAA,CAAII,OAAQ,CAAAD,iBAAiB,CAAG,EAAA;IAC3B,OAAA,IAAA;EACT;EAEA,MAAME,OAAOJ,cAAAA,CAAAA,SAAAA,CAAM,CAAAxB,QAAA,CAAS0B,iBAAkB,CAAAE,IAAA,CAAKL,GAAG,CAAC,CAAA;EAEhD,OAAA;IACLM,IAAA,EAAMD,KAAKC,IAAK,CAAA,CAAA;IAChBC,KAAA,EAAOF,KAAKE,KAAM,CAAA,CAAA;IAClBC,OAAA,EAASH,KAAKG,OAAQ,CAAA,CAAA;IACtBC,OAAA,EAASJ,KAAKI,OAAQ,CAAA;EAAA,CACxB;AACF,CAAA;AAUK,MAAMC,mCAAsC,GAAAb,gBAAA,CACjD,qBACF,CAAA;AAOO,MAAMc,mCAAsC,GAAAd,gBAAA,CACjD,qBACF,CAAA;;;;"}
1
+ {"version":3,"file":"sales.js","sources":["../../src/utils/sales.ts"],"sourcesContent":["import dayjs, { extend } from \"dayjs\";\nimport duration from \"dayjs/plugin/duration\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\n\nimport { StoreId } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\n\nextend(timezone);\nextend(duration);\nextend(utc);\n\n/**\n * Returns label and timezone for a given store according\n * to IANA timezone database\n * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\n */\nexport const getStoreTimeZone = (\n storeId: StoreId,\n): {\n label: string;\n timezone: string;\n} => {\n switch (storeId) {\n case StoreId.Br:\n return {\n label: \"UTC-3\",\n timezone: \"America/Fortaleza\",\n };\n case StoreId.Uk:\n return {\n label: \"GMT\",\n timezone: \"Etc/GMT\",\n };\n case StoreId.Eu:\n case StoreId.Za:\n return {\n label: \"EET\",\n timezone: \"EET\",\n };\n case StoreId.Me:\n return {\n label: \"GST\",\n timezone: \"Asia/Dubai\",\n };\n case StoreId.Sg:\n return {\n label: \"SGT\",\n timezone: \"Asia/Singapore\",\n };\n case StoreId.Cn:\n case StoreId.Tw:\n return {\n label: \"CST\",\n timezone: \"Asia/Shanghai\",\n };\n case StoreId.Jp:\n return {\n label: \"JST\",\n timezone: \"Asia/Tokyo\",\n };\n case StoreId.Ca:\n case StoreId.Us:\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n case StoreId.Mx:\n return {\n label: \"CST\",\n timezone: \"America/Mexico_City\",\n };\n case StoreId.In:\n return {\n label: \"IST\",\n timezone: \"Asia/Kolkata\",\n };\n case StoreId.Ph:\n return {\n label: \"PHT\",\n timezone: \"Asia/Manila\",\n };\n default:\n checkUnreachable(storeId);\n // Fallback to US/CA timezone\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n }\n};\n\nexport interface TimeLeft {\n days: number;\n hours: number;\n minutes: number;\n seconds: number;\n}\n\nexport type SaleEndMethod = (storeId: StoreId) => TimeLeft | null;\n\n/**\n * Returns the time left until the end of the sale for a given store\n * @returns {SaleEndMethod} TimeLeft object if the sale is still active, null otherwise\n */\nexport const getSaleEndMethod =\n (saleEndDatetime: string): SaleEndMethod =>\n (storeId: StoreId): TimeLeft | null => {\n const { timezone: storeTimezone } = getStoreTimeZone(storeId);\n\n const now = dayjs().tz(storeTimezone); // Current time in the store's timezone\n\n const endOfSaleDatetime = dayjs.tz(saleEndDatetime, storeTimezone); // The sale's end datetime in the store's timezone\n\n // If it is passed the end of sale datetime, return null\n if (now.isAfter(endOfSaleDatetime)) {\n return null;\n }\n\n const diff = dayjs.duration(endOfSaleDatetime.diff(now));\n\n return {\n days: diff.days(),\n hours: diff.hours(),\n minutes: diff.minutes(),\n seconds: diff.seconds(),\n };\n };\n\n// #############################################################################\n// Sales methods\n// #############################################################################\n/**\n * Black Friday Sale\n * Returns the time left until the end of Black Friday for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Black Friday, null otherwise\n */\nexport const getTimeUntilEndOfBlackFridayByStore = getSaleEndMethod(\n \"2024-12-02 23:59:59\",\n);\n\n/**\n * Holiday Sale\n * Returns the time left until the end of Holiday Sale for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Holiday Sale, null otherwise\n */\nexport const getTimeUntilEndOfHolidaySaleByStore = getSaleEndMethod(\n \"2024-12-27 23:59:59\",\n);\n"],"names":["extend","timezone","duration","utc","getStoreTimeZone","storeId","StoreId","Br","label","Uk","Eu","Za","Me","Sg","Cn","Tw","Jp","Ca","Us","Mx","In","Ph","checkUnreachable","getSaleEndMethod","saleEndDatetime","storeTimezone","now","dayjs","tz","endOfSaleDatetime","isAfter","diff","days","hours","minutes","seconds","getTimeUntilEndOfBlackFridayByStore","getTimeUntilEndOfHolidaySaleByStore"],"mappings":";;;;;;;;;;;;;;;;;;;AAQAA,KAAA,CAAAA,MAAA,CAAOC,iBAAQ,CAAA,SAAA,CAAA,CAAA;AACfD,KAAA,CAAAA,MAAA,CAAOE,iBAAQ,CAAA,SAAA,CAAA,CAAA;AACfF,KAAA,CAAAA,MAAA,CAAOG,YAAG,CAAA,SAAA,CAAA,CAAA;AAOG,MAAAC,gBAAA,GACXC,OAIG,IAAA;EACH,QAAQA,OAAS;IACf,KAAKC,SAAQ,CAAAA,OAAA,CAAAC,EAAA;MACJ,OAAA;QACLC,KAAO,EAAA,OAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,SAAQ,CAAA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A,CACZ;IACF;MACEqB,MAAA,CAAAA,gBAAA,CAAiBjB,OAAO,CAAA;MAEjB,OAAA;QACLG,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;EACJ;AACF,CAAA;AAeO,MAAMsB,gBACX,GAACC,eACD,IAACnB,OAAsC,IAAA;EACrC,MAAM;IAAEJ,QAAA,EAAUwB;EAAc,CAAA,GAAIrB,iBAAiBC,OAAO,CAAA;EAE5D,MAAMqB,GAAM,GAAAC,cAAA,CAAA,SAAA,CAAA,CAAA,CAAQ,CAAAC,EAAA,CAAGH,aAAa,CAAA;EAEpC,MAAMI,iBAAoB,GAAAF,cAAA,CAAA,SAAA,CAAA,CAAMC,EAAG,CAAAJ,eAAA,EAAiBC,aAAa,CAAA;EAG7D,IAAAC,GAAA,CAAII,OAAQ,CAAAD,iBAAiB,CAAG,EAAA;IAC3B,OAAA,IAAA;EACT;EAEA,MAAME,OAAOJ,cAAAA,CAAAA,SAAAA,CAAM,CAAAzB,QAAA,CAAS2B,iBAAkB,CAAAE,IAAA,CAAKL,GAAG,CAAC,CAAA;EAEhD,OAAA;IACLM,IAAA,EAAMD,KAAKC,IAAK,CAAA,CAAA;IAChBC,KAAA,EAAOF,KAAKE,KAAM,CAAA,CAAA;IAClBC,OAAA,EAASH,KAAKG,OAAQ,CAAA,CAAA;IACtBC,OAAA,EAASJ,KAAKI,OAAQ,CAAA;EAAA,CACxB;AACF,CAAA;AAUK,MAAMC,mCAAsC,GAAAb,gBAAA,CACjD,qBACF,CAAA;AAOO,MAAMc,mCAAsC,GAAAd,gBAAA,CACjD,qBACF,CAAA;;;;"}
@@ -37,6 +37,7 @@ const getStoreTimeZone = storeId => {
37
37
  label: "SGT",
38
38
  timezone: "Asia/Singapore"
39
39
  };
40
+ case StoreId.Cn:
40
41
  case StoreId.Tw:
41
42
  return {
42
43
  label: "CST",
@@ -1 +1 @@
1
- {"version":3,"file":"sales.mjs","sources":["../../src/utils/sales.ts"],"sourcesContent":["import dayjs, { extend } from \"dayjs\";\nimport duration from \"dayjs/plugin/duration\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\n\nimport { StoreId } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\n\nextend(timezone);\nextend(duration);\nextend(utc);\n\n/**\n * Returns label and timezone for a given store according\n * to IANA timezone database\n * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\n */\nexport const getStoreTimeZone = (\n storeId: StoreId,\n): {\n label: string;\n timezone: string;\n} => {\n switch (storeId) {\n case StoreId.Br:\n return {\n label: \"UTC-3\",\n timezone: \"America/Fortaleza\",\n };\n case StoreId.Uk:\n return {\n label: \"GMT\",\n timezone: \"Etc/GMT\",\n };\n case StoreId.Eu:\n case StoreId.Za:\n return {\n label: \"EET\",\n timezone: \"EET\",\n };\n case StoreId.Me:\n return {\n label: \"GST\",\n timezone: \"Asia/Dubai\",\n };\n case StoreId.Sg:\n return {\n label: \"SGT\",\n timezone: \"Asia/Singapore\",\n };\n case StoreId.Tw:\n return {\n label: \"CST\",\n timezone: \"Asia/Shanghai\",\n };\n case StoreId.Jp:\n return {\n label: \"JST\",\n timezone: \"Asia/Tokyo\",\n };\n case StoreId.Ca:\n case StoreId.Us:\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n case StoreId.Mx:\n return {\n label: \"CST\",\n timezone: \"America/Mexico_City\",\n };\n case StoreId.In:\n return {\n label: \"IST\",\n timezone: \"Asia/Kolkata\",\n };\n case StoreId.Ph:\n return {\n label: \"PHT\",\n timezone: \"Asia/Manila\",\n };\n default:\n checkUnreachable(storeId);\n // Fallback to US/CA timezone\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n }\n};\n\nexport interface TimeLeft {\n days: number;\n hours: number;\n minutes: number;\n seconds: number;\n}\n\nexport type SaleEndMethod = (storeId: StoreId) => TimeLeft | null;\n\n/**\n * Returns the time left until the end of the sale for a given store\n * @returns {SaleEndMethod} TimeLeft object if the sale is still active, null otherwise\n */\nexport const getSaleEndMethod =\n (saleEndDatetime: string): SaleEndMethod =>\n (storeId: StoreId): TimeLeft | null => {\n const { timezone: storeTimezone } = getStoreTimeZone(storeId);\n\n const now = dayjs().tz(storeTimezone); // Current time in the store's timezone\n\n const endOfSaleDatetime = dayjs.tz(saleEndDatetime, storeTimezone); // The sale's end datetime in the store's timezone\n\n // If it is passed the end of sale datetime, return null\n if (now.isAfter(endOfSaleDatetime)) {\n return null;\n }\n\n const diff = dayjs.duration(endOfSaleDatetime.diff(now));\n\n return {\n days: diff.days(),\n hours: diff.hours(),\n minutes: diff.minutes(),\n seconds: diff.seconds(),\n };\n };\n\n// #############################################################################\n// Sales methods\n// #############################################################################\n/**\n * Black Friday Sale\n * Returns the time left until the end of Black Friday for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Black Friday, null otherwise\n */\nexport const getTimeUntilEndOfBlackFridayByStore = getSaleEndMethod(\n \"2024-12-02 23:59:59\",\n);\n\n/**\n * Holiday Sale\n * Returns the time left until the end of Holiday Sale for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Holiday Sale, null otherwise\n */\nexport const getTimeUntilEndOfHolidaySaleByStore = getSaleEndMethod(\n \"2024-12-27 23:59:59\",\n);\n"],"names":["extend","timezone","duration","utc","getStoreTimeZone","storeId","StoreId","Br","label","Uk","Eu","Za","Me","Sg","Tw","Jp","Ca","Us","Mx","In","Ph","checkUnreachable","getSaleEndMethod","saleEndDatetime","storeTimezone","now","dayjs","tz","endOfSaleDatetime","isAfter","diff","days","hours","minutes","seconds","getTimeUntilEndOfBlackFridayByStore","getTimeUntilEndOfHolidaySaleByStore"],"mappings":";;;;;;;;AAQAA,MAAA,CAAOC,QAAQ,CAAA;AACfD,MAAA,CAAOE,QAAQ,CAAA;AACfF,MAAA,CAAOG,GAAG,CAAA;AAOG,MAAAC,gBAAA,GACXC,OAIG,IAAA;EACH,QAAQA,OAAS;IACf,KAAKC,OAAQ,CAAAC,EAAA;MACJ,O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F,CAAA;AAeO,MAAMqB,gBACX,GAACC,eACD,IAAClB,OAAsC,IAAA;EACrC,MAAM;IAAEJ,QAAA,EAAUuB;EAAc,CAAA,GAAIpB,iBAAiBC,OAAO,CAAA;EAE5D,MAAMoB,GAAM,GAAAC,KAAA,CAAA,CAAQ,CAAAC,EAAA,CAAGH,aAAa,CAAA;EAEpC,MAAMI,iBAAoB,GAAAF,KAAA,CAAMC,EAAG,CAAAJ,eAAA,EAAiBC,aAAa,CAAA;EAG7D,IAAAC,GAAA,CAAII,OAAQ,CAAAD,iBAAiB,CAAG,EAAA;IAC3B,OAAA,IAAA;EACT;EAEA,MAAME,OAAOJ,KAAM,CAAAxB,QAAA,CAAS0B,iBAAkB,CAAAE,IAAA,CAAKL,GAAG,CAAC,CAAA;EAEhD,OAAA;IACLM,IAAA,EAAMD,KAAKC,IAAK,CAAA,CAAA;IAChBC,KAAA,EAAOF,KAAKE,KAAM,CAAA,CAAA;IAClBC,OAAA,EAASH,KAAKG,OAAQ,CAAA,CAAA;IACtBC,OAAA,EAASJ,KAAKI,OAAQ,CAAA;EAAA,CACxB;AACF,CAAA;AAUK,MAAMC,mCAAsC,GAAAb,gBAAA,CACjD,qBACF,CAAA;AAOO,MAAMc,mCAAsC,GAAAd,gBAAA,CACjD,qBACF,CAAA;"}
1
+ {"version":3,"file":"sales.mjs","sources":["../../src/utils/sales.ts"],"sourcesContent":["import dayjs, { extend } from \"dayjs\";\nimport duration from \"dayjs/plugin/duration\";\nimport timezone from \"dayjs/plugin/timezone\";\nimport utc from \"dayjs/plugin/utc\";\n\nimport { StoreId } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\n\nextend(timezone);\nextend(duration);\nextend(utc);\n\n/**\n * Returns label and timezone for a given store according\n * to IANA timezone database\n * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones\n */\nexport const getStoreTimeZone = (\n storeId: StoreId,\n): {\n label: string;\n timezone: string;\n} => {\n switch (storeId) {\n case StoreId.Br:\n return {\n label: \"UTC-3\",\n timezone: \"America/Fortaleza\",\n };\n case StoreId.Uk:\n return {\n label: \"GMT\",\n timezone: \"Etc/GMT\",\n };\n case StoreId.Eu:\n case StoreId.Za:\n return {\n label: \"EET\",\n timezone: \"EET\",\n };\n case StoreId.Me:\n return {\n label: \"GST\",\n timezone: \"Asia/Dubai\",\n };\n case StoreId.Sg:\n return {\n label: \"SGT\",\n timezone: \"Asia/Singapore\",\n };\n case StoreId.Cn:\n case StoreId.Tw:\n return {\n label: \"CST\",\n timezone: \"Asia/Shanghai\",\n };\n case StoreId.Jp:\n return {\n label: \"JST\",\n timezone: \"Asia/Tokyo\",\n };\n case StoreId.Ca:\n case StoreId.Us:\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n case StoreId.Mx:\n return {\n label: \"CST\",\n timezone: \"America/Mexico_City\",\n };\n case StoreId.In:\n return {\n label: \"IST\",\n timezone: \"Asia/Kolkata\",\n };\n case StoreId.Ph:\n return {\n label: \"PHT\",\n timezone: \"Asia/Manila\",\n };\n default:\n checkUnreachable(storeId);\n // Fallback to US/CA timezone\n return {\n label: \"PST\",\n timezone: \"US/Pacific\",\n };\n }\n};\n\nexport interface TimeLeft {\n days: number;\n hours: number;\n minutes: number;\n seconds: number;\n}\n\nexport type SaleEndMethod = (storeId: StoreId) => TimeLeft | null;\n\n/**\n * Returns the time left until the end of the sale for a given store\n * @returns {SaleEndMethod} TimeLeft object if the sale is still active, null otherwise\n */\nexport const getSaleEndMethod =\n (saleEndDatetime: string): SaleEndMethod =>\n (storeId: StoreId): TimeLeft | null => {\n const { timezone: storeTimezone } = getStoreTimeZone(storeId);\n\n const now = dayjs().tz(storeTimezone); // Current time in the store's timezone\n\n const endOfSaleDatetime = dayjs.tz(saleEndDatetime, storeTimezone); // The sale's end datetime in the store's timezone\n\n // If it is passed the end of sale datetime, return null\n if (now.isAfter(endOfSaleDatetime)) {\n return null;\n }\n\n const diff = dayjs.duration(endOfSaleDatetime.diff(now));\n\n return {\n days: diff.days(),\n hours: diff.hours(),\n minutes: diff.minutes(),\n seconds: diff.seconds(),\n };\n };\n\n// #############################################################################\n// Sales methods\n// #############################################################################\n/**\n * Black Friday Sale\n * Returns the time left until the end of Black Friday for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Black Friday, null otherwise\n */\nexport const getTimeUntilEndOfBlackFridayByStore = getSaleEndMethod(\n \"2024-12-02 23:59:59\",\n);\n\n/**\n * Holiday Sale\n * Returns the time left until the end of Holiday Sale for a given store\n * @returns {TimeLeft | null} TimeLeft object if it is still Holiday Sale, null otherwise\n */\nexport const getTimeUntilEndOfHolidaySaleByStore = getSaleEndMethod(\n \"2024-12-27 23:59:59\",\n);\n"],"names":["extend","timezone","duration","utc","getStoreTimeZone","storeId","StoreId","Br","label","Uk","Eu","Za","Me","Sg","Cn","Tw","Jp","Ca","Us","Mx","In","Ph","checkUnreachable","getSaleEndMethod","saleEndDatetime","storeTimezone","now","dayjs","tz","endOfSaleDatetime","isAfter","diff","days","hours","minutes","seconds","getTimeUntilEndOfBlackFridayByStore","getTimeUntilEndOfHolidaySaleByStore"],"mappings":";;;;;;;;AAQAA,MAAA,CAAOC,QAAQ,CAAA;AACfD,MAAA,CAAOE,QAAQ,CAAA;AACfF,MAAA,CAAOG,GAAG,CAAA;AAOG,MAAAC,gBAAA,GACXC,OAIG,IAAA;EACH,QAAQA,OAAS;IACf,KAAKC,OAAQ,CAAAC,EAAA;MACJ,OAAA;QACLC,KAAO,EAAA,OAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAG,EAAA;MACJ,OAAA;QACLD,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAI,EAAA;IACb,KAAKJ,OAAQ,CAAAK,EAAA;MACJ,OAAA;QACLH,KAAO,EAAA,KAAA;QACPP,QAAU,EAAA;MAAA,CACZ;IACF,KAAKK,OAAQ,CAAAM,EAAA;MACJ,OAAA;QACLJ,K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AAAC,GAAA,CAAII,OAAQ,CAAAD,iBAAiB,CAAG,EAAA;IAC3B,OAAA,IAAA;EACT;EAEA,MAAME,OAAOJ,KAAM,CAAAzB,QAAA,CAAS2B,iBAAkB,CAAAE,IAAA,CAAKL,GAAG,CAAC,CAAA;EAEhD,OAAA;IACLM,IAAA,EAAMD,KAAKC,IAAK,CAAA,CAAA;IAChBC,KAAA,EAAOF,KAAKE,KAAM,CAAA,CAAA;IAClBC,OAAA,EAASH,KAAKG,OAAQ,CAAA,CAAA;IACtBC,OAAA,EAASJ,KAAKI,OAAQ,CAAA;EAAA,CACxB;AACF,CAAA;AAUK,MAAMC,mCAAsC,GAAAb,gBAAA,CACjD,qBACF,CAAA;AAOO,MAAMc,mCAAsC,GAAAd,gBAAA,CACjD,qBACF,CAAA;"}
@@ -27,6 +27,7 @@ const getFreeShippingDaysPerStore = storeId => {
27
27
  case generated.StoreId.Eu:
28
28
  case generated.StoreId.Uk:
29
29
  case generated.StoreId.In:
30
+ case generated.StoreId.Cn:
30
31
  case generated.StoreId.Br:
31
32
  {
32
33
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"shipping.js","sources":["../../src/utils/shipping.ts"],"sourcesContent":["import { StoreId } from \"../types\";\nimport type { Nullish } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\n\n/**\n * Utility to get how many days free shipping will be for a specific store, defaulting to a fallback value\n */\nexport const getFreeShippingDaysPerStore = (\n // Instead of using StoreId type using plain string so if we add a new store it won't break types as we already have\n // configured a explicity default behaviour\n storeId: Nullish<StoreId>,\n): Nullish<number> => {\n if (!storeId) {\n // Return undefined to indicate detect \"loading state\" as we can't determine it yet\n return undefined;\n }\n\n /**\n * Reasoning for values:\n * - Singapore - https://ui.slack.com/archives/C02CXF2Q7B4/p1709209947062139\n * - Brazil - we read dynamically latest option as free so there is no guarantee\n * - Japan - same as other just standard 5-days\n */\n switch (storeId) {\n case StoreId.Ca:\n case StoreId.Za:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Ph: {\n return 5;\n }\n case StoreId.Me: {\n return 2;\n }\n case StoreId.Us:\n case StoreId.Mx:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.In:\n case StoreId.Br: {\n // Return null to indicate \"no match\"\n return null;\n }\n\n default: {\n checkUnreachable(storeId);\n // Return null to indicate \"no match\"\n return null;\n }\n }\n};\n"],"names":["getFreeShippingDaysPerStore","storeId","StoreId","Ca","Za","Sg","Tw","Jp","Ph","Me","Us","Mx","Eu","Uk","In","Br","checkUnreachable"],"mappings":";;;;;;AAOa,MAAAA,2BAAA,GAGXC,OACoB,IAAA;EACpB,IAAI,CAACA,OAAS,EAAA;IAEL,OAAA,KAAA,CAAA;EACT;EAQA,QAAQA,OAAS;IACf,KAAKC,SAAAA,CAAAA,OAAQ,CAAAC,EAAA;IACb,KAAKD,SAAAA,CAAAA,OAAQ,CAAAE,EAAA;IACb,KAAKF,SAAAA,CAAAA,OAAQ,CAAAG,EAAA;IACb,KAAKH,SAAAA,CAAAA,OAAQ,CAAAI,EAAA;IACb,KAAKJ,SAAAA,CAAAA,OAAQ,CAAAK,EAAA;IACb,KAAKL,SAAAA,CAAAA,QAAQM,EAAI;MAAA;QACR,OAAA,CAAA;MACT;IACA,KAAKN,SAAAA,CAAAA,QAAQO,EAAI;MAAA;QACR,OAAA,CAAA;MACT;IACA,KAAKP,SAAAA,CAAAA,OAAQ,CAAAQ,EAAA;IACb,KAAKR,SAAAA,CAAAA,OAAQ,CAAAS,EAAA;IACb,KAAKT,SAAAA,CAAAA,OAAQ,CAAAU,EAAA;IACb,KAAKV,SAAAA,CAAAA,OAAQ,CAAAW,EAAA;IACb,KAAKX,SAAAA,CAAAA,OAAQ,CAAAY,EAAA;IACb,KAAKZ,SAAAA,CAAAA,QAAQa,EAAI;MAAA;QAER,OAAA,IAAA;MACT;IAEA;MAAS;QACPC,MAAA,CAAAA,gBAAA,CAAiBf,OAAO,CAAA;QAEjB,OAAA,IAAA;MACT;EACF;AACF,CAAA;"}
1
+ {"version":3,"file":"shipping.js","sources":["../../src/utils/shipping.ts"],"sourcesContent":["import { StoreId } from \"../types\";\nimport type { Nullish } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\n\n/**\n * Utility to get how many days free shipping will be for a specific store, defaulting to a fallback value\n */\nexport const getFreeShippingDaysPerStore = (\n // Instead of using StoreId type using plain string so if we add a new store it won't break types as we already have\n // configured a explicity default behaviour\n storeId: Nullish<StoreId>,\n): Nullish<number> => {\n if (!storeId) {\n // Return undefined to indicate detect \"loading state\" as we can't determine it yet\n return undefined;\n }\n\n /**\n * Reasoning for values:\n * - Singapore - https://ui.slack.com/archives/C02CXF2Q7B4/p1709209947062139\n * - Brazil - we read dynamically latest option as free so there is no guarantee\n * - Japan - same as other just standard 5-days\n */\n switch (storeId) {\n case StoreId.Ca:\n case StoreId.Za:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Ph: {\n return 5;\n }\n case StoreId.Me: {\n return 2;\n }\n case StoreId.Us:\n case StoreId.Mx:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.In:\n case StoreId.Cn:\n case StoreId.Br: {\n // Return null to indicate \"no match\"\n return null;\n }\n\n default: {\n checkUnreachable(storeId);\n // Return null to indicate \"no match\"\n return null;\n }\n }\n};\n"],"names":["getFreeShippingDaysPerStore","storeId","StoreId","Ca","Za","Sg","Tw","Jp","Ph","Me","Us","Mx","Eu","Uk","In","Cn","Br","checkUnreachable"],"mappings":";;;;;;AAOa,MAAAA,2BAAA,GAGXC,OACoB,IAAA;EACpB,IAAI,CAACA,OAAS,EAAA;IAEL,OAAA,KAAA,CAAA;EACT;EAQA,QAAQA,OAAS;IACf,KAAKC,SAAAA,CAAAA,OAAQ,CAAAC,EAAA;IACb,KAAKD,SAAAA,CAAAA,OAAQ,CAAAE,EAAA;IACb,KAAKF,SAAAA,CAAAA,OAAQ,CAAAG,EAAA;IACb,KAAKH,SAAAA,CAAAA,OAAQ,CAAAI,EAAA;IACb,KAAKJ,SAAAA,CAAAA,OAAQ,CAAAK,EAAA;IACb,KAAKL,SAAAA,CAAAA,QAAQM,EAAI;MAAA;QACR,OAAA,CAAA;MACT;IACA,KAAKN,SAAAA,CAAAA,QAAQO,EAAI;MAAA;QACR,OAAA,CAAA;MACT;IACA,KAAKP,SAAAA,CAAAA,OAAQ,CAAAQ,EAAA;IACb,KAAKR,SAAAA,CAAAA,OAAQ,CAAAS,EAAA;IACb,KAAKT,SAAAA,CAAAA,OAAQ,CAAAU,EAAA;IACb,KAAKV,SAAAA,CAAAA,OAAQ,CAAAW,EAAA;IACb,KAAKX,SAAAA,CAAAA,OAAQ,CAAAY,EAAA;IACb,KAAKZ,SAAAA,CAAAA,OAAQ,CAAAa,EAAA;IACb,KAAKb,SAAAA,CAAAA,QAAQc,EAAI;MAAA;QAER,OAAA,IAAA;MACT;IAEA;MAAS;QACPC,MAAA,CAAAA,gBAAA,CAAiBhB,OAAO,CAAA;QAEjB,OAAA,IAAA;MACT;EACF;AACF,CAAA;"}
@@ -25,6 +25,7 @@ const getFreeShippingDaysPerStore = storeId => {
25
25
  case StoreId.Eu:
26
26
  case StoreId.Uk:
27
27
  case StoreId.In:
28
+ case StoreId.Cn:
28
29
  case StoreId.Br:
29
30
  {
30
31
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"shipping.mjs","sources":["../../src/utils/shipping.ts"],"sourcesContent":["import { StoreId } from \"../types\";\nimport type { Nullish } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\n\n/**\n * Utility to get how many days free shipping will be for a specific store, defaulting to a fallback value\n */\nexport const getFreeShippingDaysPerStore = (\n // Instead of using StoreId type using plain string so if we add a new store it won't break types as we already have\n // configured a explicity default behaviour\n storeId: Nullish<StoreId>,\n): Nullish<number> => {\n if (!storeId) {\n // Return undefined to indicate detect \"loading state\" as we can't determine it yet\n return undefined;\n }\n\n /**\n * Reasoning for values:\n * - Singapore - https://ui.slack.com/archives/C02CXF2Q7B4/p1709209947062139\n * - Brazil - we read dynamically latest option as free so there is no guarantee\n * - Japan - same as other just standard 5-days\n */\n switch (storeId) {\n case StoreId.Ca:\n case StoreId.Za:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Ph: {\n return 5;\n }\n case StoreId.Me: {\n return 2;\n }\n case StoreId.Us:\n case StoreId.Mx:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.In:\n case StoreId.Br: {\n // Return null to indicate \"no match\"\n return null;\n }\n\n default: {\n checkUnreachable(storeId);\n // Return null to indicate \"no match\"\n return null;\n }\n }\n};\n"],"names":["getFreeShippingDaysPerStore","storeId","StoreId","Ca","Za","Sg","Tw","Jp","Ph","Me","Us","Mx","Eu","Uk","In","Br","checkUnreachable"],"mappings":";;;;AAOa,MAAAA,2BAAA,GAGXC,OACoB,IAAA;EACpB,IAAI,CAACA,OAAS,EAAA;IAEL,OAAA,KAAA,CAAA;EACT;EAQA,QAAQA,OAAS;IACf,KAAKC,OAAQ,CAAAC,EAAA;IACb,KAAKD,OAAQ,CAAAE,EAAA;IACb,KAAKF,OAAQ,CAAAG,EAAA;IACb,KAAKH,OAAQ,CAAAI,EAAA;IACb,KAAKJ,OAAQ,CAAAK,EAAA;IACb,KAAKL,QAAQM,EAAI;MAAA;QACR,OAAA,CAAA;MACT;IACA,KAAKN,QAAQO,EAAI;MAAA;QACR,OAAA,CAAA;MACT;IACA,KAAKP,OAAQ,CAAAQ,EAAA;IACb,KAAKR,OAAQ,CAAAS,EAAA;IACb,KAAKT,OAAQ,CAAAU,EAAA;IACb,KAAKV,OAAQ,CAAAW,EAAA;IACb,KAAKX,OAAQ,CAAAY,EAAA;IACb,KAAKZ,QAAQa,EAAI;MAAA;QAER,OAAA,IAAA;MACT;IAEA;MAAS;QACPC,gBAAA,CAAiBf,OAAO,CAAA;QAEjB,OAAA,IAAA;MACT;EACF;AACF,CAAA;"}
1
+ {"version":3,"file":"shipping.mjs","sources":["../../src/utils/shipping.ts"],"sourcesContent":["import { StoreId } from \"../types\";\nimport type { Nullish } from \"../types\";\nimport { checkUnreachable } from \"./errors\";\n\n/**\n * Utility to get how many days free shipping will be for a specific store, defaulting to a fallback value\n */\nexport const getFreeShippingDaysPerStore = (\n // Instead of using StoreId type using plain string so if we add a new store it won't break types as we already have\n // configured a explicity default behaviour\n storeId: Nullish<StoreId>,\n): Nullish<number> => {\n if (!storeId) {\n // Return undefined to indicate detect \"loading state\" as we can't determine it yet\n return undefined;\n }\n\n /**\n * Reasoning for values:\n * - Singapore - https://ui.slack.com/archives/C02CXF2Q7B4/p1709209947062139\n * - Brazil - we read dynamically latest option as free so there is no guarantee\n * - Japan - same as other just standard 5-days\n */\n switch (storeId) {\n case StoreId.Ca:\n case StoreId.Za:\n case StoreId.Sg:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Ph: {\n return 5;\n }\n case StoreId.Me: {\n return 2;\n }\n case StoreId.Us:\n case StoreId.Mx:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.In:\n case StoreId.Cn:\n case StoreId.Br: {\n // Return null to indicate \"no match\"\n return null;\n }\n\n default: {\n checkUnreachable(storeId);\n // Return null to indicate \"no match\"\n return null;\n }\n }\n};\n"],"names":["getFreeShippingDaysPerStore","storeId","StoreId","Ca","Za","Sg","Tw","Jp","Ph","Me","Us","Mx","Eu","Uk","In","Cn","Br","checkUnreachable"],"mappings":";;;;AAOa,MAAAA,2BAAA,GAGXC,OACoB,IAAA;EACpB,IAAI,CAACA,OAAS,EAAA;IAEL,OAAA,KAAA,CAAA;EACT;EAQA,QAAQA,OAAS;IACf,KAAKC,OAAQ,CAAAC,EAAA;IACb,KAAKD,OAAQ,CAAAE,EAAA;IACb,KAAKF,OAAQ,CAAAG,EAAA;IACb,KAAKH,OAAQ,CAAAI,EAAA;IACb,KAAKJ,OAAQ,CAAAK,EAAA;IACb,KAAKL,QAAQM,EAAI;MAAA;QACR,OAAA,CAAA;MACT;IACA,KAAKN,QAAQO,EAAI;MAAA;QACR,OAAA,CAAA;MACT;IACA,KAAKP,OAAQ,CAAAQ,EAAA;IACb,KAAKR,OAAQ,CAAAS,EAAA;IACb,KAAKT,OAAQ,CAAAU,EAAA;IACb,KAAKV,OAAQ,CAAAW,EAAA;IACb,KAAKX,OAAQ,CAAAY,EAAA;IACb,KAAKZ,OAAQ,CAAAa,EAAA;IACb,KAAKb,QAAQc,EAAI;MAAA;QAER,OAAA,IAAA;MACT;IAEA;MAAS;QACPC,gBAAA,CAAiBhB,OAAO,CAAA;QAEjB,OAAA,IAAA;MACT;EACF;AACF,CAAA;"}
@@ -63,6 +63,7 @@ const getTaxLabelType = storeId => {
63
63
  case generated.StoreId.Br:
64
64
  case generated.StoreId.Tw:
65
65
  case generated.StoreId.Jp:
66
+ case generated.StoreId.Cn:
66
67
  case generated.StoreId.Ph:
67
68
  {
68
69
  return types.TaxLabelType.Vat;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/utils/tax/index.ts"],"sourcesContent":["import isRegExp from \"lodash/isRegExp\";\n\nimport {\n BUSINESS_COUNTRY_CODE_MAPPING,\n RESIDENTIAL_COUNTRY_CODE_MAPPING,\n USER_ASSIGNED_COUNTRY_MAPPING_RULES,\n} from \"../../constants/address\";\nimport type { Nullish, UserAssignedCountryCode } from \"../../types\";\nimport { AddressType, CountryCode, StoreId } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport { formatCnpj, formatCpf } from \"./brazil\";\nimport type { TaxCountryCode } from \"./types\";\nimport { TaxLabelType } from \"./types\";\n\n/**\n * Util to get the country code mapping based on address type in a type-safe way\n */\nexport const getValidationMappingByType = (type: AddressType) => {\n switch (type) {\n case AddressType.Business: {\n return BUSINESS_COUNTRY_CODE_MAPPING;\n }\n case AddressType.Residential: {\n return RESIDENTIAL_COUNTRY_CODE_MAPPING;\n }\n default: {\n assertUnreachable(type);\n }\n }\n};\n\n/**\n * Checks if given tax country has regex pattern for tax id's\n */\nexport const hasTaxNumberPatternValidation = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n): taxCountryCode is keyof ReturnType<typeof getValidationMappingByType> =>\n taxCountryCode in getValidationMappingByType(type);\n\n/**\n * Checks if given tax id meets static pattern validation\n */\nexport const isValidTaxNumberPattern = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n taxId: Nullish<string>,\n): boolean => {\n // If country doesn't have a tax number pattern then mark input as valid\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return true;\n }\n\n const mapping = getValidationMappingByType(type);\n const { validation, isOptional } = mapping[taxCountryCode];\n\n // Mark input as valid if the tax ID is missing but it's optional\n if (!taxId && isOptional) {\n return true;\n }\n\n // Check for empty tax id's in cases when they are required\n if (!taxId) {\n return false;\n }\n\n // Technically, this should already be covered by the \"hasTaxNumberPatternValidation\"\n // check above but just in case something goes really wrong, we are adding this\n // to avoid unexpected type errors during runtime\n if (!validation) {\n return true;\n }\n\n // Validate pattern\n return isRegExp(validation)\n ? validation.test(taxId)\n : validation({ taxId, taxCountryCode });\n};\n\n/**\n * Depending on store Tax is called different names, so this mapping determines which one to use\n * @see https://ui.slack.com/archives/D0191CBEB27/p1678723218358039?thread_ts=1678722532.763459&cid=D0191CBEB27\n */\nexport const getTaxLabelType = (storeId: StoreId) => {\n switch (storeId) {\n case StoreId.Me:\n case StoreId.Za:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.Br:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Ph: {\n return TaxLabelType.Vat;\n }\n case StoreId.Ca:\n case StoreId.Us: {\n return TaxLabelType.Tax;\n }\n case StoreId.In:\n case StoreId.Sg: {\n return TaxLabelType.Gst;\n }\n case StoreId.Mx: {\n return TaxLabelType.Rfc;\n }\n default: {\n checkUnreachable(storeId);\n return TaxLabelType.Tax;\n }\n }\n};\n\nexport const getTaxLabelTypeByCountry = (\n country: CountryCode,\n options:\n | {\n type: \"general\";\n }\n | {\n type: \"specific\";\n addressType: AddressType;\n },\n) => {\n switch (country) {\n case CountryCode.Ca:\n case CountryCode.Us:\n case CountryCode.Pr:\n case CountryCode.Pw:\n case CountryCode.Gu:\n case CountryCode.As:\n case CountryCode.Vi:\n case CountryCode.Mp:\n case CountryCode.Mh:\n case CountryCode.Fm: {\n return TaxLabelType.Tax;\n }\n case CountryCode.In:\n case CountryCode.Sg: {\n return TaxLabelType.Gst;\n }\n case CountryCode.Mx: {\n return TaxLabelType.Rfc;\n }\n case CountryCode.Br: {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (options.type) {\n case \"general\":\n return TaxLabelType.Vat;\n case \"specific\": {\n const taxLabelTypesByAddressType = {\n [AddressType.Residential]: TaxLabelType.Cpf,\n [AddressType.Business]: TaxLabelType.Cnpj,\n } satisfies Record<AddressType, TaxLabelType>;\n\n return taxLabelTypesByAddressType[options.addressType];\n }\n default:\n checkUnreachable(options);\n return TaxLabelType.Vat;\n }\n }\n default: {\n return TaxLabelType.Vat;\n }\n }\n};\n\n// #############################################################################\n// Assigned country code\n// #############################################################################\n/**\n * We can't 100% trust the order of countries as compiles can possible rearrange the values, so we have to sort the\n * values with country+province first when looking for the match we can stop at first occurrence\n * @see https://stackoverflow.com/a/5525820\n */\nconst userAssignedCountryRulesSorted = Object.entries(\n USER_ASSIGNED_COUNTRY_MAPPING_RULES,\n)\n .flatMap(([userAssignedCountry, rules]) =>\n rules.map((rule) => {\n return [userAssignedCountry as UserAssignedCountryCode, rule] as const;\n }),\n )\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n .sort(([_, a], [__, b]) => {\n return b.length - a.length;\n });\n\n/**\n * Util to get TAX country code for a given country + province combination\n */\nexport const getTaxCountry = ({\n country,\n province,\n}: {\n country: CountryCode;\n province: Nullish<string>;\n}): TaxCountryCode => {\n const match = userAssignedCountryRulesSorted.find(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n ([_, [refCountry, refProvince]]) => {\n // Don't match - if countries don't match\n if (refCountry !== country) {\n return false;\n }\n\n // Match - if pattern doesn't include a province\n // TODO: this is debatable whether it should match as input province can be non-nullish\n if (refProvince == null) {\n return true;\n }\n\n return refProvince === province;\n },\n );\n\n const userAssignedCountry = match?.[0];\n\n // If there isn't a user assigned country that matches the result (most likely indicating that it doesnt require\n // unique lookup) then fallback to input country\n return userAssignedCountry ?? country;\n};\n\nexport const isTaxNumberOptional = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n) => {\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return true;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n return isOptional;\n};\n\nexport const formatTaxNumber = (\n taxNumber: string,\n { country, addressType }: { country: CountryCode; addressType: AddressType },\n) => {\n // Tax number formatting only needed for Brazil in the foreseeable future.\n if (country !== CountryCode.Br) {\n return taxNumber;\n }\n\n switch (addressType) {\n case AddressType.Residential:\n return formatCpf(taxNumber);\n\n case AddressType.Business:\n return formatCnpj(taxNumber);\n\n default:\n checkUnreachable(addressType);\n return taxNumber;\n }\n};\n"],"names":["getValidationMappingByType","type","AddressType","Business","BUSINESS_COUNTRY_CODE_MAPPING","Residential","RESIDENTIAL_COUNTRY_CODE_MAPPING","assertUnreachable","hasTaxNumberPatternValidation","taxCountryCode","isValidTaxNumberPattern","taxId","mapping","validation","isOptional","isRegExp","test","getTaxLabelType","storeId","StoreId","Me","Za","Eu","Uk","Br","Tw","Jp","Ph","TaxLabelType","Vat","Ca","Us","Tax","In","Sg","Gst","Mx","Rfc","checkUnreachable","getTaxLabelTypeByCountry","country","options","CountryCode","Pr","Pw","Gu","As","Vi","Mp","Mh","Fm","taxLabelTypesByAddressType","Cpf","Cnpj","addressType","userAssignedCountryRulesSorted","Object","entries","USER_ASSIGNED_COUNTRY_MAPPING_RULES","flatMap","userAssignedCountry","rules","map","rule","sort","_","a","__","b","length","getTaxCountry","province","match","find","refCountry","refProvince","isTaxNumberOptional","formatTaxNumber","taxNumber","formatCpf","formatCnpj"],"mapp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A,WAAA,CAAAC,QAAA;MACf,OAAO6E,MAAAA,CAAAA,WAAWF,SAAS,CAAA;IAE7B;MACExC,MAAA,CAAAA,gBAAA,CAAiBgB,WAAW,CAAA;MACrB,OAAAwB,SAAA;EACX;AACF,CAAA;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/utils/tax/index.ts"],"sourcesContent":["import isRegExp from \"lodash/isRegExp\";\n\nimport {\n BUSINESS_COUNTRY_CODE_MAPPING,\n RESIDENTIAL_COUNTRY_CODE_MAPPING,\n USER_ASSIGNED_COUNTRY_MAPPING_RULES,\n} from \"../../constants/address\";\nimport type { Nullish, UserAssignedCountryCode } from \"../../types\";\nimport { AddressType, CountryCode, StoreId } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport { formatCnpj, formatCpf } from \"./brazil\";\nimport type { TaxCountryCode } from \"./types\";\nimport { TaxLabelType } from \"./types\";\n\n/**\n * Util to get the country code mapping based on address type in a type-safe way\n */\nexport const getValidationMappingByType = (type: AddressType) => {\n switch (type) {\n case AddressType.Business: {\n return BUSINESS_COUNTRY_CODE_MAPPING;\n }\n case AddressType.Residential: {\n return RESIDENTIAL_COUNTRY_CODE_MAPPING;\n }\n default: {\n assertUnreachable(type);\n }\n }\n};\n\n/**\n * Checks if given tax country has regex pattern for tax id's\n */\nexport const hasTaxNumberPatternValidation = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n): taxCountryCode is keyof ReturnType<typeof getValidationMappingByType> =>\n taxCountryCode in getValidationMappingByType(type);\n\n/**\n * Checks if given tax id meets static pattern validation\n */\nexport const isValidTaxNumberPattern = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n taxId: Nullish<string>,\n): boolean => {\n // If country doesn't have a tax number pattern then mark input as valid\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return true;\n }\n\n const mapping = getValidationMappingByType(type);\n const { validation, isOptional } = mapping[taxCountryCode];\n\n // Mark input as valid if the tax ID is missing but it's optional\n if (!taxId && isOptional) {\n return true;\n }\n\n // Check for empty tax id's in cases when they are required\n if (!taxId) {\n return false;\n }\n\n // Technically, this should already be covered by the \"hasTaxNumberPatternValidation\"\n // check above but just in case something goes really wrong, we are adding this\n // to avoid unexpected type errors during runtime\n if (!validation) {\n return true;\n }\n\n // Validate pattern\n return isRegExp(validation)\n ? validation.test(taxId)\n : validation({ taxId, taxCountryCode });\n};\n\n/**\n * Depending on store Tax is called different names, so this mapping determines which one to use\n * @see https://ui.slack.com/archives/D0191CBEB27/p1678723218358039?thread_ts=1678722532.763459&cid=D0191CBEB27\n */\nexport const getTaxLabelType = (storeId: StoreId) => {\n switch (storeId) {\n case StoreId.Me:\n case StoreId.Za:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.Br:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Cn:\n case StoreId.Ph: {\n return TaxLabelType.Vat;\n }\n case StoreId.Ca:\n case StoreId.Us: {\n return TaxLabelType.Tax;\n }\n case StoreId.In:\n case StoreId.Sg: {\n return TaxLabelType.Gst;\n }\n case StoreId.Mx: {\n return TaxLabelType.Rfc;\n }\n default: {\n checkUnreachable(storeId);\n return TaxLabelType.Tax;\n }\n }\n};\n\nexport const getTaxLabelTypeByCountry = (\n country: CountryCode,\n options:\n | {\n type: \"general\";\n }\n | {\n type: \"specific\";\n addressType: AddressType;\n },\n) => {\n switch (country) {\n case CountryCode.Ca:\n case CountryCode.Us:\n case CountryCode.Pr:\n case CountryCode.Pw:\n case CountryCode.Gu:\n case CountryCode.As:\n case CountryCode.Vi:\n case CountryCode.Mp:\n case CountryCode.Mh:\n case CountryCode.Fm: {\n return TaxLabelType.Tax;\n }\n case CountryCode.In:\n case CountryCode.Sg: {\n return TaxLabelType.Gst;\n }\n case CountryCode.Mx: {\n return TaxLabelType.Rfc;\n }\n case CountryCode.Br: {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (options.type) {\n case \"general\":\n return TaxLabelType.Vat;\n case \"specific\": {\n const taxLabelTypesByAddressType = {\n [AddressType.Residential]: TaxLabelType.Cpf,\n [AddressType.Business]: TaxLabelType.Cnpj,\n } satisfies Record<AddressType, TaxLabelType>;\n\n return taxLabelTypesByAddressType[options.addressType];\n }\n default:\n checkUnreachable(options);\n return TaxLabelType.Vat;\n }\n }\n default: {\n return TaxLabelType.Vat;\n }\n }\n};\n\n// #############################################################################\n// Assigned country code\n// #############################################################################\n/**\n * We can't 100% trust the order of countries as compiles can possible rearrange the values, so we have to sort the\n * values with country+province first when looking for the match we can stop at first occurrence\n * @see https://stackoverflow.com/a/5525820\n */\nconst userAssignedCountryRulesSorted = Object.entries(\n USER_ASSIGNED_COUNTRY_MAPPING_RULES,\n)\n .flatMap(([userAssignedCountry, rules]) =>\n rules.map((rule) => {\n return [userAssignedCountry as UserAssignedCountryCode, rule] as const;\n }),\n )\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n .sort(([_, a], [__, b]) => {\n return b.length - a.length;\n });\n\n/**\n * Util to get TAX country code for a given country + province combination\n */\nexport const getTaxCountry = ({\n country,\n province,\n}: {\n country: CountryCode;\n province: Nullish<string>;\n}): TaxCountryCode => {\n const match = userAssignedCountryRulesSorted.find(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n ([_, [refCountry, refProvince]]) => {\n // Don't match - if countries don't match\n if (refCountry !== country) {\n return false;\n }\n\n // Match - if pattern doesn't include a province\n // TODO: this is debatable whether it should match as input province can be non-nullish\n if (refProvince == null) {\n return true;\n }\n\n return refProvince === province;\n },\n );\n\n const userAssignedCountry = match?.[0];\n\n // If there isn't a user assigned country that matches the result (most likely indicating that it doesnt require\n // unique lookup) then fallback to input country\n return userAssignedCountry ?? country;\n};\n\nexport const isTaxNumberOptional = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n) => {\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return true;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n return isOptional;\n};\n\nexport const formatTaxNumber = (\n taxNumber: string,\n { country, addressType }: { country: CountryCode; addressType: AddressType },\n) => {\n // Tax number formatting only needed for Brazil in the foreseeable future.\n if (country !== CountryCode.Br) {\n return taxNumber;\n }\n\n switch (addressType) {\n case AddressType.Residential:\n return formatCpf(taxNumber);\n\n case AddressType.Business:\n return formatCnpj(taxNumber);\n\n default:\n checkUnreachable(addressType);\n return taxNumber;\n }\n};\n"],"names":["getValidationMappingByType","type","AddressType","Business","BUSINESS_COUNTRY_CODE_MAPPING","Residential","RESIDENTIAL_COUNTRY_CODE_MAPPING","assertUnreachable","hasTaxNumberPatternValidation","taxCountryCode","isValidTaxNumberPattern","taxId","mapping","validation","isOptional","isRegExp","test","getTaxLabelType","storeId","StoreId","Me","Za","Eu","Uk","Br","Tw","Jp","Cn","Ph","TaxLabelType","Vat","Ca","Us","Tax","In","Sg","Gst","Mx","Rfc","checkUnreachable","getTaxLabelTypeByCountry","country","options","CountryCode","Pr","Pw","Gu","As","Vi","Mp","Mh","Fm","taxLabelTypesByAddressType","Cpf","Cnpj","addressType","userAssignedCountryRulesSorted","Object","entries","USER_ASSIGNED_COUNTRY_MAPPING_RULES","flatMap","userAssignedCountry","rules","map","rule","sort","_","a","__","b","length","getTaxCountry","province","match","find","refCountry","refProvince","isTaxNumberOptional","formatTaxNumber","taxNumber","formatCpf","formatCnpj"],"mappings":";;;;;;;;;;;;;;;;AAiBa,MAAAA,0BAAA,GAA8BC,IAAsB,IAAA;EAC/D,QAAQA,IAAM;IACZ,KAAKC,SAAAA,CAAAA,YAAYC,QAAU;MAAA;QAClB,OAAAC,qCAAA;MACT;IACA,KAAKF,SAAAA,CAAAA,YAAYG,WAAa;MAAA;QACrB,OAAAC,wCAAA;MACT;IACA;MAAS;QACPC,MAAA,CAAAA,iBAAA,CAAkBN,IAAI,CAAA;MACxB;EACF;AACF,CAAA;AAKO,MAAMO,gCAAgCA,CAC3CP,IAAA,EACAQ,cAEA,KAAAA,cAAA,IAAkBT,2B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,CAAA,EAAG,CAACS,UAAY,EAAAC,WAAW,CAAC,CAAM,KAAA;IAElC,IAAID,eAAelC,OAAS,EAAA;MACnB,OAAA,KAAA;IACT;IAIA,IAAImC,eAAe,IAAM,EAAA;MAChB,OAAA,IAAA;IACT;IAEA,OAAOA,WAAgB,KAAAJ,QAAA;EACzB,CAAA,CACF;EAEM,MAAAX,mBAAA,GAAsBY,QAAQ,CAAC,CAAA;EAIrC,OAAOZ,mBAAuB,IAAApB,OAAA;AAChC,CAAA;AAEa,MAAAoC,mBAAA,GAAsBA,CACjC5E,IAAA,EACAQ,cACG,KAAA;EACH,IAAI,CAACD,6BAAA,CAA8BP,IAAM,EAAAQ,cAAc,CAAG,EAAA;IACjD,OAAA,IAAA;EACT;EAEM,MAAAG,OAAA,GAAUZ,2BAA2BC,IAAI,CAAA;EAC/C,MAAM;IAAEa;EAAA,CAAe,GAAAF,OAAA,CAAQH,cAAc,CAAA;EAEtC,OAAAK,UAAA;AACT,CAAA;AAEO,MAAMgE,kBAAkBA,CAC7BC,SAAA,EACA;EAAEtC,OAAA;EAASc;CACR,KAAA;EAEC,IAAAd,OAAA,KAAYE,sBAAYnB,EAAI,EAAA;IACvB,OAAAuD,SAAA;EACT;EAEA,QAAQxB,WAAa;IACnB,KAAKrD,SAAY,CAAAA,WAAA,CAAAG,WAAA;MACf,OAAO2E,MAAAA,CAAAA,UAAUD,SAAS,CAAA;IAE5B,KAAK7E,SAAY,CAAAA,WAAA,CAAAC,QAAA;MACf,OAAO8E,MAAAA,CAAAA,WAAWF,SAAS,CAAA;IAE7B;MACExC,MAAA,CAAAA,gBAAA,CAAiBgB,WAAW,CAAA;MACrB,OAAAwB,SAAA;EACX;AACF,CAAA;;;;;;;;"}
@@ -55,6 +55,7 @@ const getTaxLabelType = storeId => {
55
55
  case StoreId.Br:
56
56
  case StoreId.Tw:
57
57
  case StoreId.Jp:
58
+ case StoreId.Cn:
58
59
  case StoreId.Ph:
59
60
  {
60
61
  return TaxLabelType.Vat;
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/utils/tax/index.ts"],"sourcesContent":["import isRegExp from \"lodash/isRegExp\";\n\nimport {\n BUSINESS_COUNTRY_CODE_MAPPING,\n RESIDENTIAL_COUNTRY_CODE_MAPPING,\n USER_ASSIGNED_COUNTRY_MAPPING_RULES,\n} from \"../../constants/address\";\nimport type { Nullish, UserAssignedCountryCode } from \"../../types\";\nimport { AddressType, CountryCode, StoreId } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport { formatCnpj, formatCpf } from \"./brazil\";\nimport type { TaxCountryCode } from \"./types\";\nimport { TaxLabelType } from \"./types\";\n\n/**\n * Util to get the country code mapping based on address type in a type-safe way\n */\nexport const getValidationMappingByType = (type: AddressType) => {\n switch (type) {\n case AddressType.Business: {\n return BUSINESS_COUNTRY_CODE_MAPPING;\n }\n case AddressType.Residential: {\n return RESIDENTIAL_COUNTRY_CODE_MAPPING;\n }\n default: {\n assertUnreachable(type);\n }\n }\n};\n\n/**\n * Checks if given tax country has regex pattern for tax id's\n */\nexport const hasTaxNumberPatternValidation = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n): taxCountryCode is keyof ReturnType<typeof getValidationMappingByType> =>\n taxCountryCode in getValidationMappingByType(type);\n\n/**\n * Checks if given tax id meets static pattern validation\n */\nexport const isValidTaxNumberPattern = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n taxId: Nullish<string>,\n): boolean => {\n // If country doesn't have a tax number pattern then mark input as valid\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return true;\n }\n\n const mapping = getValidationMappingByType(type);\n const { validation, isOptional } = mapping[taxCountryCode];\n\n // Mark input as valid if the tax ID is missing but it's optional\n if (!taxId && isOptional) {\n return true;\n }\n\n // Check for empty tax id's in cases when they are required\n if (!taxId) {\n return false;\n }\n\n // Technically, this should already be covered by the \"hasTaxNumberPatternValidation\"\n // check above but just in case something goes really wrong, we are adding this\n // to avoid unexpected type errors during runtime\n if (!validation) {\n return true;\n }\n\n // Validate pattern\n return isRegExp(validation)\n ? validation.test(taxId)\n : validation({ taxId, taxCountryCode });\n};\n\n/**\n * Depending on store Tax is called different names, so this mapping determines which one to use\n * @see https://ui.slack.com/archives/D0191CBEB27/p1678723218358039?thread_ts=1678722532.763459&cid=D0191CBEB27\n */\nexport const getTaxLabelType = (storeId: StoreId) => {\n switch (storeId) {\n case StoreId.Me:\n case StoreId.Za:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.Br:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Ph: {\n return TaxLabelType.Vat;\n }\n case StoreId.Ca:\n case StoreId.Us: {\n return TaxLabelType.Tax;\n }\n case StoreId.In:\n case StoreId.Sg: {\n return TaxLabelType.Gst;\n }\n case StoreId.Mx: {\n return TaxLabelType.Rfc;\n }\n default: {\n checkUnreachable(storeId);\n return TaxLabelType.Tax;\n }\n }\n};\n\nexport const getTaxLabelTypeByCountry = (\n country: CountryCode,\n options:\n | {\n type: \"general\";\n }\n | {\n type: \"specific\";\n addressType: AddressType;\n },\n) => {\n switch (country) {\n case CountryCode.Ca:\n case CountryCode.Us:\n case CountryCode.Pr:\n case CountryCode.Pw:\n case CountryCode.Gu:\n case CountryCode.As:\n case CountryCode.Vi:\n case CountryCode.Mp:\n case CountryCode.Mh:\n case CountryCode.Fm: {\n return TaxLabelType.Tax;\n }\n case CountryCode.In:\n case CountryCode.Sg: {\n return TaxLabelType.Gst;\n }\n case CountryCode.Mx: {\n return TaxLabelType.Rfc;\n }\n case CountryCode.Br: {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (options.type) {\n case \"general\":\n return TaxLabelType.Vat;\n case \"specific\": {\n const taxLabelTypesByAddressType = {\n [AddressType.Residential]: TaxLabelType.Cpf,\n [AddressType.Business]: TaxLabelType.Cnpj,\n } satisfies Record<AddressType, TaxLabelType>;\n\n return taxLabelTypesByAddressType[options.addressType];\n }\n default:\n checkUnreachable(options);\n return TaxLabelType.Vat;\n }\n }\n default: {\n return TaxLabelType.Vat;\n }\n }\n};\n\n// #############################################################################\n// Assigned country code\n// #############################################################################\n/**\n * We can't 100% trust the order of countries as compiles can possible rearrange the values, so we have to sort the\n * values with country+province first when looking for the match we can stop at first occurrence\n * @see https://stackoverflow.com/a/5525820\n */\nconst userAssignedCountryRulesSorted = Object.entries(\n USER_ASSIGNED_COUNTRY_MAPPING_RULES,\n)\n .flatMap(([userAssignedCountry, rules]) =>\n rules.map((rule) => {\n return [userAssignedCountry as UserAssignedCountryCode, rule] as const;\n }),\n )\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n .sort(([_, a], [__, b]) => {\n return b.length - a.length;\n });\n\n/**\n * Util to get TAX country code for a given country + province combination\n */\nexport const getTaxCountry = ({\n country,\n province,\n}: {\n country: CountryCode;\n province: Nullish<string>;\n}): TaxCountryCode => {\n const match = userAssignedCountryRulesSorted.find(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n ([_, [refCountry, refProvince]]) => {\n // Don't match - if countries don't match\n if (refCountry !== country) {\n return false;\n }\n\n // Match - if pattern doesn't include a province\n // TODO: this is debatable whether it should match as input province can be non-nullish\n if (refProvince == null) {\n return true;\n }\n\n return refProvince === province;\n },\n );\n\n const userAssignedCountry = match?.[0];\n\n // If there isn't a user assigned country that matches the result (most likely indicating that it doesnt require\n // unique lookup) then fallback to input country\n return userAssignedCountry ?? country;\n};\n\nexport const isTaxNumberOptional = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n) => {\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return true;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n return isOptional;\n};\n\nexport const formatTaxNumber = (\n taxNumber: string,\n { country, addressType }: { country: CountryCode; addressType: AddressType },\n) => {\n // Tax number formatting only needed for Brazil in the foreseeable future.\n if (country !== CountryCode.Br) {\n return taxNumber;\n }\n\n switch (addressType) {\n case AddressType.Residential:\n return formatCpf(taxNumber);\n\n case AddressType.Business:\n return formatCnpj(taxNumber);\n\n default:\n checkUnreachable(addressType);\n return taxNumber;\n }\n};\n"],"names":["getValidationMappingByType","type","AddressType","Business","BUSINESS_COUNTRY_CODE_MAPPING","Residential","RESIDENTIAL_COUNTRY_CODE_MAPPING","assertUnreachable","hasTaxNumberPatternValidation","taxCountryCode","isValidTaxNumberPattern","taxId","mapping","validation","isOptional","isRegExp","test","getTaxLabelType","storeId","StoreId","Me","Za","Eu","Uk","Br","Tw","Jp","Ph","TaxLabelType","Vat","Ca","Us","Tax","In","Sg","Gst","Mx","Rfc","checkUnreachable","getTaxLabelTypeByCountry","country","options","CountryCode","Pr","Pw","Gu","As","Vi","Mp","Mh","Fm","taxLabelTypesByAddressType","Cpf","Cnpj","addressType","userAssignedCountryRulesSorted","Object","entries","USER_ASSIGNED_COUNTRY_MAPPING_RULES","flatMap","userAssignedCountry","rules","map","rule","sort","_","a","__","b","length","getTaxCountry","province","match","find","refCountry","refProvince","isTaxNumberOptional","formatTaxNumber","taxNumber","formatCpf","formatCnpj"],"mappings":";;;;;;;;AAiBa,MAAAA,0BAAA,GAA8BC,IAAsB,IAAA;EAC/D,QAAQA,IAAM;IACZ,KAAKC,YAAYC,QAAU;MAAA;QAClB,OAAAC,6BAAA;MACT;IACA,KAAKF,YAAYG,WAAa;MAAA;QACrB,OAAAC,gCAAA;MACT;IACA;MAAS;QACPC,iBAAA,CAAkBN,IAAI,CAAA;MACxB;EACF;AACF,CAAA;AAKO,MAAMO,gCAAgCA,CAC3CP,IAAA,EACAQ,cAEA,KAAAA,cAAA,IAAkBT,2BAA2BC,IAAI,CAAA;AAK5C,MAAMS,uBAA0B,GAAAA,CACrCT,IACA,EAAAQ,cAAA,EACAE,KACY,KAAA;EAEZ,IAAI,CAACH,6BAAA,CAA8BP,IAAM,EAAAQ,cAAc,CAAG,EAAA;IACjD,OAAA,IAAA;EACT;EAEM,MAAAG,OAAA,GAAUZ,2BAA2BC,IAAI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ACExC,gBAAA,CAAiBgB,WAAW,CAAA;MACrB,OAAAwB,SAAA;EACX;AACF,CAAA;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/utils/tax/index.ts"],"sourcesContent":["import isRegExp from \"lodash/isRegExp\";\n\nimport {\n BUSINESS_COUNTRY_CODE_MAPPING,\n RESIDENTIAL_COUNTRY_CODE_MAPPING,\n USER_ASSIGNED_COUNTRY_MAPPING_RULES,\n} from \"../../constants/address\";\nimport type { Nullish, UserAssignedCountryCode } from \"../../types\";\nimport { AddressType, CountryCode, StoreId } from \"../../types\";\nimport { assertUnreachable, checkUnreachable } from \"../errors\";\nimport { formatCnpj, formatCpf } from \"./brazil\";\nimport type { TaxCountryCode } from \"./types\";\nimport { TaxLabelType } from \"./types\";\n\n/**\n * Util to get the country code mapping based on address type in a type-safe way\n */\nexport const getValidationMappingByType = (type: AddressType) => {\n switch (type) {\n case AddressType.Business: {\n return BUSINESS_COUNTRY_CODE_MAPPING;\n }\n case AddressType.Residential: {\n return RESIDENTIAL_COUNTRY_CODE_MAPPING;\n }\n default: {\n assertUnreachable(type);\n }\n }\n};\n\n/**\n * Checks if given tax country has regex pattern for tax id's\n */\nexport const hasTaxNumberPatternValidation = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n): taxCountryCode is keyof ReturnType<typeof getValidationMappingByType> =>\n taxCountryCode in getValidationMappingByType(type);\n\n/**\n * Checks if given tax id meets static pattern validation\n */\nexport const isValidTaxNumberPattern = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n taxId: Nullish<string>,\n): boolean => {\n // If country doesn't have a tax number pattern then mark input as valid\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return true;\n }\n\n const mapping = getValidationMappingByType(type);\n const { validation, isOptional } = mapping[taxCountryCode];\n\n // Mark input as valid if the tax ID is missing but it's optional\n if (!taxId && isOptional) {\n return true;\n }\n\n // Check for empty tax id's in cases when they are required\n if (!taxId) {\n return false;\n }\n\n // Technically, this should already be covered by the \"hasTaxNumberPatternValidation\"\n // check above but just in case something goes really wrong, we are adding this\n // to avoid unexpected type errors during runtime\n if (!validation) {\n return true;\n }\n\n // Validate pattern\n return isRegExp(validation)\n ? validation.test(taxId)\n : validation({ taxId, taxCountryCode });\n};\n\n/**\n * Depending on store Tax is called different names, so this mapping determines which one to use\n * @see https://ui.slack.com/archives/D0191CBEB27/p1678723218358039?thread_ts=1678722532.763459&cid=D0191CBEB27\n */\nexport const getTaxLabelType = (storeId: StoreId) => {\n switch (storeId) {\n case StoreId.Me:\n case StoreId.Za:\n case StoreId.Eu:\n case StoreId.Uk:\n case StoreId.Br:\n case StoreId.Tw:\n case StoreId.Jp:\n case StoreId.Cn:\n case StoreId.Ph: {\n return TaxLabelType.Vat;\n }\n case StoreId.Ca:\n case StoreId.Us: {\n return TaxLabelType.Tax;\n }\n case StoreId.In:\n case StoreId.Sg: {\n return TaxLabelType.Gst;\n }\n case StoreId.Mx: {\n return TaxLabelType.Rfc;\n }\n default: {\n checkUnreachable(storeId);\n return TaxLabelType.Tax;\n }\n }\n};\n\nexport const getTaxLabelTypeByCountry = (\n country: CountryCode,\n options:\n | {\n type: \"general\";\n }\n | {\n type: \"specific\";\n addressType: AddressType;\n },\n) => {\n switch (country) {\n case CountryCode.Ca:\n case CountryCode.Us:\n case CountryCode.Pr:\n case CountryCode.Pw:\n case CountryCode.Gu:\n case CountryCode.As:\n case CountryCode.Vi:\n case CountryCode.Mp:\n case CountryCode.Mh:\n case CountryCode.Fm: {\n return TaxLabelType.Tax;\n }\n case CountryCode.In:\n case CountryCode.Sg: {\n return TaxLabelType.Gst;\n }\n case CountryCode.Mx: {\n return TaxLabelType.Rfc;\n }\n case CountryCode.Br: {\n // eslint-disable-next-line sonarjs/no-nested-switch\n switch (options.type) {\n case \"general\":\n return TaxLabelType.Vat;\n case \"specific\": {\n const taxLabelTypesByAddressType = {\n [AddressType.Residential]: TaxLabelType.Cpf,\n [AddressType.Business]: TaxLabelType.Cnpj,\n } satisfies Record<AddressType, TaxLabelType>;\n\n return taxLabelTypesByAddressType[options.addressType];\n }\n default:\n checkUnreachable(options);\n return TaxLabelType.Vat;\n }\n }\n default: {\n return TaxLabelType.Vat;\n }\n }\n};\n\n// #############################################################################\n// Assigned country code\n// #############################################################################\n/**\n * We can't 100% trust the order of countries as compiles can possible rearrange the values, so we have to sort the\n * values with country+province first when looking for the match we can stop at first occurrence\n * @see https://stackoverflow.com/a/5525820\n */\nconst userAssignedCountryRulesSorted = Object.entries(\n USER_ASSIGNED_COUNTRY_MAPPING_RULES,\n)\n .flatMap(([userAssignedCountry, rules]) =>\n rules.map((rule) => {\n return [userAssignedCountry as UserAssignedCountryCode, rule] as const;\n }),\n )\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n .sort(([_, a], [__, b]) => {\n return b.length - a.length;\n });\n\n/**\n * Util to get TAX country code for a given country + province combination\n */\nexport const getTaxCountry = ({\n country,\n province,\n}: {\n country: CountryCode;\n province: Nullish<string>;\n}): TaxCountryCode => {\n const match = userAssignedCountryRulesSorted.find(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n ([_, [refCountry, refProvince]]) => {\n // Don't match - if countries don't match\n if (refCountry !== country) {\n return false;\n }\n\n // Match - if pattern doesn't include a province\n // TODO: this is debatable whether it should match as input province can be non-nullish\n if (refProvince == null) {\n return true;\n }\n\n return refProvince === province;\n },\n );\n\n const userAssignedCountry = match?.[0];\n\n // If there isn't a user assigned country that matches the result (most likely indicating that it doesnt require\n // unique lookup) then fallback to input country\n return userAssignedCountry ?? country;\n};\n\nexport const isTaxNumberOptional = (\n type: AddressType,\n taxCountryCode: TaxCountryCode,\n) => {\n if (!hasTaxNumberPatternValidation(type, taxCountryCode)) {\n return true;\n }\n\n const mapping = getValidationMappingByType(type);\n const { isOptional } = mapping[taxCountryCode];\n\n return isOptional;\n};\n\nexport const formatTaxNumber = (\n taxNumber: string,\n { country, addressType }: { country: CountryCode; addressType: AddressType },\n) => {\n // Tax number formatting only needed for Brazil in the foreseeable future.\n if (country !== CountryCode.Br) {\n return taxNumber;\n }\n\n switch (addressType) {\n case AddressType.Residential:\n return formatCpf(taxNumber);\n\n case AddressType.Business:\n return formatCnpj(taxNumber);\n\n default:\n checkUnreachable(addressType);\n return taxNumber;\n }\n};\n"],"names":["getValidationMappingByType","type","AddressType","Business","BUSINESS_COUNTRY_CODE_MAPPING","Residential","RESIDENTIAL_COUNTRY_CODE_MAPPING","assertUnreachable","hasTaxNumberPatternValidation","taxCountryCode","isValidTaxNumberPattern","taxId","mapping","validation","isOptional","isRegExp","test","getTaxLabelType","storeId","StoreId","Me","Za","Eu","Uk","Br","Tw","Jp","Cn","Ph","TaxLabelType","Vat","Ca","Us","Tax","In","Sg","Gst","Mx","Rfc","checkUnreachable","getTaxLabelTypeByCountry","country","options","CountryCode","Pr","Pw","Gu","As","Vi","Mp","Mh","Fm","taxLabelTypesByAddressType","Cpf","Cnpj","addressType","userAssignedCountryRulesSorted","Object","entries","USER_ASSIGNED_COUNTRY_MAPPING_RULES","flatMap","userAssignedCountry","rules","map","rule","sort","_","a","__","b","length","getTaxCountry","province","match","find","refCountry","refProvince","isTaxNumberOptional","formatTaxNumber","taxNumber","formatCpf","formatCnpj"],"mappings":";;;;;;;;AAiBa,MAAAA,0BAAA,GAA8BC,IAAsB,IAAA;EAC/D,QAAQA,IAAM;IACZ,KAAKC,YAAYC,QAAU;MAAA;QAClB,OAAAC,6BAAA;MACT;IACA,KAAKF,YAAYG,WAAa;MAAA;QACrB,OAAAC,gCAAA;MACT;IACA;MAAS;QACPC,iBAAA,CAAkBN,IAAI,CAAA;MACxB;EACF;AACF,CAAA;AAKO,MAAMO,gCAAgCA,CAC3CP,IAAA,EACAQ,cAEA,KAAAA,cAAA,IAAkBT,2BAA2BC,IAAI,CAAA;AAK5C,MAAMS,uBAA0B,GAAAA,CACrCT,IACA,EAAAQ,cAAA,EACAE,KACY,KAAA;EAEZ,IAAI,CAACH,6BAAA,CAA8BP,IAAM,EAAAQ,cAAc,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AA;MACf,OAAO2E,UAAUD,SAAS,CAAA;IAE5B,KAAK7E,WAAY,CAAAC,QAAA;MACf,OAAO8E,WAAWF,SAAS,CAAA;IAE7B;MACExC,gBAAA,CAAiBgB,WAAW,CAAA;MACrB,OAAAwB,SAAA;EACX;AACF,CAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubnt/store.core",
3
- "version": "9.45.0-beta.7",
3
+ "version": "9.45.0-beta.9",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "scripts": {