@arkyn/server 3.0.1-beta.10 → 3.0.1-beta.101
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 +368 -65
- package/dist/api/arkynLogRequest.d.ts +1 -1
- package/dist/api/arkynLogRequest.d.ts.map +1 -1
- package/dist/api/arkynLogRequest.js +24 -18
- package/dist/api/makeRequest.d.ts.map +1 -1
- package/dist/api/makeRequest.js +6 -2
- package/dist/bundle.js +1507 -0
- package/dist/bundle.umd.cjs +10 -0
- package/dist/http/badResponses/_badResponse.d.ts +11 -0
- package/dist/http/badResponses/_badResponse.d.ts.map +1 -0
- package/dist/http/badResponses/_badResponse.js +20 -0
- package/dist/http/badResponses/badGateway.d.ts +2 -1
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +9 -3
- package/dist/http/badResponses/badRequest.d.ts +2 -1
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +9 -3
- package/dist/http/badResponses/conflict.d.ts +2 -1
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +9 -3
- package/dist/http/badResponses/forbidden.d.ts +2 -1
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +9 -3
- package/dist/http/badResponses/notFound.d.ts +2 -1
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +9 -3
- package/dist/http/badResponses/notImplemented.d.ts +2 -1
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +9 -3
- package/dist/http/badResponses/serverError.d.ts +2 -1
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +9 -3
- package/dist/http/badResponses/unauthorized.d.ts +2 -1
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +9 -3
- package/dist/http/badResponses/unprocessableEntity.d.ts +3 -2
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +9 -4
- package/dist/http/successResponses/_successResponse.d.ts +22 -0
- package/dist/http/successResponses/_successResponse.d.ts.map +1 -0
- package/dist/http/successResponses/_successResponse.js +37 -0
- package/dist/http/successResponses/created.d.ts +6 -2
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +5 -2
- package/dist/http/successResponses/found.d.ts +6 -2
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +5 -2
- package/dist/http/successResponses/noContent.d.ts +2 -1
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.js +4 -1
- package/dist/http/successResponses/success.d.ts +6 -2
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +5 -2
- package/dist/http/successResponses/updated.d.ts +6 -2
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +5 -2
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -4
- package/dist/{config/apiInstance.d.ts → services/apiService.d.ts} +25 -21
- package/dist/services/apiService.d.ts.map +1 -0
- package/dist/{config/apiInstance.js → services/apiService.js} +45 -23
- package/dist/{config/arkynLogInstance.d.ts → services/arkynLogService.d.ts} +11 -11
- package/dist/services/arkynLogService.d.ts.map +1 -0
- package/dist/{config/arkynLogInstance.js → services/arkynLogService.js} +8 -11
- package/dist/services/debugService.d.ts +54 -0
- package/dist/services/debugService.d.ts.map +1 -0
- package/dist/services/debugService.js +57 -0
- package/dist/services/flushDebugLogs.d.ts +8 -0
- package/dist/services/flushDebugLogs.d.ts.map +1 -0
- package/dist/services/flushDebugLogs.js +20 -0
- package/{src/services/formParse.ts → dist/services/formAsyncParse.d.ts} +20 -44
- package/dist/services/formAsyncParse.d.ts.map +1 -0
- package/dist/services/formAsyncParse.js +58 -0
- package/dist/services/formParse.d.ts +3 -3
- package/dist/services/formParse.d.ts.map +1 -1
- package/dist/services/formParse.js +7 -5
- package/dist/services/getCaller.d.ts.map +1 -1
- package/dist/services/getCaller.js +9 -14
- package/dist/services/measureRouteExecution.d.ts +3 -0
- package/dist/services/measureRouteExecution.d.ts.map +1 -0
- package/dist/services/measureRouteExecution.js +24 -0
- package/dist/services/schemaValidator.d.ts +148 -3
- package/dist/services/schemaValidator.d.ts.map +1 -1
- package/dist/services/schemaValidator.js +160 -4
- package/dist/validations/validateCep.d.ts +24 -0
- package/dist/validations/validateCep.d.ts.map +1 -0
- package/dist/validations/validateCep.js +33 -0
- package/dist/validations/validateCnpj.d.ts +22 -0
- package/dist/validations/validateCnpj.d.ts.map +1 -0
- package/dist/validations/validateCnpj.js +52 -0
- package/dist/validations/validateCpf.d.ts +24 -0
- package/dist/validations/validateCpf.d.ts.map +1 -0
- package/dist/validations/validateCpf.js +54 -0
- package/dist/validations/validateDate.d.ts +34 -0
- package/dist/validations/validateDate.d.ts.map +1 -0
- package/dist/validations/validateDate.js +73 -0
- package/dist/validations/validateEmail.d.ts +22 -0
- package/dist/validations/validateEmail.d.ts.map +1 -0
- package/dist/validations/validateEmail.js +123 -0
- package/dist/validations/validatePassword.d.ts +21 -0
- package/dist/validations/validatePassword.d.ts.map +1 -0
- package/dist/validations/validatePassword.js +34 -0
- package/dist/validations/validatePhone.d.ts +29 -0
- package/dist/validations/validatePhone.d.ts.map +1 -0
- package/dist/validations/validatePhone.js +44 -0
- package/dist/validations/validateRg.d.ts +22 -0
- package/dist/validations/validateRg.d.ts.map +1 -0
- package/dist/validations/validateRg.js +31 -0
- package/package.json +34 -18
- package/dist/config/apiInstance.d.ts.map +0 -1
- package/dist/config/arkynLogInstance.d.ts.map +0 -1
- package/dist/services/httpDebug.d.ts +0 -35
- package/dist/services/httpDebug.d.ts.map +0 -1
- package/dist/services/httpDebug.js +0 -52
- package/src/api/arkynLogRequest.ts +0 -118
- package/src/api/deleteRequest.ts +0 -22
- package/src/api/getRequest.ts +0 -20
- package/src/api/makeRequest.ts +0 -118
- package/src/api/patchRequest.ts +0 -22
- package/src/api/postRequest.ts +0 -22
- package/src/api/putRequest.ts +0 -22
- package/src/config/apiInstance.ts +0 -148
- package/src/config/arkynLogInstance.ts +0 -70
- package/src/http/badResponses/badGateway.ts +0 -63
- package/src/http/badResponses/badRequest.ts +0 -63
- package/src/http/badResponses/conflict.ts +0 -63
- package/src/http/badResponses/forbidden.ts +0 -63
- package/src/http/badResponses/notFound.ts +0 -63
- package/src/http/badResponses/notImplemented.ts +0 -63
- package/src/http/badResponses/serverError.ts +0 -63
- package/src/http/badResponses/unauthorized.ts +0 -63
- package/src/http/badResponses/unprocessableEntity.ts +0 -79
- package/src/http/successResponses/created.ts +0 -64
- package/src/http/successResponses/found.ts +0 -67
- package/src/http/successResponses/noContent.ts +0 -42
- package/src/http/successResponses/success.ts +0 -64
- package/src/http/successResponses/updated.ts +0 -64
- package/src/index.ts +0 -31
- package/src/mapper/arkynLogRequestMapper.ts +0 -73
- package/src/services/decodeErrorMessageFromRequest.ts +0 -36
- package/src/services/decodeRequestBody.ts +0 -43
- package/src/services/errorHandler.ts +0 -99
- package/src/services/getCaller.ts +0 -82
- package/src/services/getScopedParams.ts +0 -43
- package/src/services/httpDebug.ts +0 -61
- package/src/services/schemaValidator.ts +0 -66
- package/src/types/ApiResponseDTO.ts +0 -19
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -5
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a date string based on the provided format and configuration.
|
|
3
|
+
*
|
|
4
|
+
* @param rawDate - The date string to validate.
|
|
5
|
+
* @param config - Optional configuration object to customize validation.
|
|
6
|
+
* @param config.inputFormat - The expected format of the input date.
|
|
7
|
+
* Supported formats are "DD/MM/YYYY", "MM-DD-YYYY", and "YYYY-MM-DD".
|
|
8
|
+
* Defaults to "DD/MM/YYYY".
|
|
9
|
+
* @param config.minYear - The minimum allowed year for the date. Defaults to 1900.
|
|
10
|
+
* @param config.maxYear - The maximum allowed year for the date. Defaults to 3000.
|
|
11
|
+
*
|
|
12
|
+
* @returns `true` if the date is valid according to the specified format and configuration, otherwise `false`.
|
|
13
|
+
*
|
|
14
|
+
* @throws {Error} If an invalid date format is provided in the configuration.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* validateDate("31/12/2023"); // true
|
|
19
|
+
* validateDate("12-31-2023", { inputFormat: "MM-DD-YYYY" }); // true
|
|
20
|
+
* validateDate("2023-12-31", { inputFormat: "YYYY-MM-DD", minYear: 2000, maxYear: 2100 }); // true
|
|
21
|
+
* validateDate("29/02/2024", { inputFormat: "DD/MM/YYYY" }); // true (leap year)
|
|
22
|
+
* validateDate("29/02/2023", { inputFormat: "DD/MM/YYYY" }); // false (not a leap year)
|
|
23
|
+
* validateDate("31/04/2023", { inputFormat: "DD/MM/YYYY" }); // false (April has 30 days)
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const validateDate = (rawDate, config) => {
|
|
27
|
+
let day, month, year;
|
|
28
|
+
const inputFormat = config?.inputFormat || "DD/MM/YYYY";
|
|
29
|
+
const minYear = config?.minYear || 1900;
|
|
30
|
+
const maxYear = config?.maxYear || 3000;
|
|
31
|
+
if (inputFormat === "DD/MM/YYYY") {
|
|
32
|
+
const dateRegex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
|
|
33
|
+
if (!dateRegex.test(rawDate))
|
|
34
|
+
return false;
|
|
35
|
+
[, day, month, year] = rawDate.match(dateRegex) || [];
|
|
36
|
+
}
|
|
37
|
+
else if (inputFormat === "MM-DD-YYYY") {
|
|
38
|
+
const dateRegex = /^(\d{2})-(\d{2})-(\d{4})$/;
|
|
39
|
+
if (!dateRegex.test(rawDate))
|
|
40
|
+
return false;
|
|
41
|
+
[, month, day, year] = rawDate.match(dateRegex) || [];
|
|
42
|
+
}
|
|
43
|
+
else if (inputFormat === "YYYY-MM-DD") {
|
|
44
|
+
const dateRegex = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
45
|
+
if (!dateRegex.test(rawDate))
|
|
46
|
+
return false;
|
|
47
|
+
[, year, month, day] = rawDate.match(dateRegex) || [];
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error("Invalid date format");
|
|
51
|
+
}
|
|
52
|
+
const dayNum = parseInt(day, 10);
|
|
53
|
+
const monthNum = parseInt(month, 10);
|
|
54
|
+
const yearNum = parseInt(year, 10);
|
|
55
|
+
if (dayNum < 1 || dayNum > 31)
|
|
56
|
+
return false;
|
|
57
|
+
if (monthNum < 1 || monthNum > 12)
|
|
58
|
+
return false;
|
|
59
|
+
const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
60
|
+
if (monthNum === 2) {
|
|
61
|
+
const isLeapYear = (yearNum % 4 === 0 && yearNum % 100 !== 0) || yearNum % 400 === 0;
|
|
62
|
+
if (dayNum > (isLeapYear ? 29 : 28))
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
else if (dayNum > daysInMonth[monthNum - 1]) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (yearNum < minYear || yearNum > maxYear)
|
|
69
|
+
return false;
|
|
70
|
+
const isValidDate = new Date(yearNum, monthNum - 1, dayNum).getDate() === dayNum;
|
|
71
|
+
return isValidDate;
|
|
72
|
+
};
|
|
73
|
+
export { validateDate };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type ValidateEmailFunction = (rawEmail: string) => Promise<boolean>;
|
|
2
|
+
/**
|
|
3
|
+
* Validates if an email address is valid in all possible ways, including DNS validation.
|
|
4
|
+
*
|
|
5
|
+
* This function performs comprehensive email validation by:
|
|
6
|
+
* - Checking basic email format and syntax
|
|
7
|
+
* - Validating advanced RFC 5322 compliance rules
|
|
8
|
+
* - Verifying that the domain has valid MX or A records in DNS
|
|
9
|
+
*
|
|
10
|
+
* @param rawEmail - The email address string to validate
|
|
11
|
+
* @returns A promise that resolves to `true` if the email is valid (including DNS), otherwise `false`
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* await validateEmail("user@gmail.com"); // true
|
|
16
|
+
* await validateEmail("user@gmil.com"); // false (invalid domain)
|
|
17
|
+
* await validateEmail("invalid-email"); // false (invalid format)
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare const validateEmail: ValidateEmailFunction;
|
|
21
|
+
export { validateEmail };
|
|
22
|
+
//# sourceMappingURL=validateEmail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateEmail.d.ts","sourceRoot":"","sources":["../../src/validations/validateEmail.ts"],"names":[],"mappings":"AAEA,KAAK,qBAAqB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAmGpE;;;;;;;;;;;;;;;;;GAiBG;AAEH,QAAA,MAAM,aAAa,EAAE,qBAYpB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import dns from "node:dns";
|
|
2
|
+
// const resolveDns = dns.promises.resolve;
|
|
3
|
+
// Validates basic email format using a comprehensive regex pattern
|
|
4
|
+
function isValidBasicFormat(email) {
|
|
5
|
+
const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
6
|
+
return emailRegex.test(email);
|
|
7
|
+
}
|
|
8
|
+
// Validates the local part of email (before @)
|
|
9
|
+
function isValidLocalPart(localPart) {
|
|
10
|
+
if (localPart.length === 0 || localPart.length > 64)
|
|
11
|
+
return false;
|
|
12
|
+
if (localPart.startsWith(".") || localPart.endsWith("."))
|
|
13
|
+
return false;
|
|
14
|
+
if (localPart.includes(".."))
|
|
15
|
+
return false;
|
|
16
|
+
const validLocalRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/;
|
|
17
|
+
if (!validLocalRegex.test(localPart))
|
|
18
|
+
return false;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
// Validates a single domain label
|
|
22
|
+
function isValidDomainLabel(label) {
|
|
23
|
+
if (label.length === 0 || label.length > 63)
|
|
24
|
+
return false;
|
|
25
|
+
if (label.startsWith("-") || label.endsWith("-"))
|
|
26
|
+
return false;
|
|
27
|
+
if (!/^[a-zA-Z0-9-]+$/.test(label))
|
|
28
|
+
return false;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
// Validates the domain part of email (after @)
|
|
32
|
+
function isValidDomainPart(domainPart) {
|
|
33
|
+
if (domainPart.length === 0 || domainPart.length > 253)
|
|
34
|
+
return false;
|
|
35
|
+
if (domainPart.startsWith(".") ||
|
|
36
|
+
domainPart.endsWith(".") ||
|
|
37
|
+
domainPart.startsWith("-") ||
|
|
38
|
+
domainPart.endsWith("-")) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const labels = domainPart.split(".");
|
|
42
|
+
if (labels.length < 2)
|
|
43
|
+
return false;
|
|
44
|
+
for (const label of labels)
|
|
45
|
+
if (!isValidDomainLabel(label))
|
|
46
|
+
return false;
|
|
47
|
+
const tld = labels[labels.length - 1];
|
|
48
|
+
if (tld.length < 2 || !/^[a-zA-Z]+$/.test(tld))
|
|
49
|
+
return false;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
// Performs advanced syntax validation beyond basic regex
|
|
53
|
+
function isValidAdvancedSyntax(email) {
|
|
54
|
+
const parts = email.split("@");
|
|
55
|
+
if (parts.length !== 2)
|
|
56
|
+
return false;
|
|
57
|
+
const [localPart, domainPart] = parts;
|
|
58
|
+
if (!isValidLocalPart(localPart))
|
|
59
|
+
return false;
|
|
60
|
+
if (!isValidDomainPart(domainPart))
|
|
61
|
+
return false;
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
// Extracts the domain from email address
|
|
65
|
+
function extractDomain(email) {
|
|
66
|
+
const parts = email.split("@");
|
|
67
|
+
return parts.length === 2 ? parts[1].toLowerCase() : null;
|
|
68
|
+
}
|
|
69
|
+
// DNS record types to check for domain validation
|
|
70
|
+
const DNS_RECORD_TYPES = ["MX", "A", "AAAA"];
|
|
71
|
+
// Attempts to resolve a specific DNS record type for a domain
|
|
72
|
+
// async function tryResolveDnsRecord(
|
|
73
|
+
// domain: string,
|
|
74
|
+
// recordType: string
|
|
75
|
+
// ): Promise<boolean> {
|
|
76
|
+
// try {
|
|
77
|
+
// await resolveDns(domain, recordType);
|
|
78
|
+
// return true;
|
|
79
|
+
// } catch {
|
|
80
|
+
// return false;
|
|
81
|
+
// }
|
|
82
|
+
// }
|
|
83
|
+
// Validates if domain has valid DNS records (MX, A, or AAAA records)
|
|
84
|
+
// async function isValidDns(domain: string): Promise<boolean> {
|
|
85
|
+
// for (const recordType of DNS_RECORD_TYPES) {
|
|
86
|
+
// const hasRecord = await tryResolveDnsRecord(domain, recordType);
|
|
87
|
+
// if (hasRecord) return true;
|
|
88
|
+
// }
|
|
89
|
+
// return false;
|
|
90
|
+
// }
|
|
91
|
+
/**
|
|
92
|
+
* Validates if an email address is valid in all possible ways, including DNS validation.
|
|
93
|
+
*
|
|
94
|
+
* This function performs comprehensive email validation by:
|
|
95
|
+
* - Checking basic email format and syntax
|
|
96
|
+
* - Validating advanced RFC 5322 compliance rules
|
|
97
|
+
* - Verifying that the domain has valid MX or A records in DNS
|
|
98
|
+
*
|
|
99
|
+
* @param rawEmail - The email address string to validate
|
|
100
|
+
* @returns A promise that resolves to `true` if the email is valid (including DNS), otherwise `false`
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* await validateEmail("user@gmail.com"); // true
|
|
105
|
+
* await validateEmail("user@gmil.com"); // false (invalid domain)
|
|
106
|
+
* await validateEmail("invalid-email"); // false (invalid format)
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
const validateEmail = async (rawEmail) => {
|
|
110
|
+
if (!rawEmail || typeof rawEmail !== "string")
|
|
111
|
+
return false;
|
|
112
|
+
const email = rawEmail.trim();
|
|
113
|
+
if (!isValidBasicFormat(email))
|
|
114
|
+
return false;
|
|
115
|
+
if (!isValidAdvancedSyntax(email))
|
|
116
|
+
return false;
|
|
117
|
+
const domain = extractDomain(email);
|
|
118
|
+
if (!domain)
|
|
119
|
+
return false;
|
|
120
|
+
// return await isValidDns(domain);
|
|
121
|
+
return true;
|
|
122
|
+
};
|
|
123
|
+
export { validateEmail };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type ValidatePasswordFunction = (rawPassword: string) => boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Validates a password based on the following rules:
|
|
4
|
+
* - At least 8 characters
|
|
5
|
+
* - At least 1 uppercase letter
|
|
6
|
+
* - At least 1 letter (any case)
|
|
7
|
+
* - At least 1 number
|
|
8
|
+
* - At least 1 special character
|
|
9
|
+
*
|
|
10
|
+
* @param rawPassword - The raw password string.
|
|
11
|
+
* @returns `true` if password is valid, otherwise `false`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* validatePassword("Senha@123"); // true
|
|
16
|
+
* validatePassword("senha123"); // false (no uppercase, no special char)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare const validatePassword: ValidatePasswordFunction;
|
|
20
|
+
export { validatePassword };
|
|
21
|
+
//# sourceMappingURL=validatePassword.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatePassword.d.ts","sourceRoot":"","sources":["../../src/validations/validatePassword.ts"],"names":[],"mappings":"AAAA,KAAK,wBAAwB,GAAG,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;AAEjE;;;;;;;;;;;;;;;;GAgBG;AAEH,QAAA,MAAM,gBAAgB,EAAE,wBAkBvB,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a password based on the following rules:
|
|
3
|
+
* - At least 8 characters
|
|
4
|
+
* - At least 1 uppercase letter
|
|
5
|
+
* - At least 1 letter (any case)
|
|
6
|
+
* - At least 1 number
|
|
7
|
+
* - At least 1 special character
|
|
8
|
+
*
|
|
9
|
+
* @param rawPassword - The raw password string.
|
|
10
|
+
* @returns `true` if password is valid, otherwise `false`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* validatePassword("Senha@123"); // true
|
|
15
|
+
* validatePassword("senha123"); // false (no uppercase, no special char)
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
const validatePassword = (rawPassword) => {
|
|
19
|
+
if (!rawPassword)
|
|
20
|
+
return false;
|
|
21
|
+
const hasMinLength = rawPassword.length >= 8;
|
|
22
|
+
const hasUppercase = /[A-Z]/.test(rawPassword);
|
|
23
|
+
const hasLetter = /[a-z]/.test(rawPassword);
|
|
24
|
+
const hasNumber = /\d/.test(rawPassword);
|
|
25
|
+
const hasSpecialChar = /[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(rawPassword);
|
|
26
|
+
return [
|
|
27
|
+
hasMinLength,
|
|
28
|
+
hasUppercase,
|
|
29
|
+
hasLetter,
|
|
30
|
+
hasNumber,
|
|
31
|
+
hasSpecialChar,
|
|
32
|
+
].every((condition) => condition);
|
|
33
|
+
};
|
|
34
|
+
export { validatePassword };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type ValidatePhoneFunction = (rawPhone: string) => boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Validates a phone number against a list of country-specific formats.
|
|
4
|
+
*
|
|
5
|
+
* The function iterates through a predefined list of countries and checks if the
|
|
6
|
+
* provided phone number matches the format for any of the countries. It uses
|
|
7
|
+
* regular expressions to validate the phone number based on the country's code,
|
|
8
|
+
* prefix, and mask.
|
|
9
|
+
*
|
|
10
|
+
* Special handling is applied for Brazilian phone numbers (ISO code "BR"), which
|
|
11
|
+
* allows for an optional ninth digit.
|
|
12
|
+
*
|
|
13
|
+
* @param rawPhone - The phone number to validate as a string.
|
|
14
|
+
* @returns `true` if the phone number matches any country's format, otherwise `false`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { validatePhone } from "./validatePhone";
|
|
19
|
+
*
|
|
20
|
+
* validatePhone("+55 32912345678"); // true for a valid Brazilian phone number
|
|
21
|
+
* validatePhone("+55 3212345678"); // true for a valid Brazilian phone number
|
|
22
|
+
* validatePhone("+1-684 1234567"); // true for a valid American Samoa phone number
|
|
23
|
+
* validatePhone("+5532912345678"); // false for an invalid Brazilian phone number
|
|
24
|
+
* validatePhone("+55 1234567890"); // false for an invalid Brazilian phone number
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare const validatePhone: ValidatePhoneFunction;
|
|
28
|
+
export { validatePhone };
|
|
29
|
+
//# sourceMappingURL=validatePhone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatePhone.d.ts","sourceRoot":"","sources":["../../src/validations/validatePhone.ts"],"names":[],"mappings":"AAEA,KAAK,qBAAqB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,QAAA,MAAM,aAAa,EAAE,qBAiBpB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { countries } from "@arkyn/templates";
|
|
2
|
+
/**
|
|
3
|
+
* Validates a phone number against a list of country-specific formats.
|
|
4
|
+
*
|
|
5
|
+
* The function iterates through a predefined list of countries and checks if the
|
|
6
|
+
* provided phone number matches the format for any of the countries. It uses
|
|
7
|
+
* regular expressions to validate the phone number based on the country's code,
|
|
8
|
+
* prefix, and mask.
|
|
9
|
+
*
|
|
10
|
+
* Special handling is applied for Brazilian phone numbers (ISO code "BR"), which
|
|
11
|
+
* allows for an optional ninth digit.
|
|
12
|
+
*
|
|
13
|
+
* @param rawPhone - The phone number to validate as a string.
|
|
14
|
+
* @returns `true` if the phone number matches any country's format, otherwise `false`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { validatePhone } from "./validatePhone";
|
|
19
|
+
*
|
|
20
|
+
* validatePhone("+55 32912345678"); // true for a valid Brazilian phone number
|
|
21
|
+
* validatePhone("+55 3212345678"); // true for a valid Brazilian phone number
|
|
22
|
+
* validatePhone("+1-684 1234567"); // true for a valid American Samoa phone number
|
|
23
|
+
* validatePhone("+5532912345678"); // false for an invalid Brazilian phone number
|
|
24
|
+
* validatePhone("+55 1234567890"); // false for an invalid Brazilian phone number
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
const validatePhone = (rawPhone) => {
|
|
28
|
+
for (const country of countries) {
|
|
29
|
+
const countryCode = country.code;
|
|
30
|
+
const prefix = country.prefix ? `-${country.prefix}` : "";
|
|
31
|
+
const digitCount = country.mask.replace(/[^_]/g, "").length;
|
|
32
|
+
if (country.iso === "BR") {
|
|
33
|
+
const brazilRegex = new RegExp(`^\\${countryCode} \\d{2}9?\\d{8}$`);
|
|
34
|
+
if (brazilRegex.test(rawPhone))
|
|
35
|
+
return true;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const regex = new RegExp(`^\\${countryCode}${prefix} \\d{${digitCount}}$`);
|
|
39
|
+
if (regex.test(rawPhone))
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
};
|
|
44
|
+
export { validatePhone };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type ValidateRgFunction = (rawRg: string) => boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Validates a Brazilian RG (Registro Geral) in a generic way.
|
|
4
|
+
*
|
|
5
|
+
* This function does a basic structure validation:
|
|
6
|
+
* - Removes non-alphanumeric characters.
|
|
7
|
+
* - Ensures length is reasonable (7–9 digits).
|
|
8
|
+
* - Optionally allows for a final letter (verifier).
|
|
9
|
+
*
|
|
10
|
+
* @param rawRg - RG string, possibly formatted.
|
|
11
|
+
* @returns `true` if format seems valid, otherwise `false`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* validateRg("12.345.678-9"); // true
|
|
16
|
+
* validateRg("MG-12.345.678"); // false (not supported)
|
|
17
|
+
* validateRg("12345678X"); // true
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare const validateRg: ValidateRgFunction;
|
|
21
|
+
export { validateRg };
|
|
22
|
+
//# sourceMappingURL=validateRg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateRg.d.ts","sourceRoot":"","sources":["../../src/validations/validateRg.ts"],"names":[],"mappings":"AAAA,KAAK,kBAAkB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AAEH,QAAA,MAAM,UAAU,EAAE,kBAajB,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a Brazilian RG (Registro Geral) in a generic way.
|
|
3
|
+
*
|
|
4
|
+
* This function does a basic structure validation:
|
|
5
|
+
* - Removes non-alphanumeric characters.
|
|
6
|
+
* - Ensures length is reasonable (7–9 digits).
|
|
7
|
+
* - Optionally allows for a final letter (verifier).
|
|
8
|
+
*
|
|
9
|
+
* @param rawRg - RG string, possibly formatted.
|
|
10
|
+
* @returns `true` if format seems valid, otherwise `false`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* validateRg("12.345.678-9"); // true
|
|
15
|
+
* validateRg("MG-12.345.678"); // false (not supported)
|
|
16
|
+
* validateRg("12345678X"); // true
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
const validateRg = (rawRg) => {
|
|
20
|
+
if (!rawRg)
|
|
21
|
+
return false;
|
|
22
|
+
const validFormat = /^[0-9a-zA-Z.-]+$/.test(rawRg);
|
|
23
|
+
if (!validFormat)
|
|
24
|
+
return false;
|
|
25
|
+
const rg = rawRg.replace(/[^a-zA-Z0-9]/g, "");
|
|
26
|
+
if (rg.length < 7 || rg.length > 9)
|
|
27
|
+
return false;
|
|
28
|
+
const isValidFormat = /^[0-9]{7,8}[0-9Xx]?$/.test(rg);
|
|
29
|
+
return isValidFormat;
|
|
30
|
+
};
|
|
31
|
+
export { validateRg };
|
package/package.json
CHANGED
|
@@ -1,29 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkyn/server",
|
|
3
|
-
"version": "3.0.1-beta.
|
|
3
|
+
"version": "3.0.1-beta.101",
|
|
4
4
|
"author": "Arkyn | Lucas Gonçalves",
|
|
5
5
|
"main": "./dist/bundle.js",
|
|
6
|
-
"module": "./
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"zod": ">=3.24.2"
|
|
10
|
-
},
|
|
11
|
-
"devDependencies": {
|
|
12
|
-
"bun-types": "latest",
|
|
13
|
-
"vitest": "^3.1.1",
|
|
14
|
-
"typescript": "^5.8.3"
|
|
15
|
-
},
|
|
16
|
-
"peerDependencies": {
|
|
17
|
-
"@react-router/node": ">=7.6.0"
|
|
18
|
-
},
|
|
19
|
-
"description": "Server-side utilities for projects.",
|
|
6
|
+
"module": "./dist/bundle.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
20
9
|
"license": "Apache-2.0",
|
|
10
|
+
"description": "Comprehensive server-side utilities for building robust backend applications, featuring HTTP response helpers, error handlers, request utilities, and API configurations.",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"server",
|
|
13
|
+
"http",
|
|
14
|
+
"api",
|
|
15
|
+
"utilities",
|
|
16
|
+
"error-handling",
|
|
17
|
+
"validation",
|
|
18
|
+
"remix",
|
|
19
|
+
"typescript",
|
|
20
|
+
"zod"
|
|
21
|
+
],
|
|
22
|
+
"homepage": "https://docs.arkyn.dev/en/server/introduction",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/Lucas-Eduardo-Goncalves/arkyn.git",
|
|
26
|
+
"directory": "packages/server"
|
|
27
|
+
},
|
|
21
28
|
"scripts": {
|
|
22
29
|
"clean": "rm -rf dist",
|
|
23
|
-
"build": "
|
|
30
|
+
"build": "bunx vite build && tsc",
|
|
24
31
|
"test": "vitest --config vitest.config.ts",
|
|
25
32
|
"typecheck": "bunx tsc --project tsconfig.json --noEmit"
|
|
26
33
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@arkyn/shared": "*",
|
|
36
|
+
"@arkyn/templates": "*",
|
|
37
|
+
"zod": ">=4.0.17"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"bun-types": "latest",
|
|
41
|
+
"vitest": "^3.2.4",
|
|
42
|
+
"typescript": "^5.9.2",
|
|
43
|
+
"vite": "^5.4.19"
|
|
44
|
+
}
|
|
29
45
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apiInstance.d.ts","sourceRoot":"","sources":["../../src/config/apiInstance.ts"],"names":[],"mappings":"AAMA,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AAEH,cAAM,WAAW;IACf,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,SAAS,CAAC,CAAS;IAE3B;;;;;;OAMG;gBAES,KAAK,EAAE,0BAA0B;IAM7C;;;;OAIG;IAEH,OAAO,CAAC,WAAW;IAInB;;;;;OAKG;IAEH,OAAO,CAAC,eAAe;IAcvB;;;;;OAKG;IAEG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,8BAA8B;IAM9D;;;;;OAKG;IAEG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAO5D;;;;;OAKG;IAEG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAO3D;;;;;OAKG;IAEG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAO7D;;;;;OAKG;IAEG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;CAM/D;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"arkynLogInstance.d.ts","sourceRoot":"","sources":["../../src/config/arkynLogInstance.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;;;GAIG;AAEH,cAAM,gBAAgB;IACpB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAmB;IAE9C;;;;;;;;;;OAUG;IAEH,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB;IAgBtD;;;;;OAKG;IACH,MAAM,CAAC,cAAc,IAAI,gBAAgB,GAAG,SAAS;IAIrD;;;OAGG;IAEH,MAAM,CAAC,gBAAgB;CAGxB;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logs debug information to the console when in development mode or when the
|
|
3
|
-
* `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
|
|
4
|
-
*
|
|
5
|
-
* This function provides detailed information about the caller function,
|
|
6
|
-
* its location, and the provided body and cause, if any.
|
|
7
|
-
*
|
|
8
|
-
* @param name - A string representing the name or context of the debug log.
|
|
9
|
-
* @param body - The main content or data to be logged.
|
|
10
|
-
* @param cause - (Optional) Additional information or error cause to be logged.
|
|
11
|
-
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* The debug logs are only displayed when the application is running in
|
|
14
|
-
* development mode (`NODE_ENV === "development"`) or when the
|
|
15
|
-
* `SHOW_ERRORS_IN_CONSOLE` environment variable is explicitly set to "true".
|
|
16
|
-
*
|
|
17
|
-
* The logs include:
|
|
18
|
-
* - The name of the debug context.
|
|
19
|
-
* - The caller function name and its location.
|
|
20
|
-
* - The provided body content.
|
|
21
|
-
* - The optional cause, if provided.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* httpDebug("FetchUserData", { userId: 123 });
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* httpDebug("FetchUserDataError", { userId: 123 }, new Error("User not found"));
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
declare function httpDebug(name: string, body: any, cause?: any): void;
|
|
34
|
-
export { httpDebug };
|
|
35
|
-
//# sourceMappingURL=httpDebug.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"httpDebug.d.ts","sourceRoot":"","sources":["../../src/services/httpDebug.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,QAuBtD;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { getCaller } from "../services/getCaller";
|
|
2
|
-
/**
|
|
3
|
-
* Logs debug information to the console when in development mode or when the
|
|
4
|
-
* `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
|
|
5
|
-
*
|
|
6
|
-
* This function provides detailed information about the caller function,
|
|
7
|
-
* its location, and the provided body and cause, if any.
|
|
8
|
-
*
|
|
9
|
-
* @param name - A string representing the name or context of the debug log.
|
|
10
|
-
* @param body - The main content or data to be logged.
|
|
11
|
-
* @param cause - (Optional) Additional information or error cause to be logged.
|
|
12
|
-
*
|
|
13
|
-
* @remarks
|
|
14
|
-
* The debug logs are only displayed when the application is running in
|
|
15
|
-
* development mode (`NODE_ENV === "development"`) or when the
|
|
16
|
-
* `SHOW_ERRORS_IN_CONSOLE` environment variable is explicitly set to "true".
|
|
17
|
-
*
|
|
18
|
-
* The logs include:
|
|
19
|
-
* - The name of the debug context.
|
|
20
|
-
* - The caller function name and its location.
|
|
21
|
-
* - The provided body content.
|
|
22
|
-
* - The optional cause, if provided.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* httpDebug("FetchUserData", { userId: 123 });
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* httpDebug("FetchUserDataError", { userId: 123 }, new Error("User not found"));
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
function httpDebug(name, body, cause) {
|
|
35
|
-
const isDebugMode = process.env.NODE_ENV === "development" ||
|
|
36
|
-
process.env?.SHOW_ERRORS_IN_CONSOLE === "true";
|
|
37
|
-
if (isDebugMode) {
|
|
38
|
-
const reset = "\x1b[0m";
|
|
39
|
-
const cyan = "\x1b[36m";
|
|
40
|
-
const debugName = `${cyan}[ARKYN-DEBUG]${reset}`;
|
|
41
|
-
const { callerInfo, functionName } = getCaller();
|
|
42
|
-
let consoleData = `${debugName} ${name} initialized\n`;
|
|
43
|
-
consoleData += `${debugName} Caller Function: ${functionName}\n`;
|
|
44
|
-
consoleData += `${debugName} Caller Location: ${callerInfo}\n`;
|
|
45
|
-
consoleData += `${debugName} Body: ${JSON.stringify(body, null, 2)}\n`;
|
|
46
|
-
if (cause) {
|
|
47
|
-
consoleData += `${debugName} Cause: ${JSON.stringify(cause, null, 2)}\n`;
|
|
48
|
-
}
|
|
49
|
-
console.log(consoleData);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
export { httpDebug };
|