@arkyn/server 3.0.1-beta.10 → 3.0.1-beta.102
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
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
type ArkynConfigProps = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
trafficSourceId: string;
|
|
3
|
+
userToken: string;
|
|
4
|
+
apiUrl: string;
|
|
5
5
|
};
|
|
6
6
|
type SetArkynConfigProps = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
trafficSourceId: string;
|
|
8
|
+
userToken: string;
|
|
9
|
+
logBaseApiUrl?: string;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
* The `
|
|
12
|
+
* The `ArkynLogService` class manages the configuration for the arkyn flow.
|
|
13
13
|
* It allows you to set and retrieve the arkyn configuration, including the traffic source ID,
|
|
14
14
|
* user token, and API URL.
|
|
15
15
|
*/
|
|
16
|
-
declare class
|
|
16
|
+
declare class ArkynLogService {
|
|
17
17
|
private static arkynConfig?;
|
|
18
18
|
/**
|
|
19
19
|
* Sets the configuration for the arkyn. This method initializes the arkyn configuration
|
|
@@ -28,7 +28,7 @@ declare class ArkynLogInstance {
|
|
|
28
28
|
*/
|
|
29
29
|
static setArkynConfig(arkynConfig: SetArkynConfigProps): void;
|
|
30
30
|
/**
|
|
31
|
-
* Retrieves the current arkyn configuration for the
|
|
31
|
+
* Retrieves the current arkyn configuration for the ArkynLogService.
|
|
32
32
|
*
|
|
33
33
|
* @returns {ArkynConfigProps | undefined} The current arkyn configuration if set,
|
|
34
34
|
* or `undefined` if no configuration has been initialized.
|
|
@@ -40,5 +40,5 @@ declare class ArkynLogInstance {
|
|
|
40
40
|
*/
|
|
41
41
|
static resetArkynConfig(): void;
|
|
42
42
|
}
|
|
43
|
-
export {
|
|
44
|
-
//# sourceMappingURL=
|
|
43
|
+
export { ArkynLogService };
|
|
44
|
+
//# sourceMappingURL=arkynLogService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arkynLogService.d.ts","sourceRoot":"","sources":["../../src/services/arkynLogService.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;GAIG;AAEH,cAAM,eAAe;IACnB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAmB;IAE9C;;;;;;;;;;OAUG;IAEH,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB;IAYtD;;;;;OAKG;IACH,MAAM,CAAC,cAAc,IAAI,gBAAgB,GAAG,SAAS;IAIrD;;;OAGG;IAEH,MAAM,CAAC,gBAAgB;CAGxB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `
|
|
2
|
+
* The `ArkynLogService` class manages the configuration for the arkyn flow.
|
|
3
3
|
* It allows you to set and retrieve the arkyn configuration, including the traffic source ID,
|
|
4
4
|
* user token, and API URL.
|
|
5
5
|
*/
|
|
6
|
-
class
|
|
6
|
+
class ArkynLogService {
|
|
7
7
|
static arkynConfig;
|
|
8
8
|
/**
|
|
9
9
|
* Sets the configuration for the arkyn. This method initializes the arkyn configuration
|
|
@@ -19,18 +19,15 @@ class ArkynLogInstance {
|
|
|
19
19
|
static setArkynConfig(arkynConfig) {
|
|
20
20
|
if (!!this.arkynConfig)
|
|
21
21
|
return;
|
|
22
|
-
|
|
23
|
-
let arkynLogBaseApiUrl = arkynConfig.arkynLogBaseApiUrl || defaultArkynURL;
|
|
24
|
-
arkynLogBaseApiUrl =
|
|
25
|
-
arkynLogBaseApiUrl + "/http-traffic-records/:trafficSourceId";
|
|
22
|
+
const { trafficSourceId, userToken, logBaseApiUrl } = arkynConfig;
|
|
26
23
|
this.arkynConfig = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
trafficSourceId,
|
|
25
|
+
userToken,
|
|
26
|
+
apiUrl: logBaseApiUrl || `http://95.216.190.158:8081/ingest-log`,
|
|
30
27
|
};
|
|
31
28
|
}
|
|
32
29
|
/**
|
|
33
|
-
* Retrieves the current arkyn configuration for the
|
|
30
|
+
* Retrieves the current arkyn configuration for the ArkynLogService.
|
|
34
31
|
*
|
|
35
32
|
* @returns {ArkynConfigProps | undefined} The current arkyn configuration if set,
|
|
36
33
|
* or `undefined` if no configuration has been initialized.
|
|
@@ -46,4 +43,4 @@ class ArkynLogInstance {
|
|
|
46
43
|
this.arkynConfig = undefined;
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
|
-
export {
|
|
46
|
+
export { ArkynLogService };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service for managing HTTP debug configuration and behavior.
|
|
3
|
+
*
|
|
4
|
+
* This service provides functionality to configure how the `getCaller` function
|
|
5
|
+
* identifies the actual caller in the stack trace by allowing specific files
|
|
6
|
+
* to be ignored during stack trace analysis.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Configure to ignore httpAdapter.ts in stack traces
|
|
11
|
+
* HttpDebugService.setIgnoreFile("httpAdapter.ts");
|
|
12
|
+
*
|
|
13
|
+
* // Now when httpDebug is called from within httpAdapter.ts,
|
|
14
|
+
* // it will show the actual caller (e.g., cart.ts) instead
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare class DebugService {
|
|
18
|
+
/**
|
|
19
|
+
* The name of the file to ignore when analyzing the stack trace.
|
|
20
|
+
* When set, the `getCaller` function will skip stack frames containing this file name.
|
|
21
|
+
*/
|
|
22
|
+
static ignoreFiles: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Sets the file name to be ignored during stack trace analysis.
|
|
25
|
+
*
|
|
26
|
+
* This method configures the debug service to skip specific files when
|
|
27
|
+
* determining the actual caller of a function. This is useful when you have
|
|
28
|
+
* adapter or wrapper functions that you want to be transparent in the debug output.
|
|
29
|
+
*
|
|
30
|
+
* @param file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Ignore the HTTP adapter file so debug shows the actual business logic caller
|
|
35
|
+
* DebugService.setIgnoreFile("httpAdapter.ts");
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
static setIgnoreFile(file: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Clears all configured ignore files.
|
|
41
|
+
*
|
|
42
|
+
* This method resets the ignore file configuration, allowing all files to be
|
|
43
|
+
* considered in stack trace analysis again.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // Clear all ignore file configurations
|
|
48
|
+
* DebugService.clearIgnoreFiles();
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
static clearIgnoreFiles(): void;
|
|
52
|
+
}
|
|
53
|
+
export { DebugService };
|
|
54
|
+
//# sourceMappingURL=debugService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debugService.d.ts","sourceRoot":"","sources":["../../src/services/debugService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,cAAM,YAAY;IAChB;;;OAGG;IACH,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,CAAM;IAElC;;;;;;;;;;;;;;OAcG;IAEH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM;IAIjC;;;;;;;;;;;OAWG;IAEH,MAAM,CAAC,gBAAgB;CAGxB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service for managing HTTP debug configuration and behavior.
|
|
3
|
+
*
|
|
4
|
+
* This service provides functionality to configure how the `getCaller` function
|
|
5
|
+
* identifies the actual caller in the stack trace by allowing specific files
|
|
6
|
+
* to be ignored during stack trace analysis.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Configure to ignore httpAdapter.ts in stack traces
|
|
11
|
+
* HttpDebugService.setIgnoreFile("httpAdapter.ts");
|
|
12
|
+
*
|
|
13
|
+
* // Now when httpDebug is called from within httpAdapter.ts,
|
|
14
|
+
* // it will show the actual caller (e.g., cart.ts) instead
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
class DebugService {
|
|
18
|
+
/**
|
|
19
|
+
* The name of the file to ignore when analyzing the stack trace.
|
|
20
|
+
* When set, the `getCaller` function will skip stack frames containing this file name.
|
|
21
|
+
*/
|
|
22
|
+
static ignoreFiles = [];
|
|
23
|
+
/**
|
|
24
|
+
* Sets the file name to be ignored during stack trace analysis.
|
|
25
|
+
*
|
|
26
|
+
* This method configures the debug service to skip specific files when
|
|
27
|
+
* determining the actual caller of a function. This is useful when you have
|
|
28
|
+
* adapter or wrapper functions that you want to be transparent in the debug output.
|
|
29
|
+
*
|
|
30
|
+
* @param file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Ignore the HTTP adapter file so debug shows the actual business logic caller
|
|
35
|
+
* DebugService.setIgnoreFile("httpAdapter.ts");
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
static setIgnoreFile(file) {
|
|
39
|
+
this.ignoreFiles.push(file);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Clears all configured ignore files.
|
|
43
|
+
*
|
|
44
|
+
* This method resets the ignore file configuration, allowing all files to be
|
|
45
|
+
* considered in stack trace analysis again.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Clear all ignore file configurations
|
|
50
|
+
* DebugService.clearIgnoreFiles();
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
static clearIgnoreFiles() {
|
|
54
|
+
this.ignoreFiles = [];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export { DebugService };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flushDebugLogs.d.ts","sourceRoot":"","sources":["../../src/services/flushDebugLogs.ts"],"names":[],"mappings":"AAAA,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,QAwBjD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function flushDebugLogs(props) {
|
|
2
|
+
const isDebugMode = process.env.NODE_ENV === "development" ||
|
|
3
|
+
process.env?.SHOW_ERRORS_IN_CONSOLE === "true";
|
|
4
|
+
if (isDebugMode) {
|
|
5
|
+
const reset = "\x1b[0m";
|
|
6
|
+
const colors = {
|
|
7
|
+
yellow: "\x1b[33m",
|
|
8
|
+
cyan: "\x1b[36m",
|
|
9
|
+
red: "\x1b[31m",
|
|
10
|
+
green: "\x1b[32m",
|
|
11
|
+
};
|
|
12
|
+
const debugName = `${colors[props.scheme]}[${props.name}]${reset}`;
|
|
13
|
+
let consoleData = `\n`;
|
|
14
|
+
props.debugs.forEach((debug) => {
|
|
15
|
+
consoleData += `${debugName} ${debug.trim()}\n`;
|
|
16
|
+
});
|
|
17
|
+
console.log(consoleData);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export { flushDebugLogs };
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { ZodType } from "zod";
|
|
3
2
|
type SuccessResponse<T extends FormParseProps> = {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
success: true;
|
|
4
|
+
data: T[1] extends ZodType<infer U> ? U : never;
|
|
6
5
|
};
|
|
7
|
-
|
|
8
6
|
type ErrorResponse = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
success: false;
|
|
8
|
+
fields: {
|
|
9
|
+
[x: string]: string;
|
|
10
|
+
};
|
|
11
|
+
fieldErrors: {
|
|
12
|
+
[x: string]: string;
|
|
13
|
+
};
|
|
12
14
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type FormParseReturnType<T extends FormParseProps> =
|
|
17
|
-
| SuccessResponse<T>
|
|
18
|
-
| ErrorResponse;
|
|
19
|
-
|
|
15
|
+
type FormParseProps = [formData: {
|
|
16
|
+
[k: string]: any;
|
|
17
|
+
}, schema: ZodType];
|
|
18
|
+
type FormParseReturnType<T extends FormParseProps> = SuccessResponse<T> | ErrorResponse;
|
|
20
19
|
/**
|
|
21
|
-
*
|
|
20
|
+
* Asynchronously parses form data using a Zod schema and returns the result.
|
|
22
21
|
*
|
|
23
22
|
* @template T - A type that extends `FormParseProps`.
|
|
24
23
|
*
|
|
@@ -26,7 +25,7 @@ type FormParseReturnType<T extends FormParseProps> =
|
|
|
26
25
|
* @param {T[0]} param0[0] - The form data to be validated.
|
|
27
26
|
* @param {T[1]} param0[1] - The Zod schema used for validation.
|
|
28
27
|
*
|
|
29
|
-
* @returns {FormParseReturnType<T
|
|
28
|
+
* @returns {Promise<FormParseReturnType<T>>} A promise that resolves to an object containing the validation result.
|
|
30
29
|
* - If validation fails, it includes:
|
|
31
30
|
* - `success`: A boolean indicating the validation status (false).
|
|
32
31
|
* - `fieldErrors`: An object mapping field names to their respective error messages.
|
|
@@ -46,7 +45,7 @@ type FormParseReturnType<T extends FormParseProps> =
|
|
|
46
45
|
*
|
|
47
46
|
* const formData = { name: "", age: 17 };
|
|
48
47
|
*
|
|
49
|
-
* const result =
|
|
48
|
+
* const result = await formAsyncParse([formData, schema]);
|
|
50
49
|
*
|
|
51
50
|
* if (!result.success) {
|
|
52
51
|
* console.log(result.fieldErrors); // { name: "Name is required", age: "Must be at least 18" }
|
|
@@ -55,29 +54,6 @@ type FormParseReturnType<T extends FormParseProps> =
|
|
|
55
54
|
* }
|
|
56
55
|
* ```
|
|
57
56
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
schema,
|
|
62
|
-
]: T): FormParseReturnType<T> {
|
|
63
|
-
const zodResponse = schema.safeParse(formData);
|
|
64
|
-
|
|
65
|
-
if (zodResponse.success === false) {
|
|
66
|
-
const errorsObject = Object.fromEntries(
|
|
67
|
-
zodResponse.error.errors.map((item) => [
|
|
68
|
-
item.path.join("."),
|
|
69
|
-
item.message,
|
|
70
|
-
])
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
success: zodResponse.success,
|
|
75
|
-
fieldErrors: errorsObject,
|
|
76
|
-
fields: formData,
|
|
77
|
-
};
|
|
78
|
-
} else {
|
|
79
|
-
return { success: zodResponse.success, data: zodResponse.data };
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export { formParse };
|
|
57
|
+
declare function formAsyncParse<T extends FormParseProps>([formData, schema,]: T): Promise<FormParseReturnType<T>>;
|
|
58
|
+
export { formAsyncParse };
|
|
59
|
+
//# sourceMappingURL=formAsyncParse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formAsyncParse.d.ts","sourceRoot":"","sources":["../../src/services/formAsyncParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAe,cAAc,CAAC,CAAC,SAAS,cAAc,EAAE,CACtD,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAqBrC;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronously parses form data using a Zod schema and returns the result.
|
|
3
|
+
*
|
|
4
|
+
* @template T - A type that extends `FormParseProps`.
|
|
5
|
+
*
|
|
6
|
+
* @param {T} param0 - An array containing the form data and the Zod schema.
|
|
7
|
+
* @param {T[0]} param0[0] - The form data to be validated.
|
|
8
|
+
* @param {T[1]} param0[1] - The Zod schema used for validation.
|
|
9
|
+
*
|
|
10
|
+
* @returns {Promise<FormParseReturnType<T>>} A promise that resolves to an object containing the validation result.
|
|
11
|
+
* - If validation fails, it includes:
|
|
12
|
+
* - `success`: A boolean indicating the validation status (false).
|
|
13
|
+
* - `fieldErrors`: An object mapping field names to their respective error messages.
|
|
14
|
+
* - `fields`: The original form data.
|
|
15
|
+
* - If validation succeeds, it includes:
|
|
16
|
+
* - `success`: A boolean indicating the validation status (true).
|
|
17
|
+
* - `data`: The parsed and validated data.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { z } from "zod";
|
|
22
|
+
*
|
|
23
|
+
* const schema = z.object({
|
|
24
|
+
* name: z.string().min(1, "Name is required"),
|
|
25
|
+
* age: z.number().min(18, "Must be at least 18"),
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const formData = { name: "", age: 17 };
|
|
29
|
+
*
|
|
30
|
+
* const result = await formAsyncParse([formData, schema]);
|
|
31
|
+
*
|
|
32
|
+
* if (!result.success) {
|
|
33
|
+
* console.log(result.fieldErrors); // { name: "Name is required", age: "Must be at least 18" }
|
|
34
|
+
* } else {
|
|
35
|
+
* console.log(result.data); // Parsed data
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
async function formAsyncParse([formData, schema,]) {
|
|
40
|
+
const zodResponse = await schema.safeParseAsync(formData);
|
|
41
|
+
if (zodResponse.success === false) {
|
|
42
|
+
const errorsObject = Object.fromEntries(zodResponse.error.issues.map((item) => {
|
|
43
|
+
return [item.path.join("."), item.message];
|
|
44
|
+
}));
|
|
45
|
+
return {
|
|
46
|
+
success: zodResponse.success,
|
|
47
|
+
fieldErrors: errorsObject,
|
|
48
|
+
fields: formData,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return {
|
|
53
|
+
success: zodResponse.success,
|
|
54
|
+
data: zodResponse.data,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export { formAsyncParse };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ZodType } from "zod";
|
|
2
2
|
type SuccessResponse<T extends FormParseProps> = {
|
|
3
3
|
success: true;
|
|
4
|
-
data: T[1] extends
|
|
4
|
+
data: T[1] extends ZodType<infer U> ? U : never;
|
|
5
5
|
};
|
|
6
6
|
type ErrorResponse = {
|
|
7
7
|
success: false;
|
|
@@ -14,7 +14,7 @@ type ErrorResponse = {
|
|
|
14
14
|
};
|
|
15
15
|
type FormParseProps = [formData: {
|
|
16
16
|
[k: string]: any;
|
|
17
|
-
}, schema:
|
|
17
|
+
}, schema: ZodType];
|
|
18
18
|
type FormParseReturnType<T extends FormParseProps> = SuccessResponse<T> | ErrorResponse;
|
|
19
19
|
/**
|
|
20
20
|
* Parses form data using a Zod schema and returns the result.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAqB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -39,10 +39,9 @@
|
|
|
39
39
|
function formParse([formData, schema,]) {
|
|
40
40
|
const zodResponse = schema.safeParse(formData);
|
|
41
41
|
if (zodResponse.success === false) {
|
|
42
|
-
const errorsObject = Object.fromEntries(zodResponse.error.
|
|
43
|
-
item.path.join("."),
|
|
44
|
-
|
|
45
|
-
]));
|
|
42
|
+
const errorsObject = Object.fromEntries(zodResponse.error.issues.map((item) => {
|
|
43
|
+
return [item.path.join("."), item.message];
|
|
44
|
+
}));
|
|
46
45
|
return {
|
|
47
46
|
success: zodResponse.success,
|
|
48
47
|
fieldErrors: errorsObject,
|
|
@@ -50,7 +49,10 @@ function formParse([formData, schema,]) {
|
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
51
|
else {
|
|
53
|
-
return {
|
|
52
|
+
return {
|
|
53
|
+
success: zodResponse.success,
|
|
54
|
+
data: zodResponse.data,
|
|
55
|
+
};
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
export { formParse };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCaller.d.ts","sourceRoot":"","sources":["../../src/services/getCaller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getCaller.d.ts","sourceRoot":"","sources":["../../src/services/getCaller.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AAEH,iBAAS,SAAS;;;EAiEjB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import { DebugService } from "./debugService";
|
|
2
3
|
/**
|
|
3
4
|
* Retrieves information about the caller of the current function.
|
|
4
5
|
*
|
|
@@ -15,51 +16,45 @@ function getCaller() {
|
|
|
15
16
|
const err = new Error();
|
|
16
17
|
const stack = err.stack || "";
|
|
17
18
|
const stackLines = stack.split("\n").map((line) => line.trim());
|
|
18
|
-
|
|
19
|
-
// The second line is this function (getCaller)
|
|
20
|
-
// The third line should be the direct caller
|
|
21
|
-
// We start from 2 because indexes are zero-based
|
|
19
|
+
const ignoreFiles = DebugService.ignoreFiles;
|
|
22
20
|
let callerIndex = 2;
|
|
23
|
-
// Ignore internal or infrastructure lines if necessary
|
|
24
21
|
while (callerIndex < stackLines.length &&
|
|
25
22
|
(stackLines[callerIndex].includes("node:internal") ||
|
|
26
23
|
stackLines[callerIndex].includes("/node_modules/"))) {
|
|
27
24
|
callerIndex++;
|
|
28
25
|
}
|
|
26
|
+
if (ignoreFiles.length > 0) {
|
|
27
|
+
while (callerIndex < stackLines.length &&
|
|
28
|
+
ignoreFiles.some((ignoreFile) => stackLines[callerIndex].includes(ignoreFile))) {
|
|
29
|
+
callerIndex++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
29
32
|
const callerLine = stackLines[callerIndex] || "";
|
|
30
33
|
let functionName = "Unknown function";
|
|
31
34
|
let callerInfo = "Unknown caller";
|
|
32
|
-
// Default for named functions: "at functionName (file:line:column)"
|
|
33
35
|
const namedFunctionMatch = callerLine.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
|
|
34
36
|
if (namedFunctionMatch) {
|
|
35
37
|
functionName = namedFunctionMatch[1];
|
|
36
38
|
callerInfo = namedFunctionMatch[2];
|
|
37
39
|
}
|
|
38
|
-
// Default for anonymous functions or methods: "at file:line:column"
|
|
39
40
|
else {
|
|
40
41
|
const anonymousFunctionMatch = callerLine.match(/at\s+(.+)/);
|
|
41
42
|
if (anonymousFunctionMatch) {
|
|
42
43
|
callerInfo = anonymousFunctionMatch[1];
|
|
43
|
-
// Tenta extrair nome da função de padrões como Object.method ou Class.method
|
|
44
44
|
const objectMethodMatch = callerInfo.match(/at\s+([^(\s]+)\s+/);
|
|
45
45
|
if (objectMethodMatch && objectMethodMatch[1] !== "new") {
|
|
46
46
|
functionName = objectMethodMatch[1];
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
// Handles file paths
|
|
51
50
|
if (callerInfo.includes("(")) {
|
|
52
51
|
callerInfo = callerInfo.substring(callerInfo.indexOf("(") + 1, callerInfo.lastIndexOf(")"));
|
|
53
52
|
}
|
|
54
|
-
// Remove the line:column part of the file path
|
|
55
53
|
callerInfo = callerInfo.split(":").slice(0, -2).join(":");
|
|
56
|
-
// Make the path relative to the project
|
|
57
54
|
try {
|
|
58
55
|
callerInfo = path.relative(projectRoot, callerInfo);
|
|
59
56
|
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
// If it fails to relativize, use the original path
|
|
62
|
-
}
|
|
57
|
+
catch (e) { }
|
|
63
58
|
return { functionName, callerInfo };
|
|
64
59
|
}
|
|
65
60
|
export { getCaller };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measureRouteExecution.d.ts","sourceRoot":"","sources":["../../src/services/measureRouteExecution.ts"],"names":[],"mappings":"AAAA,iBAAS,qBAAqB,CAAC,CAAC,GAAG,OAAO,EACxC,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,IAEG,OAAO,GAAG,KAAG,OAAO,CAAC,CAAC,CAAC,CAyB9D;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function measureRouteExecution(handler) {
|
|
2
|
+
return async function measuredHandler(props) {
|
|
3
|
+
const startTime = performance.now();
|
|
4
|
+
try {
|
|
5
|
+
const result = await handler(props);
|
|
6
|
+
const url = new URL(props.request.url);
|
|
7
|
+
const endTime = performance.now();
|
|
8
|
+
const duration = (endTime - startTime).toFixed(2);
|
|
9
|
+
console.log({
|
|
10
|
+
domain: url.hostname,
|
|
11
|
+
pathname: url.pathname,
|
|
12
|
+
method: props.request.method,
|
|
13
|
+
duration,
|
|
14
|
+
});
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
const endTime = performance.now();
|
|
19
|
+
console.error("");
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export { measureRouteExecution };
|