@ubnt/store.core 9.6.0-alpha.0 → 9.6.0-alpha.10
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.
- package/CHANGELOG.md +41 -1
- package/lib/assets/android.svg +3 -0
- package/lib/assets/attention.svg +5 -5
- package/lib/assets/attention2.svg +5 -5
- package/lib/assets/connectDisplay.jpg +0 -0
- package/lib/assets/ucCast.jpg +0 -0
- package/lib/assets/ucCastPro.jpg +0 -0
- package/lib/components/Footer/hooks/useFooterContent.js +1 -0
- package/lib/components/Footer/hooks/useFooterContent.js.map +1 -1
- package/lib/components/Footer/hooks/useFooterContent.mjs +1 -0
- package/lib/components/Footer/hooks/useFooterContent.mjs.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.js +23 -7
- package/lib/components/Header/ProHeader/ProHeader.js.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.mjs +25 -9
- package/lib/components/Header/ProHeader/ProHeader.mjs.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.styles.d.ts +0 -32
- package/lib/components/Header/ProHeader/ProHeader.styles.js +0 -32
- package/lib/components/Header/ProHeader/ProHeader.styles.js.map +1 -1
- package/lib/components/Header/ProHeader/ProHeader.styles.mjs +2 -31
- package/lib/components/Header/ProHeader/ProHeader.styles.mjs.map +1 -1
- package/lib/components/ModelCompareV3/ModelCompareV3.types.d.ts +3 -1
- package/lib/components/ModelCompareV3/assets/ProfessionalAV/connectDisplay.jpg.js +27 -0
- package/lib/components/ModelCompareV3/assets/ProfessionalAV/connectDisplay.jpg.js.map +1 -0
- package/lib/components/ModelCompareV3/assets/ProfessionalAV/connectDisplay.jpg.mjs +3 -0
- package/lib/components/ModelCompareV3/assets/ProfessionalAV/connectDisplay.jpg.mjs.map +1 -0
- package/lib/components/ModelCompareV3/assets/android.svg.js +27 -0
- package/lib/components/ModelCompareV3/assets/android.svg.js.map +1 -0
- package/lib/components/ModelCompareV3/assets/android.svg.mjs +3 -0
- package/lib/components/ModelCompareV3/assets/android.svg.mjs.map +1 -0
- package/lib/components/ModelCompareV3/data/{DisplayCast.d.ts → ProfessionalAV.d.ts} +1 -1
- package/lib/components/ModelCompareV3/data/ProfessionalAV.js +26 -0
- package/lib/components/ModelCompareV3/data/ProfessionalAV.js.map +1 -0
- package/lib/components/ModelCompareV3/data/{DisplayCast.mjs → ProfessionalAV.mjs} +10 -7
- package/lib/components/ModelCompareV3/data/ProfessionalAV.mjs.map +1 -0
- package/lib/components/ModelCompareV3/data/index.d.ts +1 -1
- package/lib/components/ModelCompareV3/data/index.js +3 -3
- package/lib/components/ModelCompareV3/data/index.js.map +1 -1
- package/lib/components/ModelCompareV3/data/index.mjs +3 -3
- package/lib/components/ModelCompareV3/data/index.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/connectDisplay.d.ts +2 -0
- package/lib/components/ModelCompareV3/data/products/connectDisplay.js +105 -0
- package/lib/components/ModelCompareV3/data/products/connectDisplay.js.map +1 -0
- package/lib/components/ModelCompareV3/data/products/connectDisplay.mjs +97 -0
- package/lib/components/ModelCompareV3/data/products/connectDisplay.mjs.map +1 -0
- package/lib/components/ModelCompareV3/data/products/ucCast.js +17 -3
- package/lib/components/ModelCompareV3/data/products/ucCast.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/ucCast.mjs +18 -4
- package/lib/components/ModelCompareV3/data/products/ucCast.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/products/ucCastPro.js +18 -3
- package/lib/components/ModelCompareV3/data/products/ucCastPro.js.map +1 -1
- package/lib/components/ModelCompareV3/data/products/ucCastPro.mjs +19 -4
- package/lib/components/ModelCompareV3/data/products/ucCastPro.mjs.map +1 -1
- package/lib/components/ModelCompareV3/data/properties/androidAppMode.d.ts +2 -0
- package/lib/components/ModelCompareV3/data/properties/androidAppMode.js +19 -0
- package/lib/components/ModelCompareV3/data/properties/androidAppMode.js.map +1 -0
- package/lib/components/ModelCompareV3/data/properties/androidAppMode.mjs +11 -0
- package/lib/components/ModelCompareV3/data/properties/androidAppMode.mjs.map +1 -0
- package/lib/components/ModelCompareV3/data/properties/index.d.ts +1 -0
- package/lib/components/ModelCompareV3/data/properties/index.js +2 -0
- package/lib/components/ModelCompareV3/data/properties/index.js.map +1 -1
- package/lib/components/ModelCompareV3/data/properties/index.mjs +1 -0
- package/lib/components/ModelCompareV3/data/properties/index.mjs.map +1 -1
- package/lib/components/ModelCompareV3/translations/en.json.js +37 -27
- package/lib/components/ModelCompareV3/translations/en.json.js.map +1 -1
- package/lib/components/ModelCompareV3/translations/en.json.mjs +37 -27
- package/lib/components/ModelCompareV3/translations/en.json.mjs.map +1 -1
- package/lib/components/ModelCompareV3/translations/useModelCompareTranslation.d.ts +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
- package/lib/components/Tooltip/Tooltip.d.ts +2 -0
- package/lib/components/Tooltip/Tooltip.js +38 -0
- package/lib/components/Tooltip/Tooltip.js.map +1 -0
- package/lib/components/Tooltip/Tooltip.mjs +36 -0
- package/lib/components/Tooltip/Tooltip.mjs.map +1 -0
- package/lib/components/Tooltip/Tooltip.styles.d.ts +32 -0
- package/lib/components/Tooltip/Tooltip.styles.js +44 -0
- package/lib/components/Tooltip/Tooltip.styles.js.map +1 -0
- package/lib/components/Tooltip/Tooltip.styles.mjs +34 -0
- package/lib/components/Tooltip/Tooltip.styles.mjs.map +1 -0
- package/lib/components/Tooltip/index.d.ts +1 -0
- package/lib/components/Tooltip/index.js +6 -0
- package/lib/components/Tooltip/index.js.map +1 -0
- package/lib/components/Tooltip/index.mjs +3 -0
- package/lib/components/Tooltip/index.mjs.map +1 -0
- package/lib/constants/postalCode.js +9 -0
- package/lib/constants/postalCode.js.map +1 -1
- package/lib/constants/postalCode.mjs +9 -0
- package/lib/constants/postalCode.mjs.map +1 -1
- package/lib/contexts/MenuContext/mapping.js +17 -2
- package/lib/contexts/MenuContext/mapping.js.map +1 -1
- package/lib/contexts/MenuContext/mapping.mjs +17 -2
- package/lib/contexts/MenuContext/mapping.mjs.map +1 -1
- package/lib/contexts/MenuContext/presets.d.ts +28 -15
- package/lib/contexts/MenuContext/presets.js +31 -20
- package/lib/contexts/MenuContext/presets.js.map +1 -1
- package/lib/contexts/MenuContext/presets.mjs +31 -20
- package/lib/contexts/MenuContext/presets.mjs.map +1 -1
- package/lib/types/generated.d.ts +6 -2
- package/lib/types/generated.js +2 -0
- package/lib/types/generated.js.map +1 -1
- package/lib/types/generated.mjs +2 -0
- package/lib/types/generated.mjs.map +1 -1
- package/lib/utils/money/allocators/index.d.ts +1 -0
- package/lib/utils/money/allocators/index.js +2 -0
- package/lib/utils/money/allocators/index.js.map +1 -1
- package/lib/utils/money/allocators/index.mjs +1 -0
- package/lib/utils/money/allocators/index.mjs.map +1 -1
- package/lib/utils/money/allocators/productAmount.d.ts +13 -0
- package/lib/utils/money/allocators/productAmount.js +110 -0
- package/lib/utils/money/allocators/productAmount.js.map +1 -0
- package/lib/utils/money/allocators/productAmount.mjs +108 -0
- package/lib/utils/money/allocators/productAmount.mjs.map +1 -0
- package/lib/utils/money/exchangeRate.d.ts +1 -1
- package/lib/utils/money/exchangeRate.js.map +1 -1
- package/lib/utils/money/exchangeRate.mjs.map +1 -1
- package/lib/utils/money/types.d.ts +19 -5
- package/lib/utils/nextjs/navigationPresets.d.ts +4 -3
- package/lib/utils/nextjs/navigationPresets.js +2 -1
- package/lib/utils/nextjs/navigationPresets.js.map +1 -1
- package/lib/utils/nextjs/navigationPresets.mjs +2 -1
- package/lib/utils/nextjs/navigationPresets.mjs.map +1 -1
- package/lib/utils/product.js +1 -0
- package/lib/utils/product.js.map +1 -1
- package/lib/utils/product.mjs +1 -0
- package/lib/utils/product.mjs.map +1 -1
- package/lib/utils/shipping.js +1 -0
- package/lib/utils/shipping.js.map +1 -1
- package/lib/utils/shipping.mjs +1 -0
- package/lib/utils/shipping.mjs.map +1 -1
- package/lib/utils/tax/index.js +1 -0
- package/lib/utils/tax/index.js.map +1 -1
- package/lib/utils/tax/index.mjs +1 -0
- package/lib/utils/tax/index.mjs.map +1 -1
- package/package.json +4 -4
- package/lib/components/ModelCompareV3/data/DisplayCast.js +0 -23
- package/lib/components/ModelCompareV3/data/DisplayCast.js.map +0 -1
- package/lib/components/ModelCompareV3/data/DisplayCast.mjs.map +0 -1
- /package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCast.jpg.js +0 -0
- /package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCast.jpg.js.map +0 -0
- /package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCast.jpg.mjs +0 -0
- /package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCast.jpg.mjs.map +0 -0
- /package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCastPro.jpg.js +0 -0
- /package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCastPro.jpg.js.map +0 -0
- /package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCastPro.jpg.mjs +0 -0
- /package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCastPro.jpg.mjs.map +0 -0
|
@@ -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 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,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,2BAA2BC,IAAI,CAAA;AAK5C,MAAMS,uBAA0B,GAAAA,CACrCT,IACA,EAAAQ,cAAA,EACAE,KACY,KAAA;EAEZ,IAAI,CAACH,6BAAA,CAA8BP,IAAM,EAAAQ,cAAc,CAAG,EAAA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C,CAAA;EAIrC,OAAOZ,mBAAuB,IAAApB,OAAA;AAChC,CAAA;AAEa,MAAAoC,mBAAA,GAAsBA,CACjC1E,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,MAAM8D,kBAAkBA,CAC7BC,SAAA,EACA;EAAEtC,OAAA;EAASc;CACR,KAAA;EAEC,IAAAd,OAAA,KAAYE,sBAAYjB,EAAI,EAAA;IACvB,OAAAqD,SAAA;EACT;EAEA,QAAQxB,WAAa;IACnB,KAAKnD,SAAY,CAAAA,WAAA,CAAAG,WAAA;MACf,OAAOyE,MAAAA,CAAAA,UAAUD,SAAS,CAAA;IAE5B,KAAK3E,SAAY,CAAAA,WAAA,CAAAC,QAAA;MACf,OAAO4E,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.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,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,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,UAAY,EAAA;IACR,OAAA,IAAA;EACT;EAGO,OAAAE,4BAAA,CAASF,UAAU,CAAA,GACtBA,UAAW,CAAAG,IAAA,CAAKL,KAAK,CAAA,GACrBE,UAAW,CAAA;IAAEF,KAAO;IAAAF;EAAgB,CA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A;EAAEtC,OAAA;EAASc;CACR,KAAA;EAEC,IAAAd,OAAA,KAAYE,sBAAYlB,EAAI,EAAA;IACvB,OAAAsD,SAAA;EACT;EAEA,QAAQxB,WAAa;IACnB,KAAKpD,SAAY,CAAAA,WAAA,CAAAG,WAAA;MACf,OAAO0E,MAAAA,CAAAA,UAAUD,SAAS,CAAA;IAE5B,KAAK5E,SAAY,CAAAA,WAAA,CAAAC,QAAA;MACf,OAAO6E,MAAAA,CAAAA,WAAWF,SAAS,CAAA;IAE7B;MACExC,MAAA,CAAAA,gBAAA,CAAiBgB,WAAW,CAAA;MACrB,OAAAwB,SAAA;EACX;AACF,CAAA;;;;;;;;"}
|
package/lib/utils/tax/index.mjs
CHANGED
|
@@ -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 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,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A;EAC/C,MAAM;IAAEa;EAAA,CAAe,GAAAF,OAAA,CAAQH,cAAc,CAAA;EAEtC,OAAAK,UAAA;AACT,CAAA;AAEO,MAAM8D,kBAAkBA,CAC7BC,SAAA,EACA;EAAEtC,OAAA;EAASc;CACR,KAAA;EAEC,IAAAd,OAAA,KAAYE,YAAYjB,EAAI,EAAA;IACvB,OAAAqD,SAAA;EACT;EAEA,QAAQxB,WAAa;IACnB,KAAKnD,WAAY,CAAAG,WAAA;MACf,OAAOyE,UAAUD,SAAS,CAAA;IAE5B,KAAK3E,WAAY,CAAAC,QAAA;MACf,OAAO4E,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 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,K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,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,MAAM+D,kBAAkBA,CAC7BC,SAAA,EACA;EAAEtC,OAAA;EAASc;CACR,KAAA;EAEC,IAAAd,OAAA,KAAYE,YAAYlB,EAAI,EAAA;IACvB,OAAAsD,SAAA;EACT;EAEA,QAAQxB,WAAa;IACnB,KAAKpD,WAAY,CAAAG,WAAA;MACf,OAAO0E,UAAUD,SAAS,CAAA;IAE5B,KAAK5E,WAAY,CAAAC,QAAA;MACf,OAAO6E,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.6.0-alpha.
|
|
3
|
+
"version": "9.6.0-alpha.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"scripts": {
|
|
@@ -59,15 +59,15 @@
|
|
|
59
59
|
"style-loader": "4.0.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@dinero.js/currencies": "
|
|
62
|
+
"@dinero.js/currencies": "2.0.0-alpha.8",
|
|
63
63
|
"@faker-js/faker": "^7.6.0",
|
|
64
64
|
"@formatjs/intl": "^2.10.4",
|
|
65
65
|
"@types/lodash-es": "^4.17.12",
|
|
66
66
|
"@ubnt/ui-components": "^62.1.1",
|
|
67
67
|
"big.js": "^6.2.1",
|
|
68
|
-
"convert-units": "
|
|
68
|
+
"convert-units": "3.0.0-beta.5",
|
|
69
69
|
"countup.js": "^2.6.2",
|
|
70
|
-
"dinero.js": "
|
|
70
|
+
"dinero.js": "2.0.0-alpha.8",
|
|
71
71
|
"intl-messageformat": "^10.5.14",
|
|
72
72
|
"libphonenumber-js": "^1.11.4",
|
|
73
73
|
"lodash-es": "^4.17.21",
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var ucCast = require('./products/ucCast.js');
|
|
4
|
-
var ucCastPro = require('./products/ucCastPro.js');
|
|
5
|
-
require('./properties/index.js');
|
|
6
|
-
var digitalSignageMode = require('./properties/digitalSignageMode.js');
|
|
7
|
-
var videoContentSupport = require('./properties/videoContentSupport.js');
|
|
8
|
-
var webMode = require('./properties/webMode.js');
|
|
9
|
-
var youtubeMode = require('./properties/youtubeMode.js');
|
|
10
|
-
var hdmiCec = require('./properties/hdmiCec.js');
|
|
11
|
-
var usbCPeripheralSupport = require('./properties/usbCPeripheralSupport.js');
|
|
12
|
-
var connectivity = require('./properties/connectivity.js');
|
|
13
|
-
var powerMethodPoe = require('./properties/powerMethodPoe.js');
|
|
14
|
-
"use strict";
|
|
15
|
-
const DisplayCast = {
|
|
16
|
-
properties: [digitalSignageMode.digitalSignageMode, videoContentSupport.videoContentSupport, webMode.webMode, youtubeMode.youtubeMode, hdmiCec.hdmiCec, usbCPeripheralSupport.usbCPeripheralSupport, connectivity.connectivity, powerMethodPoe.powerMethodPoe],
|
|
17
|
-
products: [ucCastPro.ucCastPro, ucCast.ucCast],
|
|
18
|
-
showBadges: true,
|
|
19
|
-
columnWidth: 324,
|
|
20
|
-
propertyColumnWidth: 251
|
|
21
|
-
};
|
|
22
|
-
exports.DisplayCast = DisplayCast;
|
|
23
|
-
//# sourceMappingURL=DisplayCast.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DisplayCast.js","sources":["../../../../src/components/ModelCompareV3/data/DisplayCast.tsx"],"sourcesContent":["import type { Section } from \"../ModelCompareV3.types\";\nimport { ucCast } from \"./products/ucCast\";\nimport { ucCastPro } from \"./products/ucCastPro\";\nimport {\n connectivity,\n hdmiCec,\n powerMethodPoe,\n usbCPeripheralSupport,\n videoContentSupport,\n webMode,\n youtubeMode,\n} from \"./properties\";\nimport { digitalSignageMode } from \"./properties/digitalSignageMode\";\n\nexport const DisplayCast: Section = {\n properties: [\n digitalSignageMode,\n videoContentSupport,\n webMode,\n youtubeMode,\n hdmiCec,\n usbCPeripheralSupport,\n connectivity,\n powerMethodPoe,\n ],\n products: [ucCastPro, ucCast],\n showBadges: true,\n columnWidth: 324,\n propertyColumnWidth: 251,\n};\n"],"names":["DisplayCast","properties","digitalSignageMode","videoContentSupport","webMode","youtubeMode","hdmiCec","usbCPeripheralSupport","connectivity","powerMethodPoe","products","ucCastPro","ucCast","showBadges","columnWidth","propertyColumnWidth"],"mappings":";;;;;;;;;;;;;;AAcO,MAAMA,WAAuB,GAAA;EAClCC,UAAY,EAAA,CACVC,kBAAA,CAAAA,kBAAA,EACAC,mBAAA,CAAAA,mBAAA,EACAC,OAAA,CAAAA,OAAA,EACAC,WAAA,CAAAA,WAAA,EACAC,OAAA,CAAAA,OAAA,EACAC,qBAAA,CAAAA,qBAAA,EACAC,YAAA,CAAAA,YAAA,EACAC,cAAA,CAAAA,cAAA,CACF;EACAC,QAAA,EAAU,CAACC,SAAA,CAAAA,SAAA,EAAWC,aAAM,CAAA;EAC5BC,UAAY,EAAA,IAAA;EACZC,WAAa,EAAA,GAAA;EACbC,mBAAqB,EAAA;AACvB,CAAA;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DisplayCast.mjs","sources":["../../../../src/components/ModelCompareV3/data/DisplayCast.tsx"],"sourcesContent":["import type { Section } from \"../ModelCompareV3.types\";\nimport { ucCast } from \"./products/ucCast\";\nimport { ucCastPro } from \"./products/ucCastPro\";\nimport {\n connectivity,\n hdmiCec,\n powerMethodPoe,\n usbCPeripheralSupport,\n videoContentSupport,\n webMode,\n youtubeMode,\n} from \"./properties\";\nimport { digitalSignageMode } from \"./properties/digitalSignageMode\";\n\nexport const DisplayCast: Section = {\n properties: [\n digitalSignageMode,\n videoContentSupport,\n webMode,\n youtubeMode,\n hdmiCec,\n usbCPeripheralSupport,\n connectivity,\n powerMethodPoe,\n ],\n products: [ucCastPro, ucCast],\n showBadges: true,\n columnWidth: 324,\n propertyColumnWidth: 251,\n};\n"],"names":["DisplayCast","properties","digitalSignageMode","videoContentSupport","webMode","youtubeMode","hdmiCec","usbCPeripheralSupport","connectivity","powerMethodPoe","products","ucCastPro","ucCast","showBadges","columnWidth","propertyColumnWidth"],"mappings":";;;;;;;;;;;;AAcO,MAAMA,WAAuB,GAAA;EAClCC,UAAY,EAAA,CACVC,kBAAA,EACAC,mBAAA,EACAC,OAAA,EACAC,WAAA,EACAC,OAAA,EACAC,qBAAA,EACAC,YAAA,EACAC,cAAA,CACF;EACAC,QAAA,EAAU,CAACC,SAAA,EAAWC,MAAM,CAAA;EAC5BC,UAAY,EAAA,IAAA;EACZC,WAAa,EAAA,GAAA;EACbC,mBAAqB,EAAA;AACvB,CAAA;"}
|
|
File without changes
|
/package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCast.jpg.js.map
RENAMED
|
File without changes
|
|
File without changes
|
/package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCast.jpg.mjs.map
RENAMED
|
File without changes
|
/package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCastPro.jpg.js
RENAMED
|
File without changes
|
/package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCastPro.jpg.js.map
RENAMED
|
File without changes
|
/package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCastPro.jpg.mjs
RENAMED
|
File without changes
|
/package/lib/components/ModelCompareV3/assets/{DisplayCast → ProfessionalAV}/ucCastPro.jpg.mjs.map
RENAMED
|
File without changes
|