@swan-io/shared-business 11.4.2 → 12.0.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": "11.4.2",
3
+ "version": "12.0.0",
4
4
  "engines": {
5
5
  "node": "^22.12.0",
6
6
  "pnpm": "^10.2.0"
@@ -26,32 +26,32 @@
26
26
  ],
27
27
  "license": "MIT",
28
28
  "peerDependencies": {
29
- "@swan-io/lake": "11.4.2"
29
+ "@swan-io/lake": "12.0.0"
30
30
  },
31
31
  "dependencies": {
32
- "@formatjs/intl": "^3.1.4",
32
+ "@formatjs/intl": "^3.1.6",
33
33
  "@placekit/client-js": "^2.3.0",
34
34
  "@swan-io/boxed": "^3.2.0",
35
35
  "@swan-io/request": "^2.0.0",
36
36
  "@swan-io/use-form": "^3.1.0",
37
37
  "dayjs": "^1.11.13",
38
38
  "iban": "^0.0.14",
39
- "react": "^18.3.1",
39
+ "react": "^19.1.0",
40
40
  "react-atomic-state": "^2.0.0",
41
- "react-dom": "^18.3.1",
42
- "react-dropzone": "^14.3.5",
43
- "react-native-web": "^0.19.13",
41
+ "react-dom": "^19.1.0",
42
+ "react-dropzone": "^14.3.8",
43
+ "react-native-web": "^0.20.0",
44
44
  "rifm": "^0.12.1",
45
- "ts-pattern": "^5.6.2",
46
- "uuid": "^11.0.5"
45
+ "ts-pattern": "^5.7.0",
46
+ "uuid": "^11.1.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/iban": "0.0.35",
50
- "@types/react": "^18.3.12",
51
- "@types/react-dom": "^18.3.1",
50
+ "@types/react": "^19.1.2",
51
+ "@types/react-dom": "^19.1.2",
52
52
  "@types/react-native": "^0.72.8",
53
- "jsdom": "^26.0.0",
53
+ "jsdom": "^26.1.0",
54
54
  "vitest": "^2.1.8",
55
- "@swan-io/lake": "11.4.2"
55
+ "@swan-io/lake": "12.0.0"
56
56
  }
57
57
  }
@@ -1,7 +1,8 @@
1
- import { ForwardedRef } from "react";
1
+ import { Ref } from "react";
2
2
  import { View } from "react-native";
3
3
  import { CountryCCA3 } from "../constants/countries";
