@ubnt/store.core 9.4.0 → 9.5.0-money.4

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 (121) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/assets/attention.svg +5 -5
  3. package/lib/assets/attention2.svg +5 -5
  4. package/lib/assets/icons/wizard/plus.svg.js +1 -1
  5. package/lib/assets/icons/wizard/plus.svg.mjs +2 -2
  6. package/lib/assets/minus4.svg +8 -8
  7. package/lib/assets/minus5.svg +8 -8
  8. package/lib/assets/plus.svg +22 -4
  9. package/lib/assets/plus2.svg +4 -22
  10. package/lib/assets/plus5.svg +9 -9
  11. package/lib/assets/plus6.svg +9 -9
  12. package/lib/components/FeaturesSection_deprecated/AllFeaturesButton/AllFeaturesButton.js +1 -1
  13. package/lib/components/FeaturesSection_deprecated/AllFeaturesButton/AllFeaturesButton.mjs +1 -1
  14. package/lib/components/FeaturesSection_deprecated/assets/plus.svg.js +1 -1
  15. package/lib/components/FeaturesSection_deprecated/assets/plus.svg.mjs +2 -2
  16. package/lib/components/LandingPagePro/LandingPagePro.d.ts +3 -0
  17. package/lib/components/LandingPagePro/LandingPagePro.js +3 -3
  18. package/lib/components/LandingPagePro/LandingPagePro.js.map +1 -1
  19. package/lib/components/LandingPagePro/LandingPagePro.mjs +2 -2
  20. package/lib/components/LandingPagePro/LandingPagePro.mjs.map +1 -1
  21. package/lib/components/ProductWizard/ProductWizard.js +1 -1
  22. package/lib/components/ProductWizard/ProductWizard.mjs +1 -1
  23. package/lib/components/QuantityInput/QuantityInput.js +1 -1
  24. package/lib/components/QuantityInput/QuantityInput.mjs +1 -1
  25. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  26. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  27. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  28. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  29. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  30. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  31. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  32. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  33. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  34. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  35. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  36. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  37. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  38. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  39. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  40. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  41. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  42. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  43. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  44. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  45. package/lib/utils/money/allocators/fixedAmount.d.ts +26 -0
  46. package/lib/utils/money/allocators/fixedAmount.js +55 -0
  47. package/lib/utils/money/allocators/fixedAmount.js.map +1 -0
  48. package/lib/utils/money/allocators/fixedAmount.mjs +53 -0
  49. package/lib/utils/money/allocators/fixedAmount.mjs.map +1 -0
  50. package/lib/utils/money/allocators/index.d.ts +1 -0
  51. package/lib/utils/money/allocators/index.js +6 -0
  52. package/lib/utils/money/allocators/index.js.map +1 -0
  53. package/lib/utils/money/allocators/index.mjs +3 -0
  54. package/lib/utils/money/allocators/index.mjs.map +1 -0
  55. package/lib/utils/money/constants.d.ts +56 -25
  56. package/lib/utils/money/constants.js +72 -7
  57. package/lib/utils/money/constants.js.map +1 -1
  58. package/lib/utils/money/constants.mjs +70 -7
  59. package/lib/utils/money/constants.mjs.map +1 -1
  60. package/lib/utils/money/exchangeRate.d.ts +31 -0
  61. package/lib/utils/money/exchangeRate.js +27 -0
  62. package/lib/utils/money/exchangeRate.js.map +1 -0
  63. package/lib/utils/money/exchangeRate.mjs +23 -0
  64. package/lib/utils/money/exchangeRate.mjs.map +1 -0
  65. package/lib/utils/money/format.d.ts +10 -5
  66. package/lib/utils/money/format.js +22 -14
  67. package/lib/utils/money/format.js.map +1 -1
  68. package/lib/utils/money/format.mjs +23 -16
  69. package/lib/utils/money/format.mjs.map +1 -1
  70. package/lib/utils/money/index.d.ts +4 -1
  71. package/lib/utils/money/index.js +26 -8
  72. package/lib/utils/money/index.js.map +1 -1
  73. package/lib/utils/money/index.mjs +8 -4
  74. package/lib/utils/money/index.mjs.map +1 -1
  75. package/lib/utils/money/misc.d.ts +68 -28
  76. package/lib/utils/money/misc.js +35 -64
  77. package/lib/utils/money/misc.js.map +1 -1
  78. package/lib/utils/money/misc.mjs +32 -43
  79. package/lib/utils/money/misc.mjs.map +1 -1
  80. package/lib/utils/money/misc.private.d.ts +23 -0
  81. package/lib/utils/money/misc.private.js +46 -0
  82. package/lib/utils/money/misc.private.js.map +1 -0
  83. package/lib/utils/money/misc.private.mjs +21 -0
  84. package/lib/utils/money/misc.private.mjs.map +1 -0
  85. package/lib/utils/money/shipping.d.ts +5 -0
  86. package/lib/utils/money/shipping.js +8 -0
  87. package/lib/utils/money/shipping.js.map +1 -0
  88. package/lib/utils/money/shipping.mjs +6 -0
  89. package/lib/utils/money/shipping.mjs.map +1 -0
  90. package/lib/utils/money/tax.d.ts +38 -2
  91. package/lib/utils/money/tax.js +46 -10
  92. package/lib/utils/money/tax.js.map +1 -1
  93. package/lib/utils/money/tax.mjs +42 -11
  94. package/lib/utils/money/tax.mjs.map +1 -1
  95. package/lib/utils/money/tax.private.d.ts +17 -0
  96. package/lib/utils/money/tax.private.js +65 -0
  97. package/lib/utils/money/tax.private.js.map +1 -0
  98. package/lib/utils/money/tax.private.mjs +60 -0
  99. package/lib/utils/money/tax.private.mjs.map +1 -0
  100. package/lib/utils/money/types.d.ts +64 -3
  101. package/lib/utils/number.d.ts +1 -1
  102. package/lib/utils/number.js +1 -1
  103. package/lib/utils/number.js.map +1 -1
  104. package/lib/utils/number.mjs +1 -1
  105. package/lib/utils/number.mjs.map +1 -1
  106. package/lib/utils/tax/index.d.ts +1 -1
  107. package/lib/utils/tax/index.js +8 -1
  108. package/lib/utils/tax/index.js.map +1 -1
  109. package/lib/utils/tax/index.mjs +8 -1
  110. package/lib/utils/tax/index.mjs.map +1 -1
  111. package/lib/utils/tax/types.d.ts +2 -1
  112. package/lib/utils/tax/types.js +1 -0
  113. package/lib/utils/tax/types.js.map +1 -1
  114. package/lib/utils/tax/types.mjs +1 -0
  115. package/lib/utils/tax/types.mjs.map +1 -1
  116. package/package.json +1 -1
  117. package/lib/utils/validations.d.ts +0 -15
  118. package/lib/utils/validations.js +0 -23
  119. package/lib/utils/validations.js.map +0 -1
  120. package/lib/utils/validations.mjs +0 -21
  121. package/lib/utils/validations.mjs.map +0 -1
