@arkyn/server 3.0.1-beta.9 → 3.0.1-beta.91
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 -19
- package/dist/api/makeRequest.d.ts +1 -1
- package/dist/api/makeRequest.d.ts.map +1 -1
- package/dist/api/makeRequest.js +9 -7
- 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 +2 -1
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +4 -1
- package/dist/http/successResponses/found.d.ts +2 -1
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +4 -1
- 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 +2 -1
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +4 -1
- package/dist/http/successResponses/updated.d.ts +2 -1
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +4 -1
- 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 -125
- package/src/api/deleteRequest.ts +0 -22
- package/src/api/getRequest.ts +0 -20
- package/src/api/makeRequest.ts +0 -120
- 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,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.91",
|
|
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 };
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { ArkynLogInstance } from "../config/arkynLogInstance";
|
|
2
|
-
import { httpDebug } from "../services/httpDebug";
|
|
3
|
-
|
|
4
|
-
type ConfigProps = {
|
|
5
|
-
rawUrl: string;
|
|
6
|
-
status: number;
|
|
7
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
8
|
-
token: string | null;
|
|
9
|
-
elapsedTime: number;
|
|
10
|
-
requestHeaders: Record<string, string>;
|
|
11
|
-
requestBody: Record<string, string>;
|
|
12
|
-
queryParams: Record<string, string>;
|
|
13
|
-
responseHeaders: Record<string, string>;
|
|
14
|
-
responseBody: Record<string, string>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Sends a request to the inbox flow API with the provided configuration.
|
|
19
|
-
*
|
|
20
|
-
* @param config - The configuration object for the request.
|
|
21
|
-
* @param config.rawUrl - The raw URL of the request.
|
|
22
|
-
* @param config.status - The HTTP status code associated with the request.
|
|
23
|
-
* @param config.method - The HTTP method used for the request. Can be "POST", "GET", "PUT", "DELETE", or "PATCH".
|
|
24
|
-
* @param config.token - The authentication token for the request.
|
|
25
|
-
* @param config.elapsedTime - The elapsed time for the request in milliseconds.
|
|
26
|
-
* @param config.requestHeaders - The headers sent with the request.
|
|
27
|
-
* @param config.requestBody - The body of the request, if applicable.
|
|
28
|
-
* @param config.queryParams - The query parameters for the request.
|
|
29
|
-
* @param config.responseHeaders - The headers received in the response.
|
|
30
|
-
* @param config.responseBody - The body of the response received.
|
|
31
|
-
*
|
|
32
|
-
* @remarks
|
|
33
|
-
* - This function retrieves the inbox flow configuration using `InboxFlowInstance.getInboxConfig()`.
|
|
34
|
-
* - If the configuration is not available, the function will return early without performing any action.
|
|
35
|
-
* - In a development environment (`NODE_ENV === "development"`), the function will also return early.
|
|
36
|
-
* - The request is sent as a POST request to the inbox API URL with the provided configuration details.
|
|
37
|
-
* - If an error occurs during the request, it will be logged using the `httpDebug` service.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* const config = {
|
|
42
|
-
* rawUrl: "https://example.com/api/data",
|
|
43
|
-
* status: 200,
|
|
44
|
-
* method: "GET",
|
|
45
|
-
* token: "auth-token-123",
|
|
46
|
-
* elapsedTime: "150ms",
|
|
47
|
-
* requestHeaders: { "Accept": "application/json", "Authorization": "Bearer token123" },
|
|
48
|
-
* requestBody: {},
|
|
49
|
-
* queryParams: { "page": "1", "limit": "10" },
|
|
50
|
-
* responseHeaders: { "Content-Type": "application/json" },
|
|
51
|
-
* responseBody: { "data": "example response" }
|
|
52
|
-
* };
|
|
53
|
-
*
|
|
54
|
-
* await arkynLogRequest(config);
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
async function arkynLogRequest(config: ConfigProps) {
|
|
59
|
-
const arkynInstance = ArkynLogInstance.getArkynConfig();
|
|
60
|
-
if (!arkynInstance) return;
|
|
61
|
-
|
|
62
|
-
const { arkynUserToken, arkynApiUrl } = arkynInstance;
|
|
63
|
-
|
|
64
|
-
const {
|
|
65
|
-
elapsedTime,
|
|
66
|
-
method,
|
|
67
|
-
queryParams,
|
|
68
|
-
requestBody,
|
|
69
|
-
requestHeaders,
|
|
70
|
-
responseBody,
|
|
71
|
-
responseHeaders,
|
|
72
|
-
status,
|
|
73
|
-
token,
|
|
74
|
-
rawUrl,
|
|
75
|
-
} = config;
|
|
76
|
-
|
|
77
|
-
// if (process.env.NODE_ENV === "development") return;
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const url = new URL(rawUrl);
|
|
81
|
-
let protocol: "HTTPS" | "HTTP" = "HTTPS";
|
|
82
|
-
if (url.protocol === "http:") protocol = "HTTP";
|
|
83
|
-
|
|
84
|
-
const body = JSON.stringify({
|
|
85
|
-
domainUrl: url.protocol + "//" + url.host,
|
|
86
|
-
pathnameUrl: url.pathname,
|
|
87
|
-
status,
|
|
88
|
-
protocol,
|
|
89
|
-
method,
|
|
90
|
-
trafficUserId: null,
|
|
91
|
-
elapsedTime,
|
|
92
|
-
requestHeaders,
|
|
93
|
-
requestBody,
|
|
94
|
-
queryParams,
|
|
95
|
-
responseHeaders,
|
|
96
|
-
responseBody,
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
console.log(
|
|
100
|
-
arkynApiUrl.replace(
|
|
101
|
-
":trafficSourceId",
|
|
102
|
-
arkynInstance.arkynTrafficSourceId
|
|
103
|
-
)
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
await fetch(
|
|
107
|
-
arkynApiUrl.replace(
|
|
108
|
-
":trafficSourceId",
|
|
109
|
-
arkynInstance.arkynTrafficSourceId
|
|
110
|
-
),
|
|
111
|
-
{
|
|
112
|
-
method: "POST",
|
|
113
|
-
body,
|
|
114
|
-
headers: {
|
|
115
|
-
"Content-Type": "application/json",
|
|
116
|
-
Authorization: `Bearer ${arkynUserToken}`,
|
|
117
|
-
},
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
} catch (err) {
|
|
121
|
-
httpDebug("arkyn log error", "Error sending request", err);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export { arkynLogRequest };
|
package/src/api/deleteRequest.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { ApiResponseDTO } from "../types/ApiResponseDTO";
|
|
2
|
-
import { makeRequest } from "./makeRequest";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Sends a DELETE request to the specified URL with optional headers and body.
|
|
6
|
-
*
|
|
7
|
-
* @template T - The expected type of the response data.
|
|
8
|
-
* @param {string} url - The URL to send the DELETE request to.
|
|
9
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
10
|
-
* @param {any} [body] - Optional body to include in the request.
|
|
11
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
async function deleteRequest<T = any>(
|
|
15
|
-
url: string,
|
|
16
|
-
headers: HeadersInit = {},
|
|
17
|
-
body?: any
|
|
18
|
-
): Promise<ApiResponseDTO<T>> {
|
|
19
|
-
return makeRequest("DELETE", url, headers, body);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { deleteRequest };
|
package/src/api/getRequest.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ApiResponseDTO } from "../types/ApiResponseDTO";
|
|
2
|
-
import { makeRequest } from "./makeRequest";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Sends a GET request to the specified URL with optional headers.
|
|
6
|
-
*
|
|
7
|
-
* @template T - The expected type of the response data.
|
|
8
|
-
* @param {string} url - The URL to send the GET request to.
|
|
9
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
10
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
async function getRequest<T = any>(
|
|
14
|
-
url: string,
|
|
15
|
-
headers: HeadersInit = {}
|
|
16
|
-
): Promise<ApiResponseDTO<T>> {
|
|
17
|
-
return makeRequest("GET", url, headers);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { getRequest };
|