hvp-shared 2.0.0 → 2.0.1

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/README.md CHANGED
@@ -1,17 +1,17 @@
1
- # hvp2021-shared
1
+ # hvp-shared
2
2
 
3
- Shared types, constants, and utilities for HVP2021 backend and frontend.
3
+ Shared types, constants, and utilities for HVP backend and frontend.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install hvp2021-shared
8
+ npm install hvp-shared
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
13
  ```typescript
14
- import { ApiResponse, SimplePayroll, APP_NAME, UMA_2024_DAILY } from 'hvp2021-shared';
14
+ import { ApiResponse, SimplePayroll, APP_NAME, UMA_2024_DAILY } from 'hvp-shared';
15
15
 
16
16
  const response: ApiResponse<SimplePayroll> = {
17
17
  ok: true,
@@ -22,7 +22,7 @@ const response: ApiResponse<SimplePayroll> = {
22
22
  }
23
23
  };
24
24
 
25
- console.log(APP_NAME); // 'HVP2021'
25
+ console.log(APP_NAME); // 'HVP'
26
26
  ```
27
27
 
28
28
  ## Development
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hvp-shared",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Shared types and utilities for HVP backend and frontend",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const address_validation_1 = require("../address.validation");
4
- describe('validateAddress', () => {
5
- const validAddress = {
6
- street: 'Calle 10',
7
- exteriorNumber: '123',
8
- interiorNumber: 'A',
9
- neighborhood: 'Centro',
10
- city: 'Mérida',
11
- state: 'YUC',
12
- postalCode: '97000',
13
- country: 'México'
14
- };
15
- describe('valid addresses', () => {
16
- it('should accept valid complete address', () => {
17
- const result = (0, address_validation_1.validateAddress)(validAddress);
18
- expect(result.isValid).toBe(true);
19
- expect(result.error).toBeUndefined();
20
- });
21
- it('should accept address without interior number', () => {
22
- const { interiorNumber, ...addressWithoutInterior } = validAddress;
23
- const result = (0, address_validation_1.validateAddress)(addressWithoutInterior);
24
- expect(result.isValid).toBe(true);
25
- });
26
- it('should accept country "Mexico" without accent', () => {
27
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, country: 'Mexico' });
28
- expect(result.isValid).toBe(true);
29
- });
30
- it('should accept country in uppercase', () => {
31
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, country: 'MÉXICO' });
32
- expect(result.isValid).toBe(true);
33
- });
34
- it('should accept address with whitespace (trimmed)', () => {
35
- const result = (0, address_validation_1.validateAddress)({
36
- ...validAddress,
37
- street: ' Calle 10 ',
38
- city: ' Mérida '
39
- });
40
- expect(result.isValid).toBe(true);
41
- });
42
- });
43
- describe('required fields', () => {
44
- it('should reject missing street', () => {
45
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, street: '' });
46
- expect(result.isValid).toBe(false);
47
- expect(result.error).toBe('Calle es requerida');
48
- });
49
- it('should reject missing exterior number', () => {
50
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, exteriorNumber: '' });
51
- expect(result.isValid).toBe(false);
52
- expect(result.error).toBe('Número exterior es requerido');
53
- });
54
- it('should reject missing neighborhood', () => {
55
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, neighborhood: '' });
56
- expect(result.isValid).toBe(false);
57
- expect(result.error).toBe('Colonia es requerida');
58
- });
59
- it('should reject missing city', () => {
60
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, city: '' });
61
- expect(result.isValid).toBe(false);
62
- expect(result.error).toBe('Ciudad es requerida');
63
- });
64
- it('should reject missing postal code', () => {
65
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, postalCode: '' });
66
- expect(result.isValid).toBe(false);
67
- expect(result.error).toBe('Código postal es requerido');
68
- });
69
- it('should reject missing state', () => {
70
- const { state, ...addressWithoutState } = validAddress;
71
- const result = (0, address_validation_1.validateAddress)(addressWithoutState);
72
- expect(result.isValid).toBe(false);
73
- expect(result.error).toBe('Estado es requerido');
74
- });
75
- it('should reject missing country', () => {
76
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, country: '' });
77
- expect(result.isValid).toBe(false);
78
- expect(result.error).toBe('País es requerido');
79
- });
80
- });
81
- describe('postal code validation', () => {
82
- it('should reject postal code with less than 5 digits', () => {
83
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, postalCode: '9700' });
84
- expect(result.isValid).toBe(false);
85
- expect(result.error).toContain('5 dígitos');
86
- });
87
- it('should reject postal code with more than 5 digits', () => {
88
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, postalCode: '970001' });
89
- expect(result.isValid).toBe(false);
90
- expect(result.error).toContain('5 dígitos');
91
- });
92
- it('should reject postal code with letters', () => {
93
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, postalCode: '9700A' });
94
- expect(result.isValid).toBe(false);
95
- expect(result.error).toContain('5 dígitos');
96
- });
97
- });
98
- describe('state code validation', () => {
99
- it('should accept all valid Mexican state codes', () => {
100
- const validStates = [
101
- 'AGS', 'BC', 'BCS', 'CAMP', 'CHIS', 'CHIH', 'COAH', 'COL', 'CDMX',
102
- 'DGO', 'GTO', 'GRO', 'HGO', 'JAL', 'MEX', 'MICH', 'MOR', 'NAY',
103
- 'NL', 'OAX', 'PUE', 'QRO', 'QROO', 'SLP', 'SIN', 'SON', 'TAB',
104
- 'TAMPS', 'TLAX', 'VER', 'YUC', 'ZAC'
105
- ];
106
- validStates.forEach(state => {
107
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, state: state });
108
- expect(result.isValid).toBe(true);
109
- });
110
- });
111
- it('should reject invalid state code', () => {
112
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, state: 'INVALID' });
113
- expect(result.isValid).toBe(false);
114
- expect(result.error).toBe('Código de estado inválido');
115
- });
116
- });
117
- describe('country validation', () => {
118
- it('should reject non-Mexican country', () => {
119
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, country: 'USA' });
120
- expect(result.isValid).toBe(false);
121
- expect(result.error).toContain('México');
122
- });
123
- it('should reject other countries', () => {
124
- const result = (0, address_validation_1.validateAddress)({ ...validAddress, country: 'Canada' });
125
- expect(result.isValid).toBe(false);
126
- expect(result.error).toContain('México');
127
- });
128
- });
129
- });
130
- describe('POSTAL_CODE_PATTERN', () => {
131
- it('should match valid 5-digit postal code', () => {
132
- expect(address_validation_1.POSTAL_CODE_PATTERN.test('97000')).toBe(true);
133
- });
134
- it('should match postal code starting with 0', () => {
135
- expect(address_validation_1.POSTAL_CODE_PATTERN.test('01000')).toBe(true);
136
- });
137
- it('should not match 4-digit code', () => {
138
- expect(address_validation_1.POSTAL_CODE_PATTERN.test('9700')).toBe(false);
139
- });
140
- it('should not match 6-digit code', () => {
141
- expect(address_validation_1.POSTAL_CODE_PATTERN.test('970001')).toBe(false);
142
- });
143
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,102 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const email_validation_1 = require("../email.validation");
4
- describe('validateEmail', () => {
5
- describe('valid emails', () => {
6
- it('should accept valid email', () => {
7
- const result = (0, email_validation_1.validateEmail)('test@example.com');
8
- expect(result.isValid).toBe(true);
9
- expect(result.error).toBeUndefined();
10
- });
11
- it('should accept email with subdomain', () => {
12
- const result = (0, email_validation_1.validateEmail)('test@mail.example.com');
13
- expect(result.isValid).toBe(true);
14
- });
15
- it('should accept email with numbers', () => {
16
- const result = (0, email_validation_1.validateEmail)('test123@example.com');
17
- expect(result.isValid).toBe(true);
18
- });
19
- it('should accept email with dots in local part', () => {
20
- const result = (0, email_validation_1.validateEmail)('test.user@example.com');
21
- expect(result.isValid).toBe(true);
22
- });
23
- it('should accept email with plus sign', () => {
24
- const result = (0, email_validation_1.validateEmail)('test+tag@example.com');
25
- expect(result.isValid).toBe(true);
26
- });
27
- it('should accept uppercase email (normalized)', () => {
28
- const result = (0, email_validation_1.validateEmail)('TEST@EXAMPLE.COM');
29
- expect(result.isValid).toBe(true);
30
- });
31
- it('should accept email with whitespace (trimmed)', () => {
32
- const result = (0, email_validation_1.validateEmail)(' test@example.com ');
33
- expect(result.isValid).toBe(true);
34
- });
35
- });
36
- describe('invalid emails', () => {
37
- it('should reject empty string', () => {
38
- const result = (0, email_validation_1.validateEmail)('');
39
- expect(result.isValid).toBe(false);
40
- expect(result.error).toBe('Email es requerido');
41
- });
42
- it('should reject null', () => {
43
- const result = (0, email_validation_1.validateEmail)(null);
44
- expect(result.isValid).toBe(false);
45
- expect(result.error).toBe('Email es requerido');
46
- });
47
- it('should reject undefined', () => {
48
- const result = (0, email_validation_1.validateEmail)(undefined);
49
- expect(result.isValid).toBe(false);
50
- expect(result.error).toBe('Email es requerido');
51
- });
52
- it('should reject whitespace only', () => {
53
- const result = (0, email_validation_1.validateEmail)(' ');
54
- expect(result.isValid).toBe(false);
55
- expect(result.error).toBe('Email es requerido');
56
- });
57
- it('should reject email without @', () => {
58
- const result = (0, email_validation_1.validateEmail)('testexample.com');
59
- expect(result.isValid).toBe(false);
60
- expect(result.error).toBe('Email inválido');
61
- });
62
- it('should reject email without domain', () => {
63
- const result = (0, email_validation_1.validateEmail)('test@');
64
- expect(result.isValid).toBe(false);
65
- expect(result.error).toBe('Email inválido');
66
- });
67
- it('should reject email without local part', () => {
68
- const result = (0, email_validation_1.validateEmail)('@example.com');
69
- expect(result.isValid).toBe(false);
70
- expect(result.error).toBe('Email inválido');
71
- });
72
- it('should reject email without TLD', () => {
73
- const result = (0, email_validation_1.validateEmail)('test@example');
74
- expect(result.isValid).toBe(false);
75
- expect(result.error).toBe('Email inválido');
76
- });
77
- it('should reject email with spaces', () => {
78
- const result = (0, email_validation_1.validateEmail)('test @example.com');
79
- expect(result.isValid).toBe(false);
80
- expect(result.error).toBe('Email inválido');
81
- });
82
- });
83
- });
84
- describe('normalizeEmail', () => {
85
- it('should convert to lowercase', () => {
86
- expect((0, email_validation_1.normalizeEmail)('TEST@EXAMPLE.COM')).toBe('test@example.com');
87
- });
88
- it('should trim whitespace', () => {
89
- expect((0, email_validation_1.normalizeEmail)(' test@example.com ')).toBe('test@example.com');
90
- });
91
- it('should handle mixed case', () => {
92
- expect((0, email_validation_1.normalizeEmail)('Test@Example.Com')).toBe('test@example.com');
93
- });
94
- });
95
- describe('EMAIL_PATTERN', () => {
96
- it('should match valid email', () => {
97
- expect(email_validation_1.EMAIL_PATTERN.test('test@example.com')).toBe(true);
98
- });
99
- it('should not match invalid email', () => {
100
- expect(email_validation_1.EMAIL_PATTERN.test('invalid')).toBe(false);
101
- });
102
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const phone_validation_1 = require("../phone.validation");
4
- describe('validatePhone', () => {
5
- describe('valid phones', () => {
6
- it('should accept valid 10-digit phone', () => {
7
- const result = (0, phone_validation_1.validatePhone)('9991234567');
8
- expect(result.isValid).toBe(true);
9
- expect(result.error).toBeUndefined();
10
- });
11
- it('should accept phone with whitespace (trimmed)', () => {
12
- const result = (0, phone_validation_1.validatePhone)(' 9991234567 ');
13
- expect(result.isValid).toBe(true);
14
- });
15
- it('should accept undefined (phone is optional)', () => {
16
- const result = (0, phone_validation_1.validatePhone)(undefined);
17
- expect(result.isValid).toBe(true);
18
- });
19
- it('should accept null (phone is optional)', () => {
20
- const result = (0, phone_validation_1.validatePhone)(null);
21
- expect(result.isValid).toBe(true);
22
- });
23
- it('should accept empty string (phone is optional)', () => {
24
- const result = (0, phone_validation_1.validatePhone)('');
25
- expect(result.isValid).toBe(true);
26
- });
27
- it('should accept whitespace only (phone is optional)', () => {
28
- const result = (0, phone_validation_1.validatePhone)(' ');
29
- expect(result.isValid).toBe(true);
30
- });
31
- });
32
- describe('invalid phones', () => {
33
- it('should reject phone with less than 10 digits', () => {
34
- const result = (0, phone_validation_1.validatePhone)('999123456');
35
- expect(result.isValid).toBe(false);
36
- expect(result.error).toContain('10 dígitos');
37
- });
38
- it('should reject phone with more than 10 digits', () => {
39
- const result = (0, phone_validation_1.validatePhone)('99912345678');
40
- expect(result.isValid).toBe(false);
41
- expect(result.error).toContain('10 dígitos');
42
- });
43
- it('should reject phone with letters', () => {
44
- const result = (0, phone_validation_1.validatePhone)('999123456a');
45
- expect(result.isValid).toBe(false);
46
- expect(result.error).toContain('10 dígitos');
47
- });
48
- it('should reject phone with special characters', () => {
49
- const result = (0, phone_validation_1.validatePhone)('999-123-4567');
50
- expect(result.isValid).toBe(false);
51
- expect(result.error).toContain('10 dígitos');
52
- });
53
- it('should reject phone with spaces inside', () => {
54
- const result = (0, phone_validation_1.validatePhone)('999 123 4567');
55
- expect(result.isValid).toBe(false);
56
- expect(result.error).toContain('10 dígitos');
57
- });
58
- it('should reject phone with parentheses', () => {
59
- const result = (0, phone_validation_1.validatePhone)('(999)1234567');
60
- expect(result.isValid).toBe(false);
61
- expect(result.error).toContain('10 dígitos');
62
- });
63
- });
64
- });
65
- describe('PHONE_PATTERN', () => {
66
- it('should match valid 10-digit phone', () => {
67
- expect(phone_validation_1.PHONE_PATTERN.test('9991234567')).toBe(true);
68
- });
69
- it('should not match invalid phone', () => {
70
- expect(phone_validation_1.PHONE_PATTERN.test('999-123-4567')).toBe(false);
71
- });
72
- it('should not match phone with less than 10 digits', () => {
73
- expect(phone_validation_1.PHONE_PATTERN.test('999123456')).toBe(false);
74
- });
75
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const rfc_validation_1 = require("../rfc.validation");
4
- describe('validateRFC', () => {
5
- describe('valid RFCs', () => {
6
- it('should accept valid RFC persona moral (12 chars)', () => {
7
- const result = (0, rfc_validation_1.validateRFC)('HVP850101AB1');
8
- expect(result.isValid).toBe(true);
9
- expect(result.error).toBeUndefined();
10
- });
11
- it('should accept valid RFC persona física (13 chars)', () => {
12
- const result = (0, rfc_validation_1.validateRFC)('GARC850101AB1');
13
- expect(result.isValid).toBe(true);
14
- expect(result.error).toBeUndefined();
15
- });
16
- it('should accept RFC with Ñ', () => {
17
- const result = (0, rfc_validation_1.validateRFC)('MÑO850101AB1');
18
- expect(result.isValid).toBe(true);
19
- });
20
- it('should accept RFC with &', () => {
21
- const result = (0, rfc_validation_1.validateRFC)('M&O850101AB1');
22
- expect(result.isValid).toBe(true);
23
- });
24
- it('should accept lowercase RFC (normalized)', () => {
25
- const result = (0, rfc_validation_1.validateRFC)('hvp850101ab1');
26
- expect(result.isValid).toBe(true);
27
- });
28
- it('should accept RFC with whitespace (trimmed)', () => {
29
- const result = (0, rfc_validation_1.validateRFC)(' HVP850101AB1 ');
30
- expect(result.isValid).toBe(true);
31
- });
32
- });
33
- describe('invalid RFCs', () => {
34
- it('should reject empty string', () => {
35
- const result = (0, rfc_validation_1.validateRFC)('');
36
- expect(result.isValid).toBe(false);
37
- expect(result.error).toBe('RFC es requerido');
38
- });
39
- it('should reject null', () => {
40
- const result = (0, rfc_validation_1.validateRFC)(null);
41
- expect(result.isValid).toBe(false);
42
- expect(result.error).toBe('RFC es requerido');
43
- });
44
- it('should reject undefined', () => {
45
- const result = (0, rfc_validation_1.validateRFC)(undefined);
46
- expect(result.isValid).toBe(false);
47
- expect(result.error).toBe('RFC es requerido');
48
- });
49
- it('should reject whitespace only', () => {
50
- const result = (0, rfc_validation_1.validateRFC)(' ');
51
- expect(result.isValid).toBe(false);
52
- expect(result.error).toBe('RFC es requerido');
53
- });
54
- it('should reject RFC too short', () => {
55
- const result = (0, rfc_validation_1.validateRFC)('HVP850101');
56
- expect(result.isValid).toBe(false);
57
- expect(result.error).toContain('RFC inválido');
58
- });
59
- it('should reject RFC too long', () => {
60
- const result = (0, rfc_validation_1.validateRFC)('GARC850101AB1X');
61
- expect(result.isValid).toBe(false);
62
- expect(result.error).toContain('RFC inválido');
63
- });
64
- it('should reject RFC with invalid characters', () => {
65
- const result = (0, rfc_validation_1.validateRFC)('HVP-850101AB1');
66
- expect(result.isValid).toBe(false);
67
- expect(result.error).toContain('RFC inválido');
68
- });
69
- it('should reject RFC with wrong format', () => {
70
- const result = (0, rfc_validation_1.validateRFC)('123456789012');
71
- expect(result.isValid).toBe(false);
72
- expect(result.error).toContain('RFC inválido');
73
- });
74
- });
75
- });
76
- describe('normalizeRFC', () => {
77
- it('should convert to uppercase', () => {
78
- expect((0, rfc_validation_1.normalizeRFC)('hvp850101ab1')).toBe('HVP850101AB1');
79
- });
80
- it('should trim whitespace', () => {
81
- expect((0, rfc_validation_1.normalizeRFC)(' HVP850101AB1 ')).toBe('HVP850101AB1');
82
- });
83
- it('should handle mixed case', () => {
84
- expect((0, rfc_validation_1.normalizeRFC)('HvP850101Ab1')).toBe('HVP850101AB1');
85
- });
86
- });
87
- describe('RFC_PATTERN', () => {
88
- it('should match valid RFC persona moral', () => {
89
- expect(rfc_validation_1.RFC_PATTERN.test('HVP850101AB1')).toBe(true);
90
- });
91
- it('should match valid RFC persona física', () => {
92
- expect(rfc_validation_1.RFC_PATTERN.test('GARC850101AB1')).toBe(true);
93
- });
94
- it('should not match invalid RFC', () => {
95
- expect(rfc_validation_1.RFC_PATTERN.test('INVALID')).toBe(false);
96
- });
97
- });