@arkyn/server 3.0.1-beta.142 → 3.0.1-beta.144
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/bundle.js +90 -323
- package/dist/http/badResponses/badGateway.d.ts +12 -19
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +12 -19
- package/dist/http/badResponses/badRequest.d.ts +10 -19
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +10 -19
- package/dist/http/badResponses/conflict.d.ts +10 -19
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +10 -19
- package/dist/http/badResponses/forbidden.d.ts +10 -19
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +10 -19
- package/dist/http/badResponses/notFound.d.ts +10 -19
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +10 -19
- package/dist/http/badResponses/notImplemented.d.ts +10 -19
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +10 -19
- package/dist/http/badResponses/serverError.d.ts +10 -19
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +10 -19
- package/dist/http/badResponses/unauthorized.d.ts +10 -19
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +10 -19
- package/dist/http/badResponses/unprocessableEntity.d.ts +17 -22
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +17 -22
- package/dist/http/successResponses/created.d.ts +10 -14
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +10 -14
- package/dist/http/successResponses/found.d.ts +10 -14
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +10 -14
- package/dist/http/successResponses/noContent.d.ts +9 -7
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.js +9 -7
- package/dist/http/successResponses/success.d.ts +10 -14
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +10 -14
- package/dist/http/successResponses/updated.d.ts +11 -14
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +11 -14
- package/dist/services/apiService.d.ts +20 -0
- package/dist/services/apiService.d.ts.map +1 -1
- package/dist/services/apiService.js +16 -0
- package/dist/services/debugService.d.ts +10 -42
- package/dist/services/debugService.d.ts.map +1 -1
- package/dist/services/debugService.js +10 -42
- package/dist/services/logService.d.ts +5 -10
- package/dist/services/logService.d.ts.map +1 -1
- package/dist/services/logService.js +5 -10
- package/dist/utilities/decodeRequestBody.d.ts +11 -9
- package/dist/utilities/decodeRequestBody.d.ts.map +1 -1
- package/dist/utilities/decodeRequestBody.js +11 -9
- package/dist/utilities/decodeRequestErrorMessage.d.ts +12 -10
- package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -1
- package/dist/utilities/decodeRequestErrorMessage.js +12 -10
- package/dist/utilities/errorHandler.d.ts +13 -38
- package/dist/utilities/errorHandler.d.ts.map +1 -1
- package/dist/utilities/errorHandler.js +13 -38
- package/dist/utilities/flushDebugLogs.d.ts +6 -28
- package/dist/utilities/flushDebugLogs.d.ts.map +1 -1
- package/dist/utilities/flushDebugLogs.js +6 -28
- package/dist/utilities/formAsyncParse.d.ts +7 -28
- package/dist/utilities/formAsyncParse.d.ts.map +1 -1
- package/dist/utilities/formAsyncParse.js +7 -28
- package/dist/utilities/formParse.d.ts +7 -28
- package/dist/utilities/formParse.d.ts.map +1 -1
- package/dist/utilities/formParse.js +7 -28
- package/dist/utilities/getScopedParams.d.ts +11 -19
- package/dist/utilities/getScopedParams.d.ts.map +1 -1
- package/dist/utilities/getScopedParams.js +11 -19
- package/dist/utilities/schemaValidator.d.ts +31 -102
- package/dist/utilities/schemaValidator.d.ts.map +1 -1
- package/dist/utilities/schemaValidator.js +31 -102
- package/dist/validations/validateCep.d.ts +2 -2
- package/dist/validations/validateCep.js +2 -2
- package/dist/validations/validateCnpj.d.ts +2 -2
- package/dist/validations/validateCnpj.js +2 -2
- package/dist/validations/validateCpf.d.ts +4 -11
- package/dist/validations/validateCpf.d.ts.map +1 -1
- package/dist/validations/validateCpf.js +4 -11
- package/dist/validations/validateDate.d.ts +7 -11
- package/dist/validations/validateDate.d.ts.map +1 -1
- package/dist/validations/validateDate.js +7 -11
- package/dist/validations/validateEmail.d.ts +2 -2
- package/dist/validations/validateEmail.js +2 -2
- package/dist/validations/validatePassword.d.ts +2 -2
- package/dist/validations/validatePassword.js +2 -2
- package/dist/validations/validatePhone.d.ts +6 -18
- package/dist/validations/validatePhone.d.ts.map +1 -1
- package/dist/validations/validatePhone.js +6 -18
- package/dist/validations/validateRg.d.ts +2 -2
- package/dist/validations/validateRg.js +2 -2
- package/package.json +1 -1
|
@@ -8,103 +8,51 @@ function formatErrorMessage(error) {
|
|
|
8
8
|
return [title, ...lines].join("\n");
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Wraps a Zod schema with convenience validation methods suited for server-side use:
|
|
12
|
+
* - `isValid` — boolean check, no throws
|
|
13
|
+
* - `safeValidate` — raw Zod result, no throws
|
|
14
|
+
* - `validate` — throws `ServerError` on failure (for trusted/internal data)
|
|
15
|
+
* - `formValidate` / `formAsyncValidate` — throws `UnprocessableEntity` on failure (for user-submitted forms)
|
|
12
16
|
*
|
|
13
17
|
* @example
|
|
14
18
|
* ```typescript
|
|
15
|
-
*
|
|
19
|
+
* const validator = new SchemaValidator(z.object({ email: z.string().email() }));
|
|
16
20
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* email: z.string().email("Invalid email"),
|
|
20
|
-
* age: z.number().min(18, "Must be at least 18")
|
|
21
|
-
* });
|
|
22
|
-
*
|
|
23
|
-
* const validator = new SchemaValidator(userSchema);
|
|
24
|
-
*
|
|
25
|
-
* // Check if data is valid without throwing
|
|
26
|
-
* const isValid = validator.isValid({ name: "John", email: "john@example.com", age: 25 });
|
|
27
|
-
*
|
|
28
|
-
* // Validate and throw ServerError on failure
|
|
29
|
-
* try {
|
|
30
|
-
* const validData = validator.validate({ name: "John", email: "john@example.com", age: 25 });
|
|
31
|
-
* } catch (error) {
|
|
32
|
-
* console.error(error.message);
|
|
33
|
-
* }
|
|
34
|
-
*
|
|
35
|
-
* // Form validation with UnprocessableEntity error
|
|
36
|
-
* try {
|
|
37
|
-
* const formData = validator.formValidate(requestBody);
|
|
38
|
-
* } catch (error) {
|
|
39
|
-
* // Returns structured error with fieldErrors for forms
|
|
40
|
-
* }
|
|
21
|
+
* // Inside a Remix action:
|
|
22
|
+
* const body = validator.formValidate(await decodeRequestBody(request));
|
|
41
23
|
* ```
|
|
42
24
|
*/
|
|
43
25
|
class SchemaValidator {
|
|
44
26
|
schema;
|
|
45
27
|
/**
|
|
46
|
-
*
|
|
47
|
-
* @param {T} schema - The Zod schema to use for validation.
|
|
28
|
+
* @param schema - The Zod schema used for all validation methods on this instance.
|
|
48
29
|
*/
|
|
49
30
|
constructor(schema) {
|
|
50
31
|
this.schema = schema;
|
|
51
32
|
}
|
|
52
33
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @param {any} data - The data to validate.
|
|
56
|
-
*
|
|
57
|
-
* @returns {boolean} True if the data is valid, false otherwise.
|
|
34
|
+
* Returns `true` if the data satisfies the schema, `false` otherwise. Never throws.
|
|
58
35
|
*
|
|
59
|
-
* @
|
|
60
|
-
* ```typescript
|
|
61
|
-
* const validator = new SchemaValidator(userSchema);
|
|
62
|
-
* const isValid = validator.isValid({ name: "John", email: "invalid-email" });
|
|
63
|
-
* console.log(isValid); // false
|
|
64
|
-
* ```
|
|
36
|
+
* @param data - The value to check.
|
|
65
37
|
*/
|
|
66
38
|
isValid(data) {
|
|
67
39
|
return this.schema.safeParse(data).success;
|
|
68
40
|
}
|
|
69
41
|
/**
|
|
70
|
-
*
|
|
42
|
+
* Validates data and returns the raw Zod `safeParseResult` without throwing.
|
|
43
|
+
* Useful when you need access to the full error details.
|
|
71
44
|
*
|
|
72
|
-
* @param
|
|
73
|
-
* @returns {z.ZodSafeParseResult<z.infer<T>>} The Zod safe parse result containing success status and data or error.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```typescript
|
|
77
|
-
* const validator = new SchemaValidator(userSchema);
|
|
78
|
-
* const result = validator.safeValidate({ name: "", email: "john@example.com" });
|
|
79
|
-
*
|
|
80
|
-
* if (result.success) {
|
|
81
|
-
* console.log(result.data); // Validated data
|
|
82
|
-
* } else {
|
|
83
|
-
* console.log(result.error.issues); // Validation errors
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
45
|
+
* @param data - The value to validate.
|
|
86
46
|
*/
|
|
87
47
|
safeValidate(data) {
|
|
88
48
|
return this.schema.safeParse(data);
|
|
89
49
|
}
|
|
90
50
|
/**
|
|
91
|
-
* Validates data and returns the
|
|
92
|
-
*
|
|
93
|
-
* @param {any} data - The data to validate.
|
|
94
|
-
* @throws {ServerError} When validation fails, with a formatted error message.
|
|
95
|
-
* @returns {z.infer<T>} The validated and parsed data.
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```typescript
|
|
99
|
-
* const validator = new SchemaValidator(userSchema);
|
|
51
|
+
* Validates data and returns the typed result, throwing `ServerError` on failure.
|
|
52
|
+
* Use for validating internal/trusted data (e.g. env vars, config objects).
|
|
100
53
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* console.log(validUser); // { name: "John", email: "john@example.com", age: 25 }
|
|
104
|
-
* } catch (error) {
|
|
105
|
-
* console.error(error.message); // "Error validating:\n-> name: String must contain at least 1 character(s)"
|
|
106
|
-
* }
|
|
107
|
-
* ```
|
|
54
|
+
* @param data - The value to validate.
|
|
55
|
+
* @throws `ServerError` with a formatted field-by-field error message.
|
|
108
56
|
*/
|
|
109
57
|
validate(data) {
|
|
110
58
|
try {
|
|
@@ -115,26 +63,17 @@ class SchemaValidator {
|
|
|
115
63
|
}
|
|
116
64
|
}
|
|
117
65
|
/**
|
|
118
|
-
* Validates form data and returns the
|
|
119
|
-
*
|
|
66
|
+
* Validates form data and returns the typed result, throwing `UnprocessableEntity` on failure.
|
|
67
|
+
* The error includes `fieldErrors`, `fields`, and `data.scrollTo` (first failing field name).
|
|
120
68
|
*
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
123
|
-
* @throws
|
|
124
|
-
* @returns {z.infer<T>} The validated and parsed form data.
|
|
69
|
+
* @param data - The raw form data to validate.
|
|
70
|
+
* @param message - Optional human-readable error message for the 422 response.
|
|
71
|
+
* @throws `UnprocessableEntity` with structured field errors for client-side form handling.
|
|
125
72
|
*
|
|
126
73
|
* @example
|
|
127
74
|
* ```typescript
|
|
128
|
-
* const validator = new SchemaValidator(
|
|
129
|
-
*
|
|
130
|
-
* try {
|
|
131
|
-
* const validFormData = validator.formValidate(requestBody, "User data is invalid");
|
|
132
|
-
* console.log(validFormData);
|
|
133
|
-
* } catch (error) {
|
|
134
|
-
* // UnprocessableEntity with fieldErrors, fields, and scrollTo data
|
|
135
|
-
* console.log(error.fieldErrors); // { name: "Name is required", email: "Invalid email" }
|
|
136
|
-
* console.log(error.data.scrollTo); // "name" (first error field)
|
|
137
|
-
* }
|
|
75
|
+
* const validator = new SchemaValidator(registerSchema);
|
|
76
|
+
* const body = validator.formValidate(await decodeRequestBody(request));
|
|
138
77
|
* ```
|
|
139
78
|
*/
|
|
140
79
|
formValidate(data, message) {
|
|
@@ -151,26 +90,16 @@ class SchemaValidator {
|
|
|
151
90
|
return formParsed.data;
|
|
152
91
|
}
|
|
153
92
|
/**
|
|
154
|
-
*
|
|
155
|
-
* This method is the async version of formValidate, designed for form validation with async schemas.
|
|
93
|
+
* Async version of `formValidate` for schemas with async refinements (e.g. uniqueness checks).
|
|
156
94
|
*
|
|
157
|
-
* @param
|
|
158
|
-
* @param
|
|
159
|
-
* @throws
|
|
160
|
-
* @returns {Promise<z.infer<T>>} A promise that resolves to the validated and parsed form data.
|
|
95
|
+
* @param data - The raw form data to validate.
|
|
96
|
+
* @param message - Optional human-readable error message for the 422 response.
|
|
97
|
+
* @throws `UnprocessableEntity` with structured field errors for client-side form handling.
|
|
161
98
|
*
|
|
162
99
|
* @example
|
|
163
100
|
* ```typescript
|
|
164
|
-
* const validator = new SchemaValidator(
|
|
165
|
-
*
|
|
166
|
-
* try {
|
|
167
|
-
* const validFormData = await validator.formAsyncValidate(requestBody, "User data is invalid");
|
|
168
|
-
* console.log(validFormData);
|
|
169
|
-
* } catch (error) {
|
|
170
|
-
* // UnprocessableEntity with fieldErrors, fields, and scrollTo data
|
|
171
|
-
* console.log(error.fieldErrors); // { name: "Name is required", email: "Invalid email" }
|
|
172
|
-
* console.log(error.data.scrollTo); // "name" (first error field)
|
|
173
|
-
* }
|
|
101
|
+
* const validator = new SchemaValidator(registerSchema);
|
|
102
|
+
* const body = await validator.formAsyncValidate(await decodeRequestBody(request));
|
|
174
103
|
* ```
|
|
175
104
|
*/
|
|
176
105
|
async formAsyncValidate(data, message) {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* A valid CEP must contain exactly 8 numeric digits,
|
|
5
5
|
* optionally formatted as "12345-678".
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
8
|
-
* @returns
|
|
7
|
+
* @param rawCep - CEP value, with or without formatting.
|
|
8
|
+
* @returns `true` if the CEP is valid, otherwise `false`.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
@@ -5,8 +5,8 @@ import { removeNonNumeric } from "@arkyn/shared";
|
|
|
5
5
|
* A valid CEP must contain exactly 8 numeric digits,
|
|
6
6
|
* optionally formatted as "12345-678".
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
9
|
-
* @returns
|
|
8
|
+
* @param rawCep - CEP value, with or without formatting.
|
|
9
|
+
* @returns `true` if the CEP is valid, otherwise `false`.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```typescript
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* - Repeating digits check (invalid if all digits are the same).
|
|
8
8
|
* - Verifies the two check digits with the proper weights.
|
|
9
9
|
*
|
|
10
|
-
* @param
|
|
11
|
-
* @returns
|
|
10
|
+
* @param rawCnpj - CNPJ string, possibly formatted.
|
|
11
|
+
* @returns `true` if valid, otherwise `false`.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```typescript
|
|
@@ -27,8 +27,8 @@ function extractDigit(cnpj) {
|
|
|
27
27
|
* - Repeating digits check (invalid if all digits are the same).
|
|
28
28
|
* - Verifies the two check digits with the proper weights.
|
|
29
29
|
*
|
|
30
|
-
* @param
|
|
31
|
-
* @returns
|
|
30
|
+
* @param rawCnpj - CNPJ string, possibly formatted.
|
|
31
|
+
* @returns `true` if valid, otherwise `false`.
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
34
|
* ```typescript
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Validates a Brazilian CPF
|
|
2
|
+
* Validates a Brazilian CPF number. Strips formatting, checks length, rejects
|
|
3
|
+
* repeated-digit sequences, and verifies both check digits with the CPF algorithm.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* - Removes any non-digit characters from the input.
|
|
7
|
-
* - Verifies if the CPF has the correct length (11 digits).
|
|
8
|
-
* - Ensures that all digits are not the same (e.g., "111.111.111-11" is invalid).
|
|
9
|
-
* - Calculates the first and second verification digits using the CPF algorithm.
|
|
10
|
-
* - Compares the calculated verification digits with the ones provided in the CPF.
|
|
11
|
-
*
|
|
12
|
-
* @param {string} rawCpf - The raw CPF string, which may include formatting characters (e.g., dots or dashes).
|
|
13
|
-
* @returns {boolean} `true` if the CPF is valid, otherwise `false`.
|
|
5
|
+
* @param rawCpf - CPF string, with or without formatting (dots and dashes).
|
|
6
|
+
* @returns `true` if the CPF is valid, otherwise `false`.
|
|
14
7
|
*
|
|
15
8
|
* @example
|
|
16
9
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateCpf.d.ts","sourceRoot":"","sources":["../../src/validations/validateCpf.ts"],"names":[],"mappings":"AAyBA
|
|
1
|
+
{"version":3,"file":"validateCpf.d.ts","sourceRoot":"","sources":["../../src/validations/validateCpf.ts"],"names":[],"mappings":"AAyBA;;;;;;;;;;;;GAYG;AAEH,iBAAS,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAiB5C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -20,18 +20,11 @@ function extractDigit(cpf) {
|
|
|
20
20
|
return cpf.slice(9);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* Validates a Brazilian CPF
|
|
23
|
+
* Validates a Brazilian CPF number. Strips formatting, checks length, rejects
|
|
24
|
+
* repeated-digit sequences, and verifies both check digits with the CPF algorithm.
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* - Removes any non-digit characters from the input.
|
|
28
|
-
* - Verifies if the CPF has the correct length (11 digits).
|
|
29
|
-
* - Ensures that all digits are not the same (e.g., "111.111.111-11" is invalid).
|
|
30
|
-
* - Calculates the first and second verification digits using the CPF algorithm.
|
|
31
|
-
* - Compares the calculated verification digits with the ones provided in the CPF.
|
|
32
|
-
*
|
|
33
|
-
* @param {string} rawCpf - The raw CPF string, which may include formatting characters (e.g., dots or dashes).
|
|
34
|
-
* @returns {boolean} `true` if the CPF is valid, otherwise `false`.
|
|
26
|
+
* @param rawCpf - CPF string, with or without formatting (dots and dashes).
|
|
27
|
+
* @returns `true` if the CPF is valid, otherwise `false`.
|
|
35
28
|
*
|
|
36
29
|
* @example
|
|
37
30
|
* ```typescript
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Validates a date string
|
|
2
|
+
* Validates a date string against a format and optional year bounds.
|
|
3
3
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @
|
|
9
|
-
* @returns {boolean} `true` if the date is valid according to the specified format and configuration, otherwise `false`.
|
|
4
|
+
* @param date - The date string to validate.
|
|
5
|
+
* @param config.inputFormat - Parsing format: `"brazilianDate"` (DD/MM/YYYY, default), `"isoDate"` (MM-DD-YYYY), or `"timestamp"` (YYYY-MM-DD).
|
|
6
|
+
* @param config.minYear - Minimum allowed year. Defaults to 1900.
|
|
7
|
+
* @param config.maxYear - Maximum allowed year. Defaults to 3000.
|
|
8
|
+
* @returns `true` if the date is valid according to the format and bounds, otherwise `false`.
|
|
10
9
|
*
|
|
11
10
|
* @example
|
|
12
11
|
* ```typescript
|
|
13
12
|
* validateDate("31/12/2023"); // true
|
|
14
|
-
* validateDate("12-31-2023", { inputFormat: "isoDate" }); // true
|
|
15
13
|
* validateDate("2023-12-31", { inputFormat: "timestamp", minYear: 2000, maxYear: 2100 }); // true
|
|
16
|
-
* validateDate("29/02/
|
|
17
|
-
* validateDate("29/02/2023", { inputFormat: "brazilianDate" }); // false (not a leap year)
|
|
18
|
-
* validateDate("31/04/2023", { inputFormat: "brazilianDate" }); // false (April has 30 days)
|
|
14
|
+
* validateDate("29/02/2023"); // false (not a leap year)
|
|
19
15
|
* ```
|
|
20
16
|
*/
|
|
21
17
|
declare function validateDate(date: string, config?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateDate.d.ts","sourceRoot":"","sources":["../../src/validations/validateDate.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"validateDate.d.ts","sourceRoot":"","sources":["../../src/validations/validateDate.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AAEH,iBAAS,YAAY,CACnB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE;IACP,WAAW,CAAC,EAAE,eAAe,GAAG,SAAS,GAAG,WAAW,CAAC;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GACA,OAAO,CAiCT;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import { ValidateDateService } from "@arkyn/shared";
|
|
2
2
|
/**
|
|
3
|
-
* Validates a date string
|
|
3
|
+
* Validates a date string against a format and optional year bounds.
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @
|
|
10
|
-
* @returns {boolean} `true` if the date is valid according to the specified format and configuration, otherwise `false`.
|
|
5
|
+
* @param date - The date string to validate.
|
|
6
|
+
* @param config.inputFormat - Parsing format: `"brazilianDate"` (DD/MM/YYYY, default), `"isoDate"` (MM-DD-YYYY), or `"timestamp"` (YYYY-MM-DD).
|
|
7
|
+
* @param config.minYear - Minimum allowed year. Defaults to 1900.
|
|
8
|
+
* @param config.maxYear - Maximum allowed year. Defaults to 3000.
|
|
9
|
+
* @returns `true` if the date is valid according to the format and bounds, otherwise `false`.
|
|
11
10
|
*
|
|
12
11
|
* @example
|
|
13
12
|
* ```typescript
|
|
14
13
|
* validateDate("31/12/2023"); // true
|
|
15
|
-
* validateDate("12-31-2023", { inputFormat: "isoDate" }); // true
|
|
16
14
|
* validateDate("2023-12-31", { inputFormat: "timestamp", minYear: 2000, maxYear: 2100 }); // true
|
|
17
|
-
* validateDate("29/02/
|
|
18
|
-
* validateDate("29/02/2023", { inputFormat: "brazilianDate" }); // false (not a leap year)
|
|
19
|
-
* validateDate("31/04/2023", { inputFormat: "brazilianDate" }); // false (April has 30 days)
|
|
15
|
+
* validateDate("29/02/2023"); // false (not a leap year)
|
|
20
16
|
* ```
|
|
21
17
|
*/
|
|
22
18
|
function validateDate(date, config) {
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* - Validating advanced RFC 5322 compliance rules
|
|
7
7
|
* - Verifying that the domain has valid MX or A records in DNS
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @returns
|
|
9
|
+
* @param rawEmail - The email address to validate.
|
|
10
|
+
* @returns `true` if the email passes format checks and its domain resolves in DNS, otherwise `false`.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```typescript
|
|
@@ -85,8 +85,8 @@ async function isValidDns(domain) {
|
|
|
85
85
|
* - Validating advanced RFC 5322 compliance rules
|
|
86
86
|
* - Verifying that the domain has valid MX or A records in DNS
|
|
87
87
|
*
|
|
88
|
-
* @param
|
|
89
|
-
* @returns
|
|
88
|
+
* @param rawEmail - The email address to validate.
|
|
89
|
+
* @returns `true` if the email passes format checks and its domain resolves in DNS, otherwise `false`.
|
|
90
90
|
*
|
|
91
91
|
* @example
|
|
92
92
|
* ```typescript
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* - At least 1 number
|
|
7
7
|
* - At least 1 special character
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @returns
|
|
9
|
+
* @param rawPassword - The password string to validate.
|
|
10
|
+
* @returns `true` if the password meets all rules, otherwise `false`.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* - At least 1 number
|
|
7
7
|
* - At least 1 special character
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @returns
|
|
9
|
+
* @param rawPassword - The password string to validate.
|
|
10
|
+
* @returns `true` if the password meets all rules, otherwise `false`.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Validates
|
|
2
|
+
* Validates an international phone number using `libphonenumber-js`, then confirms
|
|
3
|
+
* the parsed country code is present in the supported countries list.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* regular expressions to validate the phone number based on the country's code,
|
|
7
|
-
* prefix, and mask.
|
|
8
|
-
*
|
|
9
|
-
* Special handling is applied for Brazilian phone numbers (ISO code "BR"), which
|
|
10
|
-
* allows for an optional ninth digit.
|
|
11
|
-
*
|
|
12
|
-
* @param {string} rawPhone - The phone number to validate as a string.
|
|
13
|
-
* @returns {boolean} `true` if the phone number matches any country's format, otherwise `false`.
|
|
5
|
+
* @param rawPhone - Phone number in E.164 format (e.g. `"+5532912345678"`).
|
|
6
|
+
* @returns `true` if the number is valid and the country is supported, otherwise `false`.
|
|
14
7
|
*
|
|
15
8
|
* @example
|
|
16
9
|
* ```typescript
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* validatePhone("+5532912345678"); // true for a valid Brazilian phone number
|
|
20
|
-
* validatePhone("+553212345678"); // true for a valid Brazilian phone number
|
|
21
|
-
* validatePhone("+19706574614"); // true for a valid American Samoa phone number
|
|
22
|
-
* validatePhone("+55329123456178"); // false for an invalid Brazilian phone number
|
|
23
|
-
* validatePhone("+55123456789"); // false for an invalid Brazilian phone number
|
|
10
|
+
* validatePhone("+5532912345678"); // true (Brazil)
|
|
11
|
+
* validatePhone("+55329123456178"); // false (invalid)
|
|
24
12
|
* ```
|
|
25
13
|
*/
|
|
26
14
|
declare function validatePhone(rawPhone: string): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validatePhone.d.ts","sourceRoot":"","sources":["../../src/validations/validatePhone.ts"],"names":[],"mappings":"AAMA
|
|
1
|
+
{"version":3,"file":"validatePhone.d.ts","sourceRoot":"","sources":["../../src/validations/validatePhone.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;GAYG;AAEH,iBAAS,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAYhD;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
import { countries } from "@arkyn/templates";
|
|
2
2
|
import { isValidPhoneNumber, parsePhoneNumberWithError, } from "libphonenumber-js";
|
|
3
3
|
/**
|
|
4
|
-
* Validates
|
|
4
|
+
* Validates an international phone number using `libphonenumber-js`, then confirms
|
|
5
|
+
* the parsed country code is present in the supported countries list.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* regular expressions to validate the phone number based on the country's code,
|
|
9
|
-
* prefix, and mask.
|
|
10
|
-
*
|
|
11
|
-
* Special handling is applied for Brazilian phone numbers (ISO code "BR"), which
|
|
12
|
-
* allows for an optional ninth digit.
|
|
13
|
-
*
|
|
14
|
-
* @param {string} rawPhone - The phone number to validate as a string.
|
|
15
|
-
* @returns {boolean} `true` if the phone number matches any country's format, otherwise `false`.
|
|
7
|
+
* @param rawPhone - Phone number in E.164 format (e.g. `"+5532912345678"`).
|
|
8
|
+
* @returns `true` if the number is valid and the country is supported, otherwise `false`.
|
|
16
9
|
*
|
|
17
10
|
* @example
|
|
18
11
|
* ```typescript
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* validatePhone("+5532912345678"); // true for a valid Brazilian phone number
|
|
22
|
-
* validatePhone("+553212345678"); // true for a valid Brazilian phone number
|
|
23
|
-
* validatePhone("+19706574614"); // true for a valid American Samoa phone number
|
|
24
|
-
* validatePhone("+55329123456178"); // false for an invalid Brazilian phone number
|
|
25
|
-
* validatePhone("+55123456789"); // false for an invalid Brazilian phone number
|
|
12
|
+
* validatePhone("+5532912345678"); // true (Brazil)
|
|
13
|
+
* validatePhone("+55329123456178"); // false (invalid)
|
|
26
14
|
* ```
|
|
27
15
|
*/
|
|
28
16
|
function validatePhone(rawPhone) {
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* - Ensures length is reasonable (7–9 digits).
|
|
7
7
|
* - Optionally allows for a final letter (verifier).
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @returns
|
|
9
|
+
* @param rawRg - RG string, possibly formatted.
|
|
10
|
+
* @returns `true` if format seems valid, otherwise `false`.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* - Ensures length is reasonable (7–9 digits).
|
|
7
7
|
* - Optionally allows for a final letter (verifier).
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @returns
|
|
9
|
+
* @param rawRg - RG string, possibly formatted.
|
|
10
|
+
* @returns `true` if format seems valid, otherwise `false`.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|