@@ -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.Mx:\n case StoreId.Jp: {\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 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.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","Mx","Jp","TaxLabelType","Vat","Ca","Us","Tax","In","Sg","Gst","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,CAAA;EAC/C,MAAM;IAAEY,UAAA;IAAYC;EAAW,CAAA,GAAIF,QAAQH,cAAc,CAAA;EAGrD,IAAA,CAACE,SAASG,U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pB,MAAMC,QAAQjB,8BAA+B,CAAAkB,IAAA;EAAA;EAE3C,CAAC,CAACR,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,CACjCzE,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,MAAM6D,kBAAkBA,CAC7BC,SAAA,EACA;EAAEtC,OAAA;EAASc;CACR,KAAA;EAEC,IAAAd,OAAA,KAAYE,YAAYhB,EAAI,EAAA;IACvB,OAAAoD,SAAA;EACT;EAEA,QAAQxB,WAAa;IACnB,KAAKlD,WAAY,CAAAG,WAAA;MACf,OAAOwE,UAAUD,SAAS,CAAA;IAE5B,KAAK1E,WAAY,CAAAC,QAAA;MACf,OAAO2E,WAAWF,SAAS,CAAA;IAE7B;MACExC,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 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","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,CAAA;EAC/C,MAAM;IAAEY,UAAA;IAAYC;EAAW,CAAA,GAAIF,QAAQH,cAAc,CAAA;EAGrD,IAAA,CAACE,SAASG,UAAY,EAAA;IACjB,OAAA,IAAA;EACT;EAGA,IAAI,CAACH,KAAO,EAAA;IACH,OAAA,KAAA;EACT;EAKA,IAAI,CAACE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
  * Ability to create custom logic (not regex based for taxId) validation
@@ -7,6 +7,7 @@ var TaxLabelType = /* @__PURE__ */(TaxLabelType2 => {
7
7
  TaxLabelType2["Gst"] = "gst";
8
8
  TaxLabelType2["Cpf"] = "cpf";
9
9
  TaxLabelType2["Cnpj"] = "cnpj";
10
+ TaxLabelType2["Rfc"] = "rfc";
10
11
  return TaxLabelType2;
11
12
  })(TaxLabelType || {});
12
13
  exports.TaxLabelType = TaxLabelType;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../src/utils/tax/types.ts"],"sourcesContent":["import type { CountryCode, UserAssignedCountryCode } from \"../../types\";\n\nexport type TaxCountryCode = CountryCode | UserAssignedCountryCode;\n\nexport enum TaxLabelType {\n Tax = \"tax\",\n Vat = \"vat\",\n Gst = \"gst\",\n Cpf = \"cpf\",\n Cnpj = \"cnpj\",\n}\n\n/**\n * Ability to create custom logic (not regex based for taxId) validation\n */\nexport type CountryTaxIdValidationFn = (options: {\n taxCountryCode: TaxCountryCode;\n taxId: string;\n}) => boolean;\n\nexport type CountryTaxValidationMapping = Partial<\n Record<\n TaxCountryCode,\n { validation: CountryTaxIdValidationFn | RegExp; isOptional?: boolean }\n >\n>;\n"],"names":["TaxLabelType"],"mappings":";;;AAIY,IAAAA,YAAA,GAAA,gBAAAA,aAAL,IAAA;EACLA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,MAAO,CAAA,GAAA,MAAA;EALGA,OAAAA,aAAAA;AAAA,CAAA,EAAAA,YAAA,IAAA,CAAA,CAAA,CAAA;"}