4
4
  type Props<T extends CountryCCA3> = {
5
+ ref?: Ref<View>;
5
6
  onValueChange: (country: T) => void;
6
7
  value: T | undefined;
7
8
  countries: T[];
@@ -12,8 +13,5 @@ type Props<T extends CountryCCA3> = {
12
13
  disabled?: boolean;
13
14
  hideErrors?: boolean;
14
15
  };
15
- declare const CountryPickerWithRef: <T extends CountryCCA3>({ onValueChange, value, countries, readOnly, id, error, placeholder, disabled, hideErrors, }: Props<T>, forwardedRef: ForwardedRef<View>) => import("react/jsx-runtime").JSX.Element;
16
- export declare const CountryPicker: <T extends CountryCCA3>(props: Props<T> & {
17
- ref?: ForwardedRef<View>;
18
- }) => ReturnType<typeof CountryPickerWithRef>;
16
+ export declare const CountryPicker: <T extends CountryCCA3>({ ref, onValueChange, value, countries, readOnly, id, error, placeholder, disabled, hideErrors, }: Props<T>) => import("react/jsx-runtime").JSX.Element;
19
17
  export {};
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { LakeSelect } from "@swan-io/lake/src/components/LakeSelect";
3
- import { forwardRef, useMemo } from "react";
3
+ import { useMemo } from "react";
4
4
  import { Flag } from "../components/Flag";
5
5
  import { getCountryByCCA3 } from "../constants/countries";
6
- const CountryPickerWithRef = ({ onValueChange, value, countries, readOnly, id, error, placeholder, disabled, hideErrors, }, forwardedRef) => {
6
+ export const CountryPicker = ({ ref, onValueChange, value, countries, readOnly, id, error, placeholder, disabled, hideErrors, }) => {
7
7
  const items = useMemo(() => {
8
8
  return countries
9
9
  .filter((item, index, array) => array.indexOf(item) === index) // deduplicate
@@ -17,6 +17,5 @@ const CountryPickerWithRef = ({ onValueChange, value, countries, readOnly, id, e
17
17
  })
18
18
  .sort((a, b) => a.name.localeCompare(b.name));
19
19
  }, [countries]);
20
- return (_jsx(LakeSelect, { readOnly: readOnly, id: id, ref: forwardedRef, error: error, items: items, placeholder: placeholder, value: value, onValueChange: onValueChange, disabled: disabled, hideErrors: hideErrors }));
20
+ return (_jsx(LakeSelect, { readOnly: readOnly, id: id, ref: ref, error: error, items: items, placeholder: placeholder, value: value, onValueChange: onValueChange, disabled: disabled, hideErrors: hideErrors }));
21
21
  };
22
- export const CountryPicker = forwardRef(CountryPickerWithRef);
@@ -1,9 +1,10 @@
1
1
  import { Future, Result } from "@swan-io/boxed";
2
2
  import { IconName } from "@swan-io/lake/src/components/Icon";
3
- import { ForwardedRef, Ref } from "react";
3
+ import { Ref } from "react";
4
4
  import { Config } from "../hooks/useFilesUploader";
5
5
  import { SwanFile } from "../utils/SwanFile";
6
6
  type Props<UploadInput, UploadOutput, GenerateUploadError, UploadFileError> = Config<UploadInput, UploadOutput, GenerateUploadError, UploadFileError> & {
7
+ ref?: Ref<FilesUploaderRef>;
7
8
  getUploadConfig: (file: File) => UploadInput;
8
9
  accept: string[];
9
10
  maxSize: number;
@@ -17,8 +18,5 @@ type Props<UploadInput, UploadOutput, GenerateUploadError, UploadFileError> = Co
17
18
  export type FilesUploaderRef = {
18
19
  add: (file: SwanFile) => void;
19
20
  };
20
- declare const FilesUploaderWithRef: <UploadInput, UploadOutput, GenerateUploadError, UploadFileError>({ maxSize, accept, icon, getUploadConfig, onRemoveFile, onChange, formatAndSizeDescription, canUpload, showIds, ...config }: Props<UploadInput, UploadOutput, GenerateUploadError, UploadFileError>, ref: Ref<FilesUploaderRef>) => import("react/jsx-runtime").JSX.Element;
21
- export declare const FilesUploader: <UploadInput, UploadOutput, GenerateUploadError, UploadFileError>(props: Props<UploadInput, UploadOutput, GenerateUploadError, UploadFileError> & {
22
- ref?: ForwardedRef<FilesUploaderRef>;
23
- }) => ReturnType<typeof FilesUploaderWithRef>;
21
+ export declare const FilesUploader: <UploadInput, UploadOutput, GenerateUploadError, UploadFileError>({ ref, maxSize, accept, icon, getUploadConfig, onRemoveFile, onChange, formatAndSizeDescription, canUpload, showIds, ...config }: Props<UploadInput, UploadOutput, GenerateUploadError, UploadFileError>) => import("react/jsx-runtime").JSX.Element;
24
22
  export {};
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box } from "@swan-io/lake/src/components/Box";
3
3
  import { Space } from "@swan-io/lake/src/components/Space";
4
- import { Fragment, forwardRef, useEffect, useImperativeHandle, useRef, } from "react";
4
+ import { Fragment, useEffect, useImperativeHandle, useRef } from "react";
5
5
  import { useFilesUploader } from "../hooks/useFilesUploader";
6
6
  import { FileInput } from "./FileInput";
7
7
  import { FileTile } from "./FileTile";
8
- const FilesUploaderWithRef = ({ maxSize, accept, icon, getUploadConfig, onRemoveFile, onChange, formatAndSizeDescription, canUpload = true, showIds = false, ...config }, ref) => {
8
+ export const FilesUploader = ({ ref, maxSize, accept, icon, getUploadConfig, onRemoveFile, onChange, formatAndSizeDescription, canUpload = true, showIds = false, ...config }) => {
9
9
  const { files, upload, remove, add } = useFilesUploader(config);
10
10
  // Keep the `onChange` callback as a ref to avoid running the effect
11
11
  // every time the function updates
@@ -36,4 +36,3 @@ const FilesUploaderWithRef = ({ maxSize, accept, icon, getUploadConfig, onRemove
36
36
  })
37
37
  : undefined })] }, file.id)))] }));
