@swan-io/shared-business 13.10.2 → 13.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-io/shared-business",
3
- "version": "13.10.2",
3
+ "version": "13.11.0",
4
4
  "engines": {
5
5
  "node": ">22.12.0"
6
6
  },
@@ -25,7 +25,7 @@
25
25
  ],
26
26
  "license": "MIT",
27
27
  "peerDependencies": {
28
- "@swan-io/lake": "13.10.2"
28
+ "@swan-io/lake": "13.11.0"
29
29
  },
30
30
  "dependencies": {
31
31
  "@formatjs/intl": "^4.1.2",
@@ -50,6 +50,6 @@
50
50
  "@types/react-dom": "^19.2.3",
51
51
  "@types/react-native": "^0.72.8",
52
52
  "type-fest": "^5.4.3",
53
- "@swan-io/lake": "13.10.2"
53
+ "@swan-io/lake": "13.11.0"
54
54
  }
55
55
  }
@@ -2,8 +2,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { LakeLabel } from "@swan-io/lake/src/components/LakeLabel";
3
3
  import { LakeTextInput } from "@swan-io/lake/src/components/LakeTextInput";
4
4
  import { t } from "../utils/i18n";
5
- import { getCompanyTaxNumberHelp, getCompanyTaxNumberPlaceholder, getIndividualTaxNumberHelp, getIndividualTaxNumberPlaceholder, } from "../utils/validation";
6
- export const TaxIdentificationNumberInput = ({ ref, value, error, valid, disabled, onChange, onBlur, country, isCompany, required, label = t("taxIdentificationNumber.label"), placeholder = isCompany
5
+ import { getCompanyTaxNumberHelp, getCompanyTaxNumberPlaceholder, getIndividualTaxNumberHelp, getIndividualTaxNumberPlaceholder, getTaxNumberLabel, } from "../utils/validation";
6
+ export const TaxIdentificationNumberInput = ({ ref, value, error, valid, disabled, onChange, onBlur, country, isCompany, required, label = getTaxNumberLabel(isCompany), placeholder = isCompany
7
7
  ? getCompanyTaxNumberPlaceholder(country)
8
8
  : getIndividualTaxNumberPlaceholder(country), }) => {
9
9
  return (_jsx(LakeLabel, { label: label, optionalLabel: required === true ? undefined : t("common.optional"), render: id => (_jsx(LakeTextInput, { id: id, ref: ref, placeholder: placeholder, help: isCompany ? getCompanyTaxNumberHelp(country) : getIndividualTaxNumberHelp(country), value: value, error: error, valid: valid, disabled: disabled, onChangeText: onChange, onBlur: onBlur })) }));
@@ -313,9 +313,9 @@ describe("Tax number helper functions", () => {
313
313
  expect(getIndividualTaxNumberPlaceholder("ESP")).toContain("Número de Identificación Fiscal");
314
314
  expect(getIndividualTaxNumberPlaceholder("ITA")).toContain("Codice fiscale");
315
315
  });
316
- test("returns generic placeholder for other countries", () => {
316
+ test("returns empty placeholder for other countries", () => {
317
317
  const placeholder = getIndividualTaxNumberPlaceholder("FRA");
318
- expect(placeholder).toBeTypeOf("string");
318
+ expect(placeholder).toBeNull;
319
319
  });
320
320
  });
321
321
  describe("getCompanyTaxNumberPlaceholder", () => {
@@ -324,9 +324,9 @@ describe("Tax number helper functions", () => {
324
324
  expect(getCompanyTaxNumberPlaceholder("ESP")).toContain("Número de Identificación Fiscal");
325
325
  expect(getCompanyTaxNumberPlaceholder("ITA")).toContain("Codice fiscale");
326
326
  });
327
- test("returns generic placeholder for other countries", () => {
327
+ test("returns empty placeholder for other countries", () => {
328
328
  const placeholder = getCompanyTaxNumberPlaceholder("FRA");
329
- expect(placeholder).toBeTypeOf("string");
329
+ expect(placeholder).toBeNull;
330
330
  });
331
331
  });
332
332
  describe("getIndividualTaxNumberHelp", () => {
@@ -11,15 +11,15 @@ export const getLanguagesHelpers = (languages) => {
11
11
  const isSupportedLanguage = (language) => (supportedLanguages !== null && supportedLanguages !== void 0 ? supportedLanguages : []).includes(language);
12
12
  const getFirstSupportedLanguage = (languages) => { var _a; return (_a = languages.find(isSupportedLanguage)) !== null && _a !== void 0 ? _a : LANGUAGE_FALLBACK; };
13
13
  const getPreferredLanguage = () => {
14
- // @deprecated temporary keeping localStorage and migrating to cookie
15
- const language = localStorage.getItem(PREFERRED_LANGUAGE_KEY);
16
- if (language) {
17
- localStorage.removeItem(PREFERRED_LANGUAGE_KEY);
18
- const domain = "." + window.location.hostname.split(".").slice(-2).join(".");
19
- document.cookie = `${PREFERRED_LANGUAGE_KEY}=${language}; path=/; max-age=31536000; SameSite=Lax; Secure; domain=${domain}`;
20
- return language;
21
- }
22
14
  try {
15
+ // @deprecated temporary keeping localStorage and migrating to cookie
16
+ const language = localStorage.getItem(PREFERRED_LANGUAGE_KEY);
17
+ if (language) {
18
+ localStorage.removeItem(PREFERRED_LANGUAGE_KEY);
19
+ const domain = "." + window.location.hostname.split(".").slice(-2).join(".");
20
+ document.cookie = `${PREFERRED_LANGUAGE_KEY}=${language}; path=/; max-age=31536000; SameSite=Lax; Secure; domain=${domain}`;
21
+ return language;
22
+ }
23
23
  const match = document.cookie
24
24
  .split("; ")
25
25
  .find(row => row.startsWith(PREFERRED_LANGUAGE_KEY + "="));
@@ -20,7 +20,8 @@ export { printFormat as printIbanFormat } from "iban";
20
20
  export declare const validateIban: (iban: string) => string | undefined;
21
21
  export declare const validateDate: (value: ExtractedDate | undefined) => string | undefined;
22
22
  export declare const validateBirthdate: (value: ExtractedDate | undefined) => string | undefined;
23
- export declare const getIndividualTaxNumberPlaceholder: (country: IndividualCountryCCA3 | CompanyCountryCCA3) => string;
24
- export declare const getCompanyTaxNumberPlaceholder: (country: IndividualCountryCCA3 | CompanyCountryCCA3) => string;
23
+ export declare const getTaxNumberLabel: (isCompany: boolean) => string;
24
+ export declare const getIndividualTaxNumberPlaceholder: (country: IndividualCountryCCA3 | CompanyCountryCCA3) => string | undefined;
25
+ export declare const getCompanyTaxNumberPlaceholder: (country: IndividualCountryCCA3 | CompanyCountryCCA3) => string | undefined;
25
26
  export declare const getCompanyTaxNumberHelp: (country: CompanyCountryCCA3) => string;
26
27
  export declare const getIndividualTaxNumberHelp: (country: IndividualCountryCCA3) => string;
@@ -238,15 +238,18 @@ export const validateBirthdate = (value) => {
238
238
  /*
239
239
  * Translation helpers for tax validation
240
240
  */
241
+ export const getTaxNumberLabel = (isCompany) => match({ isCompany, lang: locale.language })
242
+ .with({ isCompany: true, lang: "de" }, () => "Steuer-Nummer")
243
+ .otherwise(() => t("taxIdentificationNumber.label"));
241
244
  export const getIndividualTaxNumberPlaceholder = (country) => match({ country, lang: locale.language })
242
- .with({ country: "DEU", lang: P.not("de") }, () => `${t("common.form.taxIdentificationNumber.placeholder")} (Steueridentifikationsnummer)`)
243
- .with({ country: "ESP", lang: P.not("es") }, () => `${t("common.form.taxIdentificationNumber.placeholder")} (Número de Identificación Fiscal)`)
244
- .with({ country: "ITA", lang: P.not("it") }, () => `${t("common.form.taxIdentificationNumber.placeholder")} (Codice fiscale)`)
245
- .otherwise(() => t("common.form.taxIdentificationNumber.placeholder"));
245
+ .with({ country: "DEU", lang: P.not("de") }, () => "Steueridentifikationsnummer")
246
+ .with({ country: "ESP", lang: P.not("es") }, () => "Número de Identificación Fiscal")
247
+ .with({ country: "ITA", lang: P.not("it") }, () => "Codice fiscale")
248
+ .otherwise(() => undefined);
246
249
  export const getCompanyTaxNumberPlaceholder = (country) => match({ country, lang: locale.language })
247
- .with({ country: "DEU", lang: P.not("de") }, () => `${t("common.form.taxIdentificationNumber.placeholder")} (Steuer-Nummer)`)
248
- .with({ country: "ESP", lang: P.not("es") }, () => `${t("common.form.taxIdentificationNumber.placeholder")} (Número de Identificación Fiscal)`)
249
- .with({ country: "ITA", lang: P.not("it") }, () => `${t("common.form.taxIdentificationNumber.placeholder")} (Codice fiscale)`)
250
- .otherwise(() => t("common.form.taxIdentificationNumber.placeholder"));
250
+ .with({ country: "DEU", lang: P.not("de") }, () => "Steuer-Nummer")
251
+ .with({ country: "ESP", lang: P.not("es") }, () => "Número de Identificación Fiscal")
252
+ .with({ country: "ITA", lang: P.not("it") }, () => "Codice fiscale")
253
+ .otherwise(() => undefined);
251
254
  export const getCompanyTaxNumberHelp = (country) => { var _a, _b; return (_b = (_a = TAX_NUMBER_REGEX.company[country]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : ""; };
252
255
  export const getIndividualTaxNumberHelp = (country) => { var _a, _b; return (_b = (_a = TAX_NUMBER_REGEX.individual[country]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : ""; };