1
+ {"version":3,"file":"types.js","sources":["../../../src/utils/tax/types.ts"],"sourcesContent":["import type { CountryCode, UserAssignedCountryCode } from \"../../types\";\n\nexport type TaxCountryCode = CountryCode | UserAssignedCountryCode;\n\nexport enum TaxLabelType {\n Tax = \"tax\",\n Vat = \"vat\",\n Gst = \"gst\",\n Cpf = \"cpf\",\n Cnpj = \"cnpj\",\n Rfc = \"rfc\",\n}\n\n/**\n * Ability to create custom logic (not regex based for taxId) validation\n */\nexport type CountryTaxIdValidationFn = (options: {\n taxCountryCode: TaxCountryCode;\n taxId: string;\n}) => boolean;\n\nexport type CountryTaxValidationMapping = Partial<\n Record<\n TaxCountryCode,\n { validation: CountryTaxIdValidationFn | RegExp; isOptional?: boolean }\n >\n>;\n"],"names":["TaxLabelType"],"mappings":";;;AAIY,IAAAA,YAAA,GAAA,gBAAAA,aAAL,IAAA;EACLA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,MAAO,CAAA,GAAA,MAAA;EACPA,cAAA,KAAM,CAAA,GAAA,KAAA;EANIA,OAAAA,aAAAA;AAAA,CAAA,EAAAA,YAAA,IAAA,CAAA,CAAA,CAAA;"}
@@ -6,6 +6,7 @@ var TaxLabelType = /* @__PURE__ */(TaxLabelType2 => {
6
6
  TaxLabelType2["Gst"] = "gst";
7
7
  TaxLabelType2["Cpf"] = "cpf";
8
8
  TaxLabelType2["Cnpj"] = "cnpj";
9
+ TaxLabelType2["Rfc"] = "rfc";
9
10
  return TaxLabelType2;
10
11
  })(TaxLabelType || {});
