@greatapps/common 1.1.806 → 1.1.807
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/dist/components/account/sections/affiliates/ReceivingAccountModal.mjs +52 -18
- package/dist/components/account/sections/affiliates/ReceivingAccountModal.mjs.map +1 -1
- package/dist/i18n/messages/en-us.mjs +5 -0
- package/dist/i18n/messages/en-us.mjs.map +1 -1
- package/dist/i18n/messages/es-es.mjs +5 -0
- package/dist/i18n/messages/es-es.mjs.map +1 -1
- package/dist/i18n/messages/pt-br.mjs +5 -0
- package/dist/i18n/messages/pt-br.mjs.map +1 -1
- package/dist/index.mjs +6 -1
- package/dist/index.mjs.map +1 -1
- package/dist/testing/factories/affiliate.factory.mjs +24 -0
- package/dist/testing/factories/affiliate.factory.mjs.map +1 -0
- package/dist/testing/factories/index.mjs +2 -0
- package/dist/testing/factories/index.mjs.map +1 -1
- package/dist/utils/format/masks.mjs +6 -1
- package/dist/utils/format/masks.mjs.map +1 -1
- package/dist/utils/validators/pix-key.mjs +27 -0
- package/dist/utils/validators/pix-key.mjs.map +1 -0
- package/package.json +10 -9
- package/src/components/account/sections/affiliates/ReceivingAccountModal.tsx +71 -20
- package/src/i18n/messages/en-us.ts +6 -0
- package/src/i18n/messages/es-es.ts +6 -0
- package/src/i18n/messages/pt-br.ts +6 -0
- package/src/index.ts +2 -0
- package/src/testing/factories/affiliate.factory.ts +22 -0
- package/src/testing/factories/index.ts +1 -0
- package/src/utils/format/masks.ts +6 -2
- package/src/utils/validators/pix-key.ts +25 -0
package/src/index.ts
CHANGED
|
@@ -559,7 +559,9 @@ export {
|
|
|
559
559
|
formatCPF,
|
|
560
560
|
formatCNPJ,
|
|
561
561
|
formatCardNumber,
|
|
562
|
+
formatPixKey,
|
|
562
563
|
} from "./utils/format/masks";
|
|
564
|
+
export { AMBIGUOUS_PIX_KEY, normalizePixKeyForStorage } from "./utils/validators/pix-key";
|
|
563
565
|
export {
|
|
564
566
|
formatCurrency,
|
|
565
567
|
formatCurrencyNumber,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { faker } from '@faker-js/faker';
|
|
2
|
+
import type { Affiliate } from '../../modules/affiliates/types/affiliate.type';
|
|
3
|
+
import { TEST_IDS } from '../constants';
|
|
4
|
+
import { createMock } from './create-mock';
|
|
5
|
+
|
|
6
|
+
export const createAffiliateMock = createMock<Affiliate, Partial<Affiliate>>((overrides) => ({
|
|
7
|
+
id: overrides?.id ?? 1,
|
|
8
|
+
id_wl: overrides?.id_wl ?? TEST_IDS.wl,
|
|
9
|
+
id_account: overrides?.id_account ?? TEST_IDS.account,
|
|
10
|
+
active: overrides?.active ?? true,
|
|
11
|
+
deleted: overrides?.deleted ?? false,
|
|
12
|
+
balance: overrides?.balance ?? 0,
|
|
13
|
+
datetime_add: overrides?.datetime_add ?? null,
|
|
14
|
+
datetime_alt: overrides?.datetime_alt ?? null,
|
|
15
|
+
datetime_del: overrides?.datetime_del ?? null,
|
|
16
|
+
holder_name: overrides?.holder_name || faker.person.fullName(),
|
|
17
|
+
pix: overrides?.pix ?? null,
|
|
18
|
+
holder_document: overrides?.holder_document ?? null,
|
|
19
|
+
bank: overrides?.bank ?? null,
|
|
20
|
+
agency: overrides?.agency ?? null,
|
|
21
|
+
account: overrides?.account ?? null,
|
|
22
|
+
}));
|
|
@@ -8,3 +8,4 @@ export { createPlanMock, createPlanItemMock } from './plan.factory';
|
|
|
8
8
|
export { createProjectMock } from './project.factory';
|
|
9
9
|
export { createProjectUserMock } from './project-user.factory';
|
|
10
10
|
export { createCouponMock } from './coupon.factory';
|
|
11
|
+
export { createAffiliateMock } from './affiliate.factory';
|
|
@@ -92,8 +92,12 @@ function formatIfCpfCnpjShaped(value: string): string {
|
|
|
92
92
|
/** Documento do titular: CPF/CNPJ mascarado; qualquer outro conteúdo volta intacto. */
|
|
93
93
|
export const formatDocument = formatIfCpfCnpjShaped;
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
export function formatPixKey(value: string): string {
|
|
96
|
+
if (/^\+55\d{11}$/.test(value)) return `+55 ${formatPhone(value.slice(3))}`;
|
|
97
|
+
if (/^\d{11}$/.test(value)) return formatCPF(value);
|
|
98
|
+
if (/^\d{14}$/.test(value)) return formatCNPJ(value);
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
97
101
|
|
|
98
102
|
/** Tira a máscara antes de gravar; valor que não é CPF/CNPJ volta como veio. */
|
|
99
103
|
export function normalizeCpfCnpjForStorage(value: string): string {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isValidCNPJ, isValidCPF, isValidEmail } from './common';
|
|
2
|
+
|
|
3
|
+
const RANDOM_KEY = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
4
|
+
const PIX_KEY_CHARS = /^[\d ().\/+-]+$/;
|
|
5
|
+
const MOBILE_WITH_COUNTRY_CODE = /^55[1-9]{2}9\d{8}$/;
|
|
6
|
+
const MOBILE = /^[1-9]{2}9\d{8}$/;
|
|
7
|
+
|
|
8
|
+
export const AMBIGUOUS_PIX_KEY = Symbol('ambiguous-pix-key');
|
|
9
|
+
|
|
10
|
+
export function normalizePixKeyForStorage(value: string, holderDocument: string): string | typeof AMBIGUOUS_PIX_KEY | null {
|
|
11
|
+
const key = value.trim();
|
|
12
|
+
if (isValidEmail(key) || RANDOM_KEY.test(key)) return key;
|
|
13
|
+
if (!PIX_KEY_CHARS.test(key)) return null;
|
|
14
|
+
const digits = key.replace(/\D/g, '');
|
|
15
|
+
if (key.startsWith('+')) return MOBILE_WITH_COUNTRY_CODE.test(digits) ? `+${digits}` : null;
|
|
16
|
+
if (digits.length === 14) return isValidCNPJ(digits) ? digits : null;
|
|
17
|
+
if (digits.length === 13) return MOBILE_WITH_COUNTRY_CODE.test(digits) ? `+${digits}` : null;
|
|
18
|
+
if (digits.length !== 11) return null;
|
|
19
|
+
if (digits === holderDocument.replace(/\D/g, '')) return digits;
|
|
20
|
+
const isMobile = MOBILE.test(digits);
|
|
21
|
+
const isCpf = isValidCPF(digits);
|
|
22
|
+
if (isMobile && isCpf) return AMBIGUOUS_PIX_KEY;
|
|
23
|
+
if (isMobile) return `+55${digits}`;
|
|
24
|
+
return isCpf ? digits : null;
|
|
25
|
+
}
|