@arkyn/server 3.0.1-beta.12 → 3.0.1-beta.121
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/bundle.js +1518 -0
- package/dist/bundle.umd.cjs +5 -0
- package/dist/{api/arkynLogRequest.d.ts → http/api/_logRequest.d.ts} +22 -19
- package/dist/{api/arkynLogRequest.d.ts.map → http/api/_logRequest.d.ts.map} +1 -1
- package/dist/http/api/_logRequest.js +88 -0
- package/dist/http/api/_makeRequest.d.ts +61 -0
- package/dist/http/api/_makeRequest.d.ts.map +1 -0
- package/dist/{api/makeRequest.js → http/api/_makeRequest.js} +33 -20
- package/dist/http/api/deleteRequest.d.ts +17 -0
- package/dist/http/api/deleteRequest.d.ts.map +1 -0
- package/dist/http/api/deleteRequest.js +18 -0
- package/dist/http/api/getRequest.d.ts +16 -0
- package/dist/http/api/getRequest.d.ts.map +1 -0
- package/dist/http/api/getRequest.js +17 -0
- package/dist/http/api/patchRequest.d.ts +17 -0
- package/dist/http/api/patchRequest.d.ts.map +1 -0
- package/dist/http/api/patchRequest.js +18 -0
- package/dist/http/api/postRequest.d.ts +17 -0
- package/dist/http/api/postRequest.d.ts.map +1 -0
- package/dist/http/api/postRequest.js +18 -0
- package/dist/http/api/putRequest.d.ts +17 -0
- package/dist/http/api/putRequest.d.ts.map +1 -0
- package/dist/http/api/putRequest.js +18 -0
- package/dist/http/badResponses/_badResponse.d.ts +22 -0
- package/dist/http/badResponses/_badResponse.d.ts.map +1 -0
- package/dist/http/badResponses/_badResponse.js +51 -0
- package/dist/http/badResponses/badGateway.d.ts +6 -9
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +12 -14
- package/dist/http/badResponses/badRequest.d.ts +6 -9
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +12 -14
- package/dist/http/badResponses/conflict.d.ts +6 -9
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +12 -14
- package/dist/http/badResponses/forbidden.d.ts +6 -9
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +12 -14
- package/dist/http/badResponses/notFound.d.ts +6 -9
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +12 -14
- package/dist/http/badResponses/notImplemented.d.ts +6 -9
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +12 -14
- package/dist/http/badResponses/serverError.d.ts +6 -9
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +12 -14
- package/dist/http/badResponses/unauthorized.d.ts +4 -7
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +10 -12
- package/dist/http/badResponses/unprocessableEntity.d.ts +15 -19
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +18 -21
- package/dist/http/successResponses/_successResponse.d.ts +33 -0
- package/dist/http/successResponses/_successResponse.d.ts.map +1 -0
- package/dist/http/successResponses/_successResponse.js +66 -0
- package/dist/http/successResponses/created.d.ts +9 -19
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +16 -25
- package/dist/http/successResponses/found.d.ts +10 -23
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +17 -29
- package/dist/http/successResponses/noContent.d.ts +6 -13
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.js +12 -17
- package/dist/http/successResponses/success.d.ts +9 -19
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +16 -25
- package/dist/http/successResponses/updated.d.ts +9 -19
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +16 -25
- package/dist/index.d.ts +19 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -13
- package/dist/services/apiService.d.ts +63 -0
- package/dist/services/apiService.d.ts.map +1 -0
- package/dist/services/apiService.js +158 -0
- package/dist/services/debugService.d.ts +69 -0
- package/dist/services/debugService.d.ts.map +1 -0
- package/dist/services/debugService.js +114 -0
- package/dist/services/logMapperService.d.ts +86 -0
- package/dist/services/logMapperService.d.ts.map +1 -0
- package/dist/services/logMapperService.js +68 -0
- package/dist/services/logService.d.ts +38 -0
- package/dist/services/logService.d.ts.map +1 -0
- package/dist/services/logService.js +40 -0
- package/dist/{services → utilities}/decodeRequestBody.d.ts +3 -4
- package/dist/utilities/decodeRequestBody.d.ts.map +1 -0
- package/dist/{services → utilities}/decodeRequestBody.js +5 -5
- package/dist/{services/decodeErrorMessageFromRequest.d.ts → utilities/decodeRequestErrorMessage.d.ts} +6 -6
- package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -0
- package/dist/{services/decodeErrorMessageFromRequest.js → utilities/decodeRequestErrorMessage.js} +5 -5
- package/dist/utilities/errorHandler.d.ts +50 -0
- package/dist/utilities/errorHandler.d.ts.map +1 -0
- package/dist/{services → utilities}/errorHandler.js +34 -28
- package/dist/utilities/flushDebugLogs.d.ts +46 -0
- package/dist/utilities/flushDebugLogs.d.ts.map +1 -0
- package/dist/utilities/flushDebugLogs.js +59 -0
- package/dist/utilities/formAsyncParse.d.ts +59 -0
- package/dist/utilities/formAsyncParse.d.ts.map +1 -0
- package/dist/utilities/formAsyncParse.js +58 -0
- package/dist/{services → utilities}/formParse.d.ts +6 -6
- package/dist/utilities/formParse.d.ts.map +1 -0
- package/dist/{services → utilities}/formParse.js +10 -8
- package/dist/{services → utilities}/getScopedParams.d.ts +3 -4
- package/dist/utilities/getScopedParams.d.ts.map +1 -0
- package/dist/{services → utilities}/getScopedParams.js +4 -4
- package/dist/utilities/schemaValidator.d.ts +146 -0
- package/dist/utilities/schemaValidator.d.ts.map +1 -0
- package/dist/utilities/schemaValidator.js +191 -0
- package/dist/validations/validateCep.d.ts +19 -0
- package/dist/validations/validateCep.d.ts.map +1 -0
- package/dist/validations/validateCep.js +27 -0
- package/dist/validations/validateCnpj.d.ts +21 -0
- package/dist/validations/validateCnpj.d.ts.map +1 -0
- package/dist/validations/validateCnpj.js +59 -0
- package/dist/validations/validateCpf.d.ts +23 -0
- package/dist/validations/validateCpf.d.ts.map +1 -0
- package/dist/validations/validateCpf.js +61 -0
- package/dist/validations/validateDate.d.ts +27 -0
- package/dist/validations/validateDate.d.ts.map +1 -0
- package/dist/validations/validateDate.js +55 -0
- package/dist/validations/validateEmail.d.ts +21 -0
- package/dist/validations/validateEmail.d.ts.map +1 -0
- package/dist/validations/validateEmail.js +111 -0
- package/dist/validations/validatePassword.d.ts +20 -0
- package/dist/validations/validatePassword.d.ts.map +1 -0
- package/dist/validations/validatePassword.js +34 -0
- package/dist/validations/validatePhone.d.ts +28 -0
- package/dist/validations/validatePhone.d.ts.map +1 -0
- package/dist/validations/validatePhone.js +44 -0
- package/dist/validations/validateRg.d.ts +21 -0
- package/dist/validations/validateRg.d.ts.map +1 -0
- package/dist/validations/validateRg.js +31 -0
- package/package.json +34 -18
- package/dist/api/arkynLogRequest.js +0 -82
- package/dist/api/deleteRequest.d.ts +0 -13
- package/dist/api/deleteRequest.d.ts.map +0 -1
- package/dist/api/deleteRequest.js +0 -14
- package/dist/api/getRequest.d.ts +0 -12
- package/dist/api/getRequest.d.ts.map +0 -1
- package/dist/api/getRequest.js +0 -13
- package/dist/api/makeRequest.d.ts +0 -38
- package/dist/api/makeRequest.d.ts.map +0 -1
- package/dist/api/patchRequest.d.ts +0 -13
- package/dist/api/patchRequest.d.ts.map +0 -1
- package/dist/api/patchRequest.js +0 -14
- package/dist/api/postRequest.d.ts +0 -13
- package/dist/api/postRequest.d.ts.map +0 -1
- package/dist/api/postRequest.js +0 -14
- package/dist/api/putRequest.d.ts +0 -13
- package/dist/api/putRequest.d.ts.map +0 -1
- package/dist/api/putRequest.js +0 -14
- package/dist/config/apiInstance.d.ts +0 -80
- package/dist/config/apiInstance.d.ts.map +0 -1
- package/dist/config/apiInstance.js +0 -111
- package/dist/config/arkynLogInstance.d.ts +0 -44
- package/dist/config/arkynLogInstance.d.ts.map +0 -1
- package/dist/config/arkynLogInstance.js +0 -49
- package/dist/mapper/arkynLogRequestMapper.d.ts +0 -30
- package/dist/mapper/arkynLogRequestMapper.d.ts.map +0 -1
- package/dist/mapper/arkynLogRequestMapper.js +0 -44
- package/dist/services/decodeErrorMessageFromRequest.d.ts.map +0 -1
- package/dist/services/decodeRequestBody.d.ts.map +0 -1
- package/dist/services/errorHandler.d.ts +0 -44
- package/dist/services/errorHandler.d.ts.map +0 -1
- package/dist/services/formParse.d.ts.map +0 -1
- package/dist/services/getCaller.d.ts +0 -17
- package/dist/services/getCaller.d.ts.map +0 -1
- package/dist/services/getCaller.js +0 -65
- package/dist/services/getScopedParams.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/dist/services/measureRouteExecution.d.ts +0 -3
- package/dist/services/measureRouteExecution.d.ts.map +0 -1
- package/dist/services/measureRouteExecution.js +0 -24
- package/dist/services/schemaValidator.d.ts +0 -13
- package/dist/services/schemaValidator.d.ts.map +0 -1
- package/dist/services/schemaValidator.js +0 -51
- package/dist/types/ApiResponseDTO.d.ts +0 -17
- package/dist/types/ApiResponseDTO.d.ts.map +0 -1
- package/dist/types/ApiResponseDTO.js +0 -1
- 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/formParse.ts +0 -83
- package/src/services/getCaller.ts +0 -82
- package/src/services/getScopedParams.ts +0 -43
- package/src/services/httpDebug.ts +0 -61
- package/src/services/measureRouteExecution.ts +0 -31
- 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,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 {string} rawPassword - The raw password string.
|
|
10
|
+
* @returns {boolean} `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
|
+
function 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,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates a phone number against a list of country-specific formats.
|
|
3
|
+
*
|
|
4
|
+
* The function iterates through a predefined list of countries and checks if the
|
|
5
|
+
* provided phone number matches the format for any of the countries. It uses
|
|
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`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { validatePhone } from "./validatePhone";
|
|
18
|
+
*
|
|
19
|
+
* validatePhone("+55 32912345678"); // true for a valid Brazilian phone number
|
|
20
|
+
* validatePhone("+55 3212345678"); // true for a valid Brazilian phone number
|
|
21
|
+
* validatePhone("+1-684 1234567"); // true for a valid American Samoa phone number
|
|
22
|
+
* validatePhone("+5532912345678"); // false for an invalid Brazilian phone number
|
|
23
|
+
* validatePhone("+55 1234567890"); // false for an invalid Brazilian phone number
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare function validatePhone(rawPhone: string): boolean;
|
|
27
|
+
export { validatePhone };
|
|
28
|
+
//# sourceMappingURL=validatePhone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatePhone.d.ts","sourceRoot":"","sources":["../../src/validations/validatePhone.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,iBAAS,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAiBhD;AAED,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 {string} rawPhone - The phone number to validate as a string.
|
|
14
|
+
* @returns {boolean} `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
|
+
function 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,21 @@
|
|
|
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 {string} rawRg - RG string, possibly formatted.
|
|
10
|
+
* @returns {boolean} `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
|
+
declare function validateRg(rawRg: string): boolean;
|
|
20
|
+
export { validateRg };
|
|
21
|
+
//# sourceMappingURL=validateRg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateRg.d.ts","sourceRoot":"","sources":["../../src/validations/validateRg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,iBAAS,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAa1C;AAED,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 {string} rawRg - RG string, possibly formatted.
|
|
10
|
+
* @returns {boolean} `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
|
+
function 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.121",
|
|
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,82 +0,0 @@
|
|
|
1
|
-
import { ArkynLogInstance } from "../config/arkynLogInstance";
|
|
2
|
-
import { httpDebug } from "../services/httpDebug";
|
|
3
|
-
/**
|
|
4
|
-
* Sends a request to the inbox flow API with the provided configuration.
|
|
5
|
-
*
|
|
6
|
-
* @param config - The configuration object for the request.
|
|
7
|
-
* @param config.rawUrl - The raw URL of the request.
|
|
8
|
-
* @param config.status - The HTTP status code associated with the request.
|
|
9
|
-
* @param config.method - The HTTP method used for the request. Can be "POST", "GET", "PUT", "DELETE", or "PATCH".
|
|
10
|
-
* @param config.token - The authentication token for the request.
|
|
11
|
-
* @param config.elapsedTime - The elapsed time for the request in milliseconds.
|
|
12
|
-
* @param config.requestHeaders - The headers sent with the request.
|
|
13
|
-
* @param config.requestBody - The body of the request, if applicable.
|
|
14
|
-
* @param config.queryParams - The query parameters for the request.
|
|
15
|
-
* @param config.responseHeaders - The headers received in the response.
|
|
16
|
-
* @param config.responseBody - The body of the response received.
|
|
17
|
-
*
|
|
18
|
-
* @remarks
|
|
19
|
-
* - This function retrieves the inbox flow configuration using `InboxFlowInstance.getInboxConfig()`.
|
|
20
|
-
* - If the configuration is not available, the function will return early without performing any action.
|
|
21
|
-
* - In a development environment (`NODE_ENV === "development"`), the function will also return early.
|
|
22
|
-
* - The request is sent as a POST request to the inbox API URL with the provided configuration details.
|
|
23
|
-
* - If an error occurs during the request, it will be logged using the `httpDebug` service.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* const config = {
|
|
28
|
-
* rawUrl: "https://example.com/api/data",
|
|
29
|
-
* status: 200,
|
|
30
|
-
* method: "GET",
|
|
31
|
-
* token: "auth-token-123",
|
|
32
|
-
* elapsedTime: "150ms",
|
|
33
|
-
* requestHeaders: { "Accept": "application/json", "Authorization": "Bearer token123" },
|
|
34
|
-
* requestBody: {},
|
|
35
|
-
* queryParams: { "page": "1", "limit": "10" },
|
|
36
|
-
* responseHeaders: { "Content-Type": "application/json" },
|
|
37
|
-
* responseBody: { "data": "example response" }
|
|
38
|
-
* };
|
|
39
|
-
*
|
|
40
|
-
* await arkynLogRequest(config);
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
async function arkynLogRequest(config) {
|
|
44
|
-
const arkynInstance = ArkynLogInstance.getArkynConfig();
|
|
45
|
-
if (!arkynInstance)
|
|
46
|
-
return;
|
|
47
|
-
const { arkynUserToken, arkynApiUrl } = arkynInstance;
|
|
48
|
-
const { elapsedTime, method, queryParams, requestBody, requestHeaders, responseBody, responseHeaders, status, token, rawUrl, } = config;
|
|
49
|
-
// if (process.env.NODE_ENV === "development") return;
|
|
50
|
-
try {
|
|
51
|
-
const url = new URL(rawUrl);
|
|
52
|
-
let protocol = "HTTPS";
|
|
53
|
-
if (url.protocol === "http:")
|
|
54
|
-
protocol = "HTTP";
|
|
55
|
-
const body = JSON.stringify({
|
|
56
|
-
domainUrl: url.protocol + "//" + url.host,
|
|
57
|
-
pathnameUrl: url.pathname,
|
|
58
|
-
status,
|
|
59
|
-
protocol,
|
|
60
|
-
method,
|
|
61
|
-
trafficUserId: null,
|
|
62
|
-
elapsedTime,
|
|
63
|
-
requestHeaders,
|
|
64
|
-
requestBody,
|
|
65
|
-
queryParams,
|
|
66
|
-
responseHeaders,
|
|
67
|
-
responseBody,
|
|
68
|
-
});
|
|
69
|
-
await fetch(arkynApiUrl.replace(":trafficSourceId", arkynInstance.arkynTrafficSourceId), {
|
|
70
|
-
method: "POST",
|
|
71
|
-
body,
|
|
72
|
-
headers: {
|
|
73
|
-
"Content-Type": "application/json",
|
|
74
|
-
Authorization: `Bearer ${arkynUserToken}`,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
httpDebug("arkyn log error", "Error sending request", err);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export { arkynLogRequest };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ApiResponseDTO } from "../types/ApiResponseDTO";
|
|
2
|
-
/**
|
|
3
|
-
* Sends a DELETE request to the specified URL with optional headers and body.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The expected type of the response data.
|
|
6
|
-
* @param {string} url - The URL to send the DELETE request to.
|
|
7
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
-
* @param {any} [body] - Optional body to include in the request.
|
|
9
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
-
*/
|
|
11
|
-
declare function deleteRequest<T = any>(url: string, headers?: HeadersInit, body?: any): Promise<ApiResponseDTO<T>>;
|
|
12
|
-
export { deleteRequest };
|
|
13
|
-
//# sourceMappingURL=deleteRequest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deleteRequest.d.ts","sourceRoot":"","sources":["../../src/api/deleteRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D;;;;;;;;GAQG;AAEH,iBAAe,aAAa,CAAC,CAAC,GAAG,GAAG,EAClC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,IAAI,CAAC,EAAE,GAAG,GACT,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAE5B;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { makeRequest } from "./makeRequest";
|
|
2
|
-
/**
|
|
3
|
-
* Sends a DELETE request to the specified URL with optional headers and body.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The expected type of the response data.
|
|
6
|
-
* @param {string} url - The URL to send the DELETE request to.
|
|
7
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
-
* @param {any} [body] - Optional body to include in the request.
|
|
9
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
-
*/
|
|
11
|
-
async function deleteRequest(url, headers = {}, body) {
|
|
12
|
-
return makeRequest("DELETE", url, headers, body);
|
|
13
|
-
}
|
|
14
|
-
export { deleteRequest };
|
package/dist/api/getRequest.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ApiResponseDTO } from "../types/ApiResponseDTO";
|
|
2
|
-
/**
|
|
3
|
-
* Sends a GET request to the specified URL with optional headers.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The expected type of the response data.
|
|
6
|
-
* @param {string} url - The URL to send the GET request to.
|
|
7
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
9
|
-
*/
|
|
10
|
-
declare function getRequest<T = any>(url: string, headers?: HeadersInit): Promise<ApiResponseDTO<T>>;
|
|
11
|
-
export { getRequest };
|
|
12
|
-
//# sourceMappingURL=getRequest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRequest.d.ts","sourceRoot":"","sources":["../../src/api/getRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D;;;;;;;GAOG;AAEH,iBAAe,UAAU,CAAC,CAAC,GAAG,GAAG,EAC/B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAE5B;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/api/getRequest.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { makeRequest } from "./makeRequest";
|
|
2
|
-
/**
|
|
3
|
-
* Sends a GET request to the specified URL with optional headers.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The expected type of the response data.
|
|
6
|
-
* @param {string} url - The URL to send the GET request to.
|
|
7
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
9
|
-
*/
|
|
10
|
-
async function getRequest(url, headers = {}) {
|
|
11
|
-
return makeRequest("GET", url, headers);
|
|
12
|
-
}
|
|
13
|
-
export { getRequest };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ApiResponseDTO } from "../types/ApiResponseDTO";
|
|
2
|
-
/**
|
|
3
|
-
* Makes an HTTP request using the Fetch API and returns a standardized response.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The expected type of the response data.
|
|
6
|
-
* @param method - The HTTP method to use for the request. Supported methods are:
|
|
7
|
-
* - "POST": Create a new resource.
|
|
8
|
-
* - "PUT": Update an existing resource.
|
|
9
|
-
* - "DELETE": Remove a resource.
|
|
10
|
-
* - "PATCH": Partially update a resource.
|
|
11
|
-
* - "GET": Retrieve a resource.
|
|
12
|
-
* @param url - The URL to which the request is sent.
|
|
13
|
-
* @param headers - Optional headers to include in the request. Defaults to an empty object.
|
|
14
|
-
* @param body - Optional body to include in the request. Should be serializable to JSON.
|
|
15
|
-
* @returns A promise that resolves to an `ApiResponseDTO<T>` object containing:
|
|
16
|
-
* - `success`: A boolean indicating whether the request was successful.
|
|
17
|
-
* - `status`: The HTTP status code of the response.
|
|
18
|
-
* - `message`: A message describing the result of the request.
|
|
19
|
-
* - `response`: The parsed JSON response data, or `null` if parsing fails.
|
|
20
|
-
* - `cause`: Additional error information, if applicable.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* import { makeRequest } from "./makeRequest";
|
|
25
|
-
*
|
|
26
|
-
* async function fetchData() {
|
|
27
|
-
* const response = await makeRequest("GET", "https://api.example.com/data");
|
|
28
|
-
* if (response.success) {
|
|
29
|
-
* console.log("Data:", response.response);
|
|
30
|
-
* } else {
|
|
31
|
-
* console.error("Error:", response.message);
|
|
32
|
-
* }
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
declare function makeRequest<T = any>(method: "POST" | "PUT" | "DELETE" | "PATCH" | "GET", url: string, rawHeaders?: HeadersInit, body?: any): Promise<ApiResponseDTO<T>>;
|
|
37
|
-
export { makeRequest };
|
|
38
|
-
//# sourceMappingURL=makeRequest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"makeRequest.d.ts","sourceRoot":"","sources":["../../src/api/makeRequest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,iBAAe,WAAW,CAAC,CAAC,GAAG,GAAG,EAChC,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,EACnD,GAAG,EAAE,MAAM,EACX,UAAU,GAAE,WAAgB,EAC5B,IAAI,CAAC,EAAE,GAAG,GACT,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAsE5B;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ApiResponseDTO } from "../types/ApiResponseDTO";
|
|
2
|
-
/**
|
|
3
|
-
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The expected type of the response data.
|
|
6
|
-
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
-
* @param {any} body - The body to include in the request.
|
|
9
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
-
*/
|
|
11
|
-
declare function patchRequest<T = any>(url: string, headers: HeadersInit | undefined, body: any): Promise<ApiResponseDTO<T>>;
|
|
12
|
-
export { patchRequest };
|
|
13
|
-
//# sourceMappingURL=patchRequest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"patchRequest.d.ts","sourceRoot":"","sources":["../../src/api/patchRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D;;;;;;;;GAQG;AAEH,iBAAe,YAAY,CAAC,CAAC,GAAG,GAAG,EACjC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,YAAK,EACzB,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAE5B;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/api/patchRequest.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { makeRequest } from "./makeRequest";
|
|
2
|
-
/**
|
|
3
|
-
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The expected type of the response data.
|
|
6
|
-
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
-
* @param {any} body - The body to include in the request.
|
|
9
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
-
*/
|
|
11
|
-
async function patchRequest(url, headers = {}, body) {
|
|
12
|
-
return makeRequest("PATCH", url, headers, body);
|
|
13
|
-
}
|
|
14
|
-
export { patchRequest };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ApiResponseDTO } from "../types/ApiResponseDTO";
|
|
2
|
-
/**
|
|
3
|
-
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The expected type of the response data.
|
|
6
|
-
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
-
* @param {any} body - The body to include in the request.
|
|
9
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
-
*/
|
|
11
|
-
declare function postRequest<T = any>(url: string, headers: HeadersInit | undefined, body: any): Promise<ApiResponseDTO<T>>;
|
|
12
|
-
export { postRequest };
|
|
13
|
-
//# sourceMappingURL=postRequest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postRequest.d.ts","sourceRoot":"","sources":["../../src/api/postRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D;;;;;;;;GAQG;AAEH,iBAAe,WAAW,CAAC,CAAC,GAAG,GAAG,EAChC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,YAAK,EACzB,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAE5B;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/api/postRequest.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { makeRequest } from "./makeRequest";
|
|
2
|
-
/**
|
|
3
|
-
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The expected type of the response data.
|
|
6
|
-
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
-
* @param {any} body - The body to include in the request.
|
|
9
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
-
*/
|
|
11
|
-
async function postRequest(url, headers = {}, body) {
|
|
12
|
-
return makeRequest("POST", url, headers, body);
|
|
13
|
-
}
|
|
14
|
-
export { postRequest };
|
package/dist/api/putRequest.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ApiResponseDTO } from "../types/ApiResponseDTO";
|
|
2
|
-
/**
|
|
3
|
-
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The expected type of the response data.
|
|
6
|
-
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
-
* @param {any} body - The body to include in the request.
|
|
9
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
-
*/
|
|
11
|
-
declare function putRequest<T = any>(url: string, headers: HeadersInit | undefined, body: any): Promise<ApiResponseDTO<T>>;
|
|
12
|
-
export { putRequest };
|
|
13
|
-
//# sourceMappingURL=putRequest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"putRequest.d.ts","sourceRoot":"","sources":["../../src/api/putRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D;;;;;;;;GAQG;AAEH,iBAAe,UAAU,CAAC,CAAC,GAAG,GAAG,EAC/B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,YAAK,EACzB,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAE5B;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/api/putRequest.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { makeRequest } from "./makeRequest";
|
|
2
|
-
/**
|
|
3
|
-
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
-
*
|
|
5
|
-
* @template T - The expected type of the response data.
|
|
6
|
-
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
-
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
-
* @param {any} body - The body to include in the request.
|
|
9
|
-
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
-
*/
|
|
11
|
-
async function putRequest(url, headers = {}, body) {
|
|
12
|
-
return makeRequest("PUT", url, headers, body);
|
|
13
|
-
}
|
|
14
|
-
export { putRequest };
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
type ApiInstanceConstructorProps = {
|
|
2
|
-
baseUrl: string;
|
|
3
|
-
baseHeaders?: HeadersInit;
|
|
4
|
-
baseToken?: string | null;
|
|
5
|
-
};
|
|
6
|
-
type ApiRequestDataWithoutBodyProps = {
|
|
7
|
-
headers?: HeadersInit;
|
|
8
|
-
token?: string;
|
|
9
|
-
};
|
|
10
|
-
type ApiRequestDataWithBodyProps = {
|
|
11
|
-
body?: any;
|
|
12
|
-
headers?: HeadersInit;
|
|
13
|
-
token?: string;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Class representing an API instance to handle HTTP requests with base configurations.
|
|
17
|
-
*/
|
|
18
|
-
declare class ApiInstance {
|
|
19
|
-
private baseUrl;
|
|
20
|
-
private baseHeaders?;
|
|
21
|
-
private baseToken?;
|
|
22
|
-
/**
|
|
23
|
-
* Creates an instance of ApiInstance.
|
|
24
|
-
* @param props - The configuration properties for the API instance.
|
|
25
|
-
* @param props.baseUrl - The base URL for the API.
|
|
26
|
-
* @param props.baseHeaders - Optional base headers to include in all requests.
|
|
27
|
-
* @param props.baseToken - Optional base token for authorization.
|
|
28
|
-
*/
|
|
29
|
-
constructor(props: ApiInstanceConstructorProps);
|
|
30
|
-
/**
|
|
31
|
-
* Generates the full URL by appending the route to the base URL.
|
|
32
|
-
* @param route - The route to append to the base URL.
|
|
33
|
-
* @returns The full URL as a string.
|
|
34
|
-
*/
|
|
35
|
-
private generateURL;
|
|
36
|
-
/**
|
|
37
|
-
* Generates the headers for a request by merging base headers, provided headers, and tokens.
|
|
38
|
-
* @param initHeaders - Initial headers to include in the request.
|
|
39
|
-
* @param token - Optional token to override the base token.
|
|
40
|
-
* @returns The merged headers as a HeadersInit object.
|
|
41
|
-
*/
|
|
42
|
-
private generateHeaders;
|
|
43
|
-
/**
|
|
44
|
-
* Sends a get request to the specified route.
|
|
45
|
-
* @param route - The API route to send the get request to.
|
|
46
|
-
* @param data - The request data, including optional headers and token.
|
|
47
|
-
* @returns The API response data.
|
|
48
|
-
*/
|
|
49
|
-
get(route: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
50
|
-
/**
|
|
51
|
-
* Sends a post request to the specified route.
|
|
52
|
-
* @param route - The API route to send the post request to.
|
|
53
|
-
* @param data - The request data, including body, optional headers, and token.
|
|
54
|
-
* @returns The API response data.
|
|
55
|
-
*/
|
|
56
|
-
post(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
57
|
-
/**
|
|
58
|
-
* Sends a put request to the specified route.
|
|
59
|
-
* @param route - The API route to send the put request to.
|
|
60
|
-
* @param data - The request data, including body, optional headers, and token.
|
|
61
|
-
* @returns The API response data.
|
|
62
|
-
*/
|
|
63
|
-
put(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
64
|
-
/**
|
|
65
|
-
* Sends a patch request to the specified route.
|
|
66
|
-
* @param route - The API route to send the patch request to.
|
|
67
|
-
* @param data - The request data, including body, optional headers, and token.
|
|
68
|
-
* @returns The API response data.
|
|
69
|
-
*/
|
|
70
|
-
patch(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
71
|
-
/**
|
|
72
|
-
* Sends a delete request to the specified route.
|
|
73
|
-
* @param route - The API route to send the delete request to.
|
|
74
|
-
* @param data - The request data, including body, optional headers, and token.
|
|
75
|
-
* @returns The API response data.
|
|
76
|
-
*/
|
|
77
|
-
delete(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
78
|
-
}
|
|
79
|
-
export { ApiInstance };
|
|
80
|
-
//# sourceMappingURL=apiInstance.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apiInstance.d.ts","sourceRoot":"","sources":["../../src/config/apiInstance.ts"],"names":[],"mappings":"AAMA,KAAK,2BAA2B,GAAG;IACjC,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,2BAA2B;IAM9C;;;;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"}
|