38
38
  };
39
- export const FilesUploader = forwardRef(FilesUploaderWithRef);
@@ -13,11 +13,10 @@ import { Stack } from "@swan-io/lake/src/components/Stack";
13
13
  import { Tag } from "@swan-io/lake/src/components/Tag";
14
14
  import { colors, shadows } from "@swan-io/lake/src/constants/design";
15
15
  import { useDisclosure } from "@swan-io/lake/src/hooks/useDisclosure";
16
- import { useMergeRefs } from "@swan-io/lake/src/hooks/useMergeRefs";
17
16
  import { usePreviousValue } from "@swan-io/lake/src/hooks/usePreviousValue";
18
17
  import { isNotNullish, isNullish } from "@swan-io/lake/src/utils/nullish";
19
18
  import dayjs from "dayjs";
20
- import { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from "react";
19
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
21
20
  import { Pressable, StyleSheet, Text, View } from "react-native";
22
21
  import { P, match } from "ts-pattern";
23
22
  import { locale, t } from "../utils/i18n";
@@ -75,11 +74,7 @@ const styles = StyleSheet.create({
75
74
  whiteSpace: "nowrap",
76
75
  },
77
76
  });
78
- const FilterTag = forwardRef(({ onPress, onPressRemove, label, value = "", isActive }, forwardRef) => {
79
- const ref = useRef(null);
80
- const mergedRef = useMergeRefs(ref, forwardRef);
81
- return (_jsx(Pressable, { ref: mergedRef, onPress: onPress, children: ({ hovered }) => (_jsxs(_Fragment, { children: [_jsx(View, { style: [styles.shadowed, hovered && styles.hovered] }), _jsx(Tag, { label: label, color: "current", onPressRemove: onPressRemove, children: _jsxs(Box, { direction: "row", alignItems: "center", children: [_jsx(Text, { numberOfLines: 1, style: styles.value, children: value }), _jsx(Space, { width: 4 }), _jsx(Icon, { color: colors.current.primary, name: isActive ? "chevron-up-filled" : "chevron-down-filled", size: 16 })] }) })] })) }));
82
- });
77
+ const FilterTag = ({ ref, onPress, onPressRemove, label, value = "", isActive }) => (_jsx(Pressable, { ref: ref, onPress: onPress, children: ({ hovered }) => (_jsxs(_Fragment, { children: [_jsx(View, { style: [styles.shadowed, hovered && styles.hovered] }), _jsx(Tag, { label: label, color: "current", onPressRemove: onPressRemove, children: _jsxs(Box, { direction: "row", alignItems: "center", children: [_jsx(Text, { numberOfLines: 1, style: styles.value, children: value }), _jsx(Space, { width: 4 }), _jsx(Icon, { color: colors.current.primary, name: isActive ? "chevron-up-filled" : "chevron-down-filled", size: 16 })] }) })] })) }));
83
78
  const FilterRadio = ({ label, items, width, value, onValueChange, onPressRemove, autoOpen = false, }) => {
84
79
  const inputRef = useRef(null);
85
80
  const [visible, { close, toggle }] = useDisclosure(autoOpen);
@@ -1,5 +1,5 @@
1
1
  import { PKOptions } from "@placekit/client-js";
2
- import { MutableRefObject } from "react";
2
+ import { Ref } from "react";
3
3
  import { StyleProp, ViewStyle } from "react-native";
4
4
  import { CountryCCA3 } from "../constants/countries";
5
5
  export type AddressDetail = {
@@ -10,7 +10,7 @@ export type AddressDetail = {
10
10
  countryCode: string;
11
11
  };
12
12
  type Props = {
13
- inputRef?: MutableRefObject<unknown>;
13
+ inputRef?: Ref<unknown>;
14
14
  id?: string;
15
15
  types?: PKOptions["types"];
16
16
  country?: CountryCCA3;
@@ -1,4 +1,4 @@
1
- import { ReactElement } from "react";
1
+ import { ReactNode } from "react";
2
2
  declare const keys: {
3
3
  "end-user": string;
4
4
  partner: string;
@@ -18,9 +18,9 @@ type Props = {
18
18
  accentColor?: string;
19
19
  children: (props: {
20
20
  onPressShow: () => void;
21
- }) => ReactElement;
21
+ }) => ReactNode;
22
22
  type: keyof typeof keys;
23
23
  additionalInfo: AdditionalInfo;
24
24
  };
25
- export declare const SupportChat: ({ children, accentColor, type, additionalInfo }: Props) => ReactElement<any, string | import("react").JSXElementConstructor<any>>;
25
+ export declare const SupportChat: ({ children, accentColor, type, additionalInfo }: Props) => ReactNode;
26
26
  export {};
@@ -1,6 +1,6 @@
1
1
  import { Future, Result } from "@swan-io/boxed";
2
2
  import { NetworkError, Response, TimeoutError } from "@swan-io/request";
3
- import { ForwardedRef, Ref } from "react";
3
+ import { Ref } from "react";
4
4
  import { UploadFileInput, UploadOutputWithId } from "../hooks/useFilesUploader";
5
5
  import { SwanFile } from "../utils/SwanFile";
6
6
  export type Document<Purpose extends string> = {
@@ -27,7 +27,12 @@ type PurposeMetadata = {
27
27
  value: string;
28
28
  }[];
29
29
  };
30
+ export type SupportingDocumentCollectionRef<Purpose extends string> = {
31
+ areAllRequiredDocumentsFilled: () => boolean;
32
+ addDocument: (document: Document<Purpose>) => void;
33
+ };
30
34
  type Props<Purpose extends string> = {
35
+ ref?: Ref<SupportingDocumentCollectionRef<Purpose>>;
31
36
  status: SupportingDocumentCollectionStatus;
32
37
  generateUpload: (input: UploadInput<Purpose>) => Future<Result<UploadOutputWithId<UploadOutput>, unknown>>;
33
38
  documents: Document<Purpose>[];
@@ -43,12 +48,5 @@ type Props<Purpose extends string> = {
43
48
  };
44
49
  export declare const getSupportingDocumentPurposeLabel: (purpose: string) => string;
45
50
  export declare const getSupportingDocumentPurposeDescriptionLabel: (purpose: string) => string;
46
- export type SupportingDocumentCollectionRef<Purpose extends string> = {
47
- areAllRequiredDocumentsFilled: () => boolean;
48
- addDocument: (document: Document<Purpose>) => void;
49
- };
50
- export declare const SupportingDocumentCollectionWithRef: <Purpose extends string>({ documents, generateUpload, uploadFile, requiredDocumentPurposes, templateLanguage, status, onRemoveFile, showIds, readOnly, getPurposeMetadata, readonlyDocumentPurposes, }: Props<Purpose>, ref: Ref<SupportingDocumentCollectionRef<Purpose>>) => import("react/jsx-runtime").JSX.Element;
51
- export declare const SupportingDocumentCollection: <I extends string>(props: Props<I> & {
52
- ref?: ForwardedRef<SupportingDocumentCollectionRef<I>>;
53
- }) => ReturnType<typeof SupportingDocumentCollectionWithRef>;
51
+ export declare const SupportingDocumentCollection: <Purpose extends string>({ ref, documents, generateUpload, uploadFile, requiredDocumentPurposes, templateLanguage, status, onRemoveFile, showIds, readOnly, getPurposeMetadata, readonlyDocumentPurposes, }: Props<Purpose>) => import("react/jsx-runtime").JSX.Element;
54
52
  export {};
@@ -11,7 +11,7 @@ import { Space } from "@swan-io/lake/src/components/Space";
11
11
  import { colors } from "@swan-io/lake/src/constants/design";
12
12
  import { isNotNullish } from "@swan-io/lake/src/utils/nullish";
13
13
  import { Request, badStatusToError } from "@swan-io/request";
14
- import { Fragment, forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, } from "react";
14
+ import { Fragment, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
15
15
  import { StyleSheet } from "react-native";
16
16
  import { match } from "ts-pattern";
17
17
  import { isTranslationKey, locale, t } from "../utils/i18n";
@@ -47,7 +47,7 @@ export const getSupportingDocumentPurposeDescriptionLabel = (purpose) => {
47
47
  const key = `supportingDocuments.purpose.${purpose}.description`;
48
48
  return isTranslationKey(key) ? t(key) : "";
49
49
  };
50
- export const SupportingDocumentCollectionWithRef = ({ documents, generateUpload, uploadFile, requiredDocumentPurposes, templateLanguage = locale.language, status, onRemoveFile, showIds = false, readOnly = false, getPurposeMetadata, readonlyDocumentPurposes = [], }, ref) => {
50
+ export const SupportingDocumentCollection = ({ ref, documents, generateUpload, uploadFile, requiredDocumentPurposes, templateLanguage = locale.language, status, onRemoveFile, showIds = false, readOnly = false, getPurposeMetadata, readonlyDocumentPurposes = [], }) => {
51
51
  const [showPowerOfAttorneyModal, setShowPowerOfAttorneyModal] = useState(false);
52
52
  const [showSwornStatementModal, setShowSwornStatementModal] = useState(false);
53
53
  const [currentMetadata, setCurrentMetadata] = useState(undefined);
@@ -165,4 +165,3 @@ export const SupportingDocumentCollectionWithRef = ({ documents, generateUpload,
165
165
  .with("es", () => "es")
166
166
  .otherwise(() => "en")}.pdf`), children: t("supportingDocuments.downloadTemplate") }) })] }), _jsxs(LakeModal, { visible: showSwornStatementModal, title: t("supportingDocuments.purpose.SwornStatement"), icon: "document-regular", onPressClose: () => setShowSwornStatementModal(false), children: [_jsx(LakeText, { children: t("supportingDocuments.purpose.SwornStatement.description") }), _jsx(Space, { height: 16 }), _jsx(LakeButtonGroup, { paddingBottom: 0, children: _jsx(LakeButton, { grow: true, color: "current", onPress: () => window.open("/sworn-statement-template/es.pdf"), children: t("supportingDocuments.downloadTemplate") }) })] }), _jsx(LakeModal, { visible: isNotNullish(currentMetadata), title: t("supportingDocuments.informations"), icon: "document-regular", onPressClose: () => setCurrentMetadata(undefined), children: _jsx(ReadOnlyFieldList, { children: currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.values.map(({ title, value, type }, index) => (_jsx(LakeLabel, { type: "viewSmall", label: title, actions: type === "copy" && (_jsx(LakeCopyButton, { valueToCopy: value, copiedText: t("copyButton.copiedTooltip"), copyText: t("copyButton.copyTooltip") })), render: () => (_jsx(LakeText, { variant: "regular", color: colors.gray[900], children: value })) }, `metadata-${index}`))) }) })] }));
167
167
  };
168
- export const SupportingDocumentCollection = forwardRef(SupportingDocumentCollectionWithRef);
@@ -1,6 +1,8 @@
1
+ import { Ref } from "react";
1
2
  import { TextInput } from "react-native";
2
3
  import { AccountCountry } from "../utils/templateTranslations";
3
4
  type Props = {
5
+ ref?: Ref<TextInput>;
4
6
  value: string;
5
7
  error: string | undefined;
6
8
  valid: boolean;
@@ -11,6 +13,7 @@ type Props = {
11
13
  isCompany: boolean;
12
14
  required?: boolean;
13
15
  label?: string;
16
+ placeholder?: string;
14
17
  };
15
- export declare const TaxIdentificationNumberInput: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<TextInput | null>>;
18
+ export declare const TaxIdentificationNumberInput: ({ ref, value, error, valid, disabled, onChange, onBlur, accountCountry, isCompany, required, label, placeholder, }: Props) => import("react/jsx-runtime").JSX.Element;
16
19
  export {};
@@ -4,14 +4,13 @@ import { LakeLabel } from "@swan-io/lake/src/components/LakeLabel";
4
4
  import { LakeTextInput } from "@swan-io/lake/src/components/LakeTextInput";
5
5
  import { LakeTooltip } from "@swan-io/lake/src/components/LakeTooltip";
6
6
  import { colors } from "@swan-io/lake/src/constants/design";
7
- import { forwardRef } from "react";
8
7
  import { t } from "../utils/i18n";
9
8
  import { getCompanyTaxNumberHelp, getCompanyTaxNumberPlaceholder, getIndividualTaxNumberHelp, getIndividualTaxNumberPlaceholder, getTaxNumberTooltip, } from "../utils/templateTranslations";
10
- export const TaxIdentificationNumberInput = forwardRef(({ value, error, valid, disabled, onChange, onBlur, accountCountry, isCompany, required, label = t("taxIdentificationNumber.label"), }, ref) => {
9
+ export const TaxIdentificationNumberInput = ({ ref, value, error, valid, disabled, onChange, onBlur, accountCountry, isCompany, required, label = t("taxIdentificationNumber.label"), placeholder = isCompany
10
+ ? getCompanyTaxNumberPlaceholder(accountCountry)
11
+ : getIndividualTaxNumberPlaceholder(accountCountry), }) => {
11
12
  const tooltipContents = getTaxNumberTooltip(accountCountry);
12
- return (_jsx(LakeLabel, { label: label, optionalLabel: required === true ? undefined : t("common.optional"), help: tooltipContents != null ? (_jsx(LakeTooltip, { content: tooltipContents, placement: "right", width: accountCountry === "DEU" ? 800 : undefined, children: _jsx(Icon, { name: "question-circle-regular", size: 16, color: colors.gray[600] }) })) : null, render: id => (_jsx(LakeTextInput, { id: id, ref: ref, placeholder: isCompany
13
- ? getCompanyTaxNumberPlaceholder(accountCountry)
14
- : getIndividualTaxNumberPlaceholder(accountCountry), help: isCompany
13
+ return (_jsx(LakeLabel, { label: label, optionalLabel: required === true ? undefined : t("common.optional"), help: tooltipContents != null ? (_jsx(LakeTooltip, { content: tooltipContents, placement: "right", width: accountCountry === "DEU" ? 800 : undefined, children: _jsx(Icon, { name: "question-circle-regular", size: 16, color: colors.gray[600] }) })) : null, render: id => (_jsx(LakeTextInput, { id: id, ref: ref, placeholder: placeholder, help: isCompany
15
14
  ? getCompanyTaxNumberHelp(accountCountry)
16
15
  : getIndividualTaxNumberHelp(accountCountry), value: value, error: error, valid: valid, disabled: disabled, onChangeText: onChange, onBlur: onBlur })) }));
17
- });
16
+ };
@@ -18,7 +18,7 @@ type Locale = {
18
18
  export declare const locale: Locale;
19
19
  export declare const t: (key: TranslationKey, params?: TranslationParams) => string;
20
20
  export declare const formatCurrencyIso: (value: number, currency: string) => string;
21
- export declare const formatNestedMessage: (key: TranslationKey, params: Record<string, string | number | ReactElement | ((children: ReactNode) => ReactNode)>) => (string | ReactElement<any, string | import("react").JSXElementConstructor<any>>)[];
21
+ export declare const formatNestedMessage: (key: TranslationKey, params: Record<string, string | number | ReactElement | ((children: ReactNode) => ReactNode)>) => (string | ReactElement<unknown, string | import("react").JSXElementConstructor<any>>)[];
22
22
  export declare const rifmDateProps: RifmProps;
23
23
  export declare const isTranslationKey: (value: unknown) => value is TranslationKey;
24
24
  export declare const translateError: (error: unknown) => string;