11
12
  export { TaxLabelType };
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sources":["../../../src/utils/tax/types.ts"],"sourcesContent":["import type { CountryCode, UserAssignedCountryCode } from \"../../types\";\n\nexport type TaxCountryCode = CountryCode | UserAssignedCountryCode;\n\nexport enum TaxLabelType {\n Tax = \"tax\",\n Vat = \"vat\",\n Gst = \"gst\",\n Cpf = \"cpf\",\n Cnpj = \"cnpj\",\n}\n\n/**\n * Ability to create custom logic (not regex based for taxId) validation\n */\nexport type CountryTaxIdValidationFn = (options: {\n taxCountryCode: TaxCountryCode;\n taxId: string;\n}) => boolean;\n\nexport type CountryTaxValidationMapping = Partial<\n Record<\n TaxCountryCode,\n { validation: CountryTaxIdValidationFn | RegExp; isOptional?: boolean }\n >\n>;\n"],"names":["TaxLabelType"],"mappings":";;AAIY,IAAAA,YAAA,GAAA,gBAAAA,aAAL,IAAA;EACLA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,MAAO,CAAA,GAAA,MAAA;EALGA,OAAAA,aAAAA;AAAA,CAAA,EAAAA,YAAA,IAAA,CAAA,CAAA,CAAA;"}
1
+ {"version":3,"file":"types.mjs","sources":["../../../src/utils/tax/types.ts"],"sourcesContent":["import type { CountryCode, UserAssignedCountryCode } from \"../../types\";\n\nexport type TaxCountryCode = CountryCode | UserAssignedCountryCode;\n\nexport enum TaxLabelType {\n Tax = \"tax\",\n Vat = \"vat\",\n Gst = \"gst\",\n Cpf = \"cpf\",\n Cnpj = \"cnpj\",\n Rfc = \"rfc\",\n}\n\n/**\n * Ability to create custom logic (not regex based for taxId) validation\n */\nexport type CountryTaxIdValidationFn = (options: {\n taxCountryCode: TaxCountryCode;\n taxId: string;\n}) => boolean;\n\nexport type CountryTaxValidationMapping = Partial<\n Record<\n TaxCountryCode,\n { validation: CountryTaxIdValidationFn | RegExp; isOptional?: boolean }\n >\n>;\n"],"names":["TaxLabelType"],"mappings":";;AAIY,IAAAA,YAAA,GAAA,gBAAAA,aAAL,IAAA;EACLA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,KAAM,CAAA,GAAA,KAAA;EACNA,cAAA,MAAO,CAAA,GAAA,MAAA;EACPA,cAAA,KAAM,CAAA,GAAA,KAAA;EANIA,OAAAA,aAAAA;AAAA,CAAA,EAAAA,YAAA,IAAA,CAAA,CAAA,CAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubnt/store.core",
3
- "version": "9.4.0",
3
+ "version": "9.5.0-money.4",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "scripts": {
@@ -1,15 +0,0 @@
1
- /**
2
- * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)
3
- * @throws If given input is not a finite number
4
- */
5
- export declare function isFiniteNumber(value: unknown, entity?: string, ErrorClass?: new (message: string) => void): asserts value is number;
6
- /**
7
- * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a
8
- * Number.isSafeInteger would be sufficient.
9
- *
10
- * Code inspired from graphql-scalars library.
11
- * @see
12
- * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32
13
- * @throws If given input is not a valid integer
14
- */
15
- export declare function isInt(value: unknown, entity?: string, ErrorClass?: new (message: string) => void): asserts value is number;
@@ -1,23 +0,0 @@
1
- 'use strict';
2
- "use strict";
3
-
4
- function isFiniteNumber(value, entity = "Value", ErrorClass = TypeError) {
5
- if (typeof value !== "number" || Number.isNaN(value)) {
6
- throw new ErrorClass(`${entity} is not a number: ${value}`);
7
- }
8
- if (!Number.isFinite(value)) {
9
- throw new ErrorClass(`${entity} is not a finite number: ${value}`);
10
- }
11
- }
12
- function isInt(value, entity = "Value", ErrorClass = TypeError) {
13
- isFiniteNumber(value, entity, ErrorClass);
14
- if (!Number.isInteger(value)) {
15
- throw new ErrorClass(`${entity} is not an integer: ${value}`);
16
- }
17
- if (!Number.isSafeInteger(value)) {
18
- throw new ErrorClass(`${entity} is not a safe integer: ${value}`);
19
- }
20
- }
21
- exports.isFiniteNumber = isFiniteNumber;
22
- exports.isInt = isInt;
23
- //# sourceMappingURL=validations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validations.js","sources":["../../src/utils/validations.ts"],"sourcesContent":["/**\n * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)\n * @throws If given input is not a finite number\n */\nexport function isFiniteNumber(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a number: ${value}`);\n }\n\n if (!Number.isFinite(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a finite number: ${value}`);\n }\n}\n\n/**\n * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.isSafeInteger would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32\n * @throws If given input is not a valid integer\n */\nexport function isInt(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n\n if (!Number.isInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not an integer: ${value}`);\n }\n\n if (!Number.isSafeInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a safe integer: ${value}`);\n }\n}\n"],"names":["isFiniteNumber","value","entity","ErrorClass","TypeError","Number","isNaN","isFinite","isInt","isInteger","isSafeInteger"],"mappings":";;;AAIO,SAASA,cACdA,CAAAC,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACzB,IAAI,OAAOH,KAAU,KAAA,QAAA,IAAYI,MAAO,CAAAC,KAAA,CAAML,KAAK,CAAG,EAAA;IAEpD,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,qBAAqBD,KAAO,EAAA,CAAA;EAC5D;EAEA,IAAI,CAACI,MAAA,CAAOE,QAAS,CAAAN,KAAK,CAAG,EAAA;IAE3B,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,4BAA4BD,KAAO,EAAA,CAAA;EACnE;AACF;AAWO,SAASO,KACdA,CAAAP,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACVJ,cAAA,CAAAC,KAAA,EAAOC,QAAQC,UAAU,CAAA;EAExC,IAAI,CAACE,MAAA,CAAOI,SAAU,CAAAR,KAAK,CAAG,EAAA;IAE5B,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,uBAAuBD,KAAO,EAAA,CAAA;EAC9D;EAEA,IAAI,CAACI,MAAA,CAAOK,aAAc,CAAAT,KAAK,CAAG,EAAA;IAEhC,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,2BAA2BD,KAAO,EAAA,CAAA;EAClE;AACF;;"}
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- function isFiniteNumber(value, entity = "Value", ErrorClass = TypeError) {
4
- if (typeof value !== "number" || Number.isNaN(value)) {
5
- throw new ErrorClass(`${entity} is not a number: ${value}`);
6
- }
7
- if (!Number.isFinite(value)) {
8
- throw new ErrorClass(`${entity} is not a finite number: ${value}`);
9
- }
10
- }
11
- function isInt(value, entity = "Value", ErrorClass = TypeError) {
12
- isFiniteNumber(value, entity, ErrorClass);
13
- if (!Number.isInteger(value)) {
14
- throw new ErrorClass(`${entity} is not an integer: ${value}`);
15
- }
16
- if (!Number.isSafeInteger(value)) {
17
- throw new ErrorClass(`${entity} is not a safe integer: ${value}`);
18
- }
19
- }
20
- export { isFiniteNumber, isInt };
21
- //# sourceMappingURL=validations.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validations.mjs","sources":["../../src/utils/validations.ts"],"sourcesContent":["/**\n * Util to easily parse that any given input is a finite number (not NaN, Infinity, -Infinity, etc.)\n * @throws If given input is not a finite number\n */\nexport function isFiniteNumber(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a number: ${value}`);\n }\n\n if (!Number.isFinite(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a finite number: ${value}`);\n }\n}\n\n/**\n * Custom isInt validation function that returns a more fine-grained error message otherwise for type safety alone a\n * Number.isSafeInteger would be sufficient.\n *\n * Code inspired from graphql-scalars library.\n * @see\n * https://github.com/Urigo/graphql-scalars/blob/c4fa3d27b965e39ceda6c33fc18041f112ecce49/src/scalars/utilities.ts#L20-L32\n * @throws If given input is not a valid integer\n */\nexport function isInt(\n value: unknown,\n entity = \"Value\",\n ErrorClass: new (message: string) => void = TypeError,\n): asserts value is number {\n isFiniteNumber(value, entity, ErrorClass);\n\n if (!Number.isInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not an integer: ${value}`);\n }\n\n if (!Number.isSafeInteger(value)) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw new ErrorClass(`${entity} is not a safe integer: ${value}`);\n }\n}\n"],"names":["isFiniteNumber","value","entity","ErrorClass","TypeError","Number","isNaN","isFinite","isInt","isInteger","isSafeInteger"],"mappings":";;AAIO,SAASA,cACdA,CAAAC,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACzB,IAAI,OAAOH,KAAU,KAAA,QAAA,IAAYI,MAAO,CAAAC,KAAA,CAAML,KAAK,CAAG,EAAA;IAEpD,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,qBAAqBD,KAAO,EAAA,CAAA;EAC5D;EAEA,IAAI,CAACI,MAAA,CAAOE,QAAS,CAAAN,KAAK,CAAG,EAAA;IAE3B,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,4BAA4BD,KAAO,EAAA,CAAA;EACnE;AACF;AAWO,SAASO,KACdA,CAAAP,KAAA,EACAC,MAAS,GAAA,OAAA,EACTC,aAA4CC,SACnB,EAAA;EACVJ,cAAA,CAAAC,KAAA,EAAOC,QAAQC,UAAU,CAAA;EAExC,IAAI,CAACE,MAAA,CAAOI,SAAU,CAAAR,KAAK,CAAG,EAAA;IAE5B,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,uBAAuBD,KAAO,EAAA,CAAA;EAC9D;EAEA,IAAI,CAACI,MAAA,CAAOK,aAAc,CAAAT,KAAK,CAAG,EAAA;IAEhC,MAAM,IAAIE,UAAW,CAAA,GAAGD,MAAM,2BAA2BD,KAAO,EAAA,CAAA;EAClE;AACF;"}