@arkyn/server 3.0.1-beta.4 → 3.0.1-beta.41
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 +7 -8
- package/dist/api/makeRequest.d.ts +1 -1
- package/dist/api/makeRequest.d.ts.map +1 -1
- package/dist/api/makeRequest.js +3 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/mapper/arkynLogRequestMapper.js +2 -2
- package/dist/{config/apiInstance.d.ts → services/apiService.d.ts} +21 -21
- package/dist/{config/apiInstance.d.ts.map → services/apiService.d.ts.map} +1 -1
- package/dist/{config/apiInstance.js → services/apiService.js} +18 -18
- package/dist/{config/arkynLogInstance.d.ts → services/arkynLogService.d.ts} +5 -5
- package/dist/services/arkynLogService.d.ts.map +1 -0
- package/dist/{config/arkynLogInstance.js → services/arkynLogService.js} +4 -5
- package/dist/services/formParse.d.ts +3 -3
- package/dist/services/formParse.d.ts.map +1 -1
- package/dist/services/formParse.js +8 -5
- package/dist/services/getCaller.d.ts.map +1 -1
- package/dist/services/getCaller.js +9 -14
- package/dist/services/httpDebug.d.ts +40 -1
- package/dist/services/httpDebug.d.ts.map +1 -1
- package/dist/services/httpDebug.js +42 -1
- 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 +3 -3
- package/dist/services/schemaValidator.d.ts.map +1 -1
- package/dist/services/schemaValidator.js +1 -1
- package/package.json +31 -20
- package/src/api/arkynLogRequest.ts +20 -14
- package/src/api/makeRequest.ts +3 -5
- package/src/index.ts +3 -5
- package/src/mapper/arkynLogRequestMapper.ts +2 -2
- package/src/{config/apiInstance.ts → services/apiService.ts} +20 -20
- package/src/{config/arkynLogInstance.ts → services/arkynLogService.ts} +4 -9
- package/src/services/formParse.ts +11 -8
- package/src/services/getCaller.ts +15 -16
- package/src/services/httpDebug.ts +44 -1
- package/src/services/measureRouteExecution.ts +31 -0
- package/src/services/schemaValidator.ts +4 -4
- package/dist/config/arkynLogInstance.d.ts.map +0 -1
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type
|
|
1
|
+
type ApiServiceConstructorProps = {
|
|
2
2
|
baseUrl: string;
|
|
3
3
|
baseHeaders?: HeadersInit;
|
|
4
4
|
baseToken?: string | null;
|
|
@@ -15,18 +15,18 @@ type ApiRequestDataWithBodyProps = {
|
|
|
15
15
|
/**
|
|
16
16
|
* Class representing an API instance to handle HTTP requests with base configurations.
|
|
17
17
|
*/
|
|
18
|
-
declare class
|
|
18
|
+
declare class ApiService {
|
|
19
19
|
private baseUrl;
|
|
20
20
|
private baseHeaders?;
|
|
21
21
|
private baseToken?;
|
|
22
22
|
/**
|
|
23
|
-
* Creates an instance of
|
|
23
|
+
* Creates an instance of ApiService.
|
|
24
24
|
* @param props - The configuration properties for the API instance.
|
|
25
25
|
* @param props.baseUrl - The base URL for the API.
|
|
26
26
|
* @param props.baseHeaders - Optional base headers to include in all requests.
|
|
27
27
|
* @param props.baseToken - Optional base token for authorization.
|
|
28
28
|
*/
|
|
29
|
-
constructor(props:
|
|
29
|
+
constructor(props: ApiServiceConstructorProps);
|
|
30
30
|
/**
|
|
31
31
|
* Generates the full URL by appending the route to the base URL.
|
|
32
32
|
* @param route - The route to append to the base URL.
|
|
@@ -41,40 +41,40 @@ declare class ApiInstance {
|
|
|
41
41
|
*/
|
|
42
42
|
private generateHeaders;
|
|
43
43
|
/**
|
|
44
|
-
* Sends a
|
|
45
|
-
* @param route - The API route to send the
|
|
44
|
+
* Sends a get request to the specified route.
|
|
45
|
+
* @param route - The API route to send the get request to.
|
|
46
46
|
* @param data - The request data, including optional headers and token.
|
|
47
47
|
* @returns The API response data.
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
get(route: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
50
50
|
/**
|
|
51
|
-
* Sends a
|
|
52
|
-
* @param route - The API route to send the
|
|
51
|
+
* Sends a post request to the specified route.
|
|
52
|
+
* @param route - The API route to send the post request to.
|
|
53
53
|
* @param data - The request data, including body, optional headers, and token.
|
|
54
54
|
* @returns The API response data.
|
|
55
55
|
*/
|
|
56
|
-
|
|
56
|
+
post(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
57
57
|
/**
|
|
58
|
-
* Sends a
|
|
59
|
-
* @param route - The API route to send the
|
|
58
|
+
* Sends a put request to the specified route.
|
|
59
|
+
* @param route - The API route to send the put request to.
|
|
60
60
|
* @param data - The request data, including body, optional headers, and token.
|
|
61
61
|
* @returns The API response data.
|
|
62
62
|
*/
|
|
63
|
-
|
|
63
|
+
put(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
64
64
|
/**
|
|
65
|
-
* Sends a
|
|
66
|
-
* @param route - The API route to send the
|
|
65
|
+
* Sends a patch request to the specified route.
|
|
66
|
+
* @param route - The API route to send the patch request to.
|
|
67
67
|
* @param data - The request data, including body, optional headers, and token.
|
|
68
68
|
* @returns The API response data.
|
|
69
69
|
*/
|
|
70
|
-
|
|
70
|
+
patch(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
71
71
|
/**
|
|
72
|
-
* Sends a
|
|
73
|
-
* @param route - The API route to send the
|
|
72
|
+
* Sends a delete request to the specified route.
|
|
73
|
+
* @param route - The API route to send the delete request to.
|
|
74
74
|
* @param data - The request data, including body, optional headers, and token.
|
|
75
75
|
* @returns The API response data.
|
|
76
76
|
*/
|
|
77
|
-
|
|
77
|
+
delete(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
|
|
78
78
|
}
|
|
79
|
-
export {
|
|
80
|
-
//# sourceMappingURL=
|
|
79
|
+
export { ApiService };
|
|
80
|
+
//# sourceMappingURL=apiService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../src/services/apiService.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,UAAU;IACd,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,UAAU,EAAE,CAAC"}
|
|
@@ -6,12 +6,12 @@ import { putRequest } from "../api/putRequest";
|
|
|
6
6
|
/**
|
|
7
7
|
* Class representing an API instance to handle HTTP requests with base configurations.
|
|
8
8
|
*/
|
|
9
|
-
class
|
|
9
|
+
class ApiService {
|
|
10
10
|
baseUrl;
|
|
11
11
|
baseHeaders;
|
|
12
12
|
baseToken;
|
|
13
13
|
/**
|
|
14
|
-
* Creates an instance of
|
|
14
|
+
* Creates an instance of ApiService.
|
|
15
15
|
* @param props - The configuration properties for the API instance.
|
|
16
16
|
* @param props.baseUrl - The base URL for the API.
|
|
17
17
|
* @param props.baseHeaders - Optional base headers to include in all requests.
|
|
@@ -49,63 +49,63 @@ class ApiInstance {
|
|
|
49
49
|
return headers;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
* Sends a
|
|
53
|
-
* @param route - The API route to send the
|
|
52
|
+
* Sends a get request to the specified route.
|
|
53
|
+
* @param route - The API route to send the get request to.
|
|
54
54
|
* @param data - The request data, including optional headers and token.
|
|
55
55
|
* @returns The API response data.
|
|
56
56
|
*/
|
|
57
|
-
async
|
|
57
|
+
async get(route, data) {
|
|
58
58
|
const url = this.generateURL(route);
|
|
59
59
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
60
60
|
return await getRequest(url, headers);
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* Sends a
|
|
64
|
-
* @param route - The API route to send the
|
|
63
|
+
* Sends a post request to the specified route.
|
|
64
|
+
* @param route - The API route to send the post request to.
|
|
65
65
|
* @param data - The request data, including body, optional headers, and token.
|
|
66
66
|
* @returns The API response data.
|
|
67
67
|
*/
|
|
68
|
-
async
|
|
68
|
+
async post(route, data) {
|
|
69
69
|
const url = this.generateURL(route);
|
|
70
70
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
71
71
|
const body = data?.body;
|
|
72
72
|
return await postRequest(url, headers, body);
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
|
-
* Sends a
|
|
76
|
-
* @param route - The API route to send the
|
|
75
|
+
* Sends a put request to the specified route.
|
|
76
|
+
* @param route - The API route to send the put request to.
|
|
77
77
|
* @param data - The request data, including body, optional headers, and token.
|
|
78
78
|
* @returns The API response data.
|
|
79
79
|
*/
|
|
80
|
-
async
|
|
80
|
+
async put(route, data) {
|
|
81
81
|
const url = this.generateURL(route);
|
|
82
82
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
83
83
|
const body = data?.body;
|
|
84
84
|
return await putRequest(url, headers, body);
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
|
-
* Sends a
|
|
88
|
-
* @param route - The API route to send the
|
|
87
|
+
* Sends a patch request to the specified route.
|
|
88
|
+
* @param route - The API route to send the patch request to.
|
|
89
89
|
* @param data - The request data, including body, optional headers, and token.
|
|
90
90
|
* @returns The API response data.
|
|
91
91
|
*/
|
|
92
|
-
async
|
|
92
|
+
async patch(route, data) {
|
|
93
93
|
const url = this.generateURL(route);
|
|
94
94
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
95
95
|
const body = data?.body;
|
|
96
96
|
return await patchRequest(url, headers, body);
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
|
-
* Sends a
|
|
100
|
-
* @param route - The API route to send the
|
|
99
|
+
* Sends a delete request to the specified route.
|
|
100
|
+
* @param route - The API route to send the delete request to.
|
|
101
101
|
* @param data - The request data, including body, optional headers, and token.
|
|
102
102
|
* @returns The API response data.
|
|
103
103
|
*/
|
|
104
|
-
async
|
|
104
|
+
async delete(route, data) {
|
|
105
105
|
const url = this.generateURL(route);
|
|
106
106
|
const headers = this.generateHeaders(data?.headers || {}, data?.token);
|
|
107
107
|
const body = data?.body;
|
|
108
108
|
return await deleteRequest(url, headers, body);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
export {
|
|
111
|
+
export { ApiService };
|
|
@@ -9,11 +9,11 @@ type SetArkynConfigProps = {
|
|
|
9
9
|
arkynLogBaseApiUrl?: 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,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,eAAe;IACnB,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,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
|
|
@@ -23,7 +23,6 @@ class ArkynLogInstance {
|
|
|
23
23
|
let arkynLogBaseApiUrl = arkynConfig.arkynLogBaseApiUrl || defaultArkynURL;
|
|
24
24
|
arkynLogBaseApiUrl =
|
|
25
25
|
arkynLogBaseApiUrl + "/http-traffic-records/:trafficSourceId";
|
|
26
|
-
arkynLogBaseApiUrl.replace(":trafficSourceId", arkynConfig.arkynTrafficSourceId);
|
|
27
26
|
this.arkynConfig = {
|
|
28
27
|
arkynTrafficSourceId: arkynConfig.arkynTrafficSourceId,
|
|
29
28
|
arkynUserToken: arkynConfig.arkynUserToken,
|
|
@@ -31,7 +30,7 @@ class ArkynLogInstance {
|
|
|
31
30
|
};
|
|
32
31
|
}
|
|
33
32
|
/**
|
|
34
|
-
* Retrieves the current arkyn configuration for the
|
|
33
|
+
* Retrieves the current arkyn configuration for the ArkynLogService.
|
|
35
34
|
*
|
|
36
35
|
* @returns {ArkynConfigProps | undefined} The current arkyn configuration if set,
|
|
37
36
|
* or `undefined` if no configuration has been initialized.
|
|
@@ -47,4 +46,4 @@ class ArkynLogInstance {
|
|
|
47
46
|
this.arkynConfig = undefined;
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
|
-
export {
|
|
49
|
+
export { ArkynLogService };
|
|
@@ -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,CAsB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -39,10 +39,10 @@
|
|
|
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
|
-
|
|
44
|
-
item.message
|
|
45
|
-
|
|
42
|
+
const errorsObject = Object.fromEntries(zodResponse.error.issues.map((item) => {
|
|
43
|
+
console.log(item);
|
|
44
|
+
return [item.path.join("."), item.message];
|
|
45
|
+
}));
|
|
46
46
|
return {
|
|
47
47
|
success: zodResponse.success,
|
|
48
48
|
fieldErrors: errorsObject,
|
|
@@ -50,7 +50,10 @@ function formParse([formData, schema,]) {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
return {
|
|
53
|
+
return {
|
|
54
|
+
success: zodResponse.success,
|
|
55
|
+
data: zodResponse.data,
|
|
56
|
+
};
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
59
|
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;;;EA+DjB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import { HttpDebugService } from "./httpDebug";
|
|
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 ignoreFile = HttpDebugService.ignoreFile;
|
|
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 (ignoreFile) {
|
|
27
|
+
while (callerIndex < stackLines.length &&
|
|
28
|
+
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 };
|
|
@@ -1,3 +1,42 @@
|
|
|
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 HttpDebugService {
|
|
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 ignoreFile?: 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
|
+
* HttpDebugService.setIgnoreFile("httpAdapter.ts");
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
static setIgnoreFile(file: string): void;
|
|
39
|
+
}
|
|
1
40
|
/**
|
|
2
41
|
* Logs debug information to the console when in development mode or when the
|
|
3
42
|
* `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
|
|
@@ -31,5 +70,5 @@
|
|
|
31
70
|
* ```
|
|
32
71
|
*/
|
|
33
72
|
declare function httpDebug(name: string, body: any, cause?: any): void;
|
|
34
|
-
export { httpDebug };
|
|
73
|
+
export { httpDebug, HttpDebugService };
|
|
35
74
|
//# sourceMappingURL=httpDebug.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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
|
+
{"version":3,"file":"httpDebug.d.ts","sourceRoot":"","sources":["../../src/services/httpDebug.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,cAAM,gBAAgB;IACpB;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM;CAGlC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,QAuBtD;AAED,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,4 +1,45 @@
|
|
|
1
1
|
import { getCaller } from "../services/getCaller";
|
|
2
|
+
/**
|
|
3
|
+
* Service for managing HTTP debug configuration and behavior.
|
|
4
|
+
*
|
|
5
|
+
* This service provides functionality to configure how the `getCaller` function
|
|
6
|
+
* identifies the actual caller in the stack trace by allowing specific files
|
|
7
|
+
* to be ignored during stack trace analysis.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Configure to ignore httpAdapter.ts in stack traces
|
|
12
|
+
* HttpDebugService.setIgnoreFile("httpAdapter.ts");
|
|
13
|
+
*
|
|
14
|
+
* // Now when httpDebug is called from within httpAdapter.ts,
|
|
15
|
+
* // it will show the actual caller (e.g., cart.ts) instead
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
class HttpDebugService {
|
|
19
|
+
/**
|
|
20
|
+
* The name of the file to ignore when analyzing the stack trace.
|
|
21
|
+
* When set, the `getCaller` function will skip stack frames containing this file name.
|
|
22
|
+
*/
|
|
23
|
+
static ignoreFile;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the file name to be ignored during stack trace analysis.
|
|
26
|
+
*
|
|
27
|
+
* This method configures the debug service to skip specific files when
|
|
28
|
+
* determining the actual caller of a function. This is useful when you have
|
|
29
|
+
* adapter or wrapper functions that you want to be transparent in the debug output.
|
|
30
|
+
*
|
|
31
|
+
* @param file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Ignore the HTTP adapter file so debug shows the actual business logic caller
|
|
36
|
+
* HttpDebugService.setIgnoreFile("httpAdapter.ts");
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
static setIgnoreFile(file) {
|
|
40
|
+
this.ignoreFile = file;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
2
43
|
/**
|
|
3
44
|
* Logs debug information to the console when in development mode or when the
|
|
4
45
|
* `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
|
|
@@ -49,4 +90,4 @@ function httpDebug(name, body, cause) {
|
|
|
49
90
|
console.log(consoleData);
|
|
50
91
|
}
|
|
51
92
|
}
|
|
52
|
-
export { httpDebug };
|
|
93
|
+
export { httpDebug, HttpDebugService };
|
|
@@ -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 };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare class SchemaValidator<T extends
|
|
1
|
+
import { ZodType, z } from "zod";
|
|
2
|
+
declare class SchemaValidator<T extends ZodType> {
|
|
3
3
|
readonly schema: T;
|
|
4
4
|
functionName: string;
|
|
5
5
|
callerInfo: string;
|
|
6
6
|
constructor(schema: T);
|
|
7
7
|
isValid(data: any): boolean;
|
|
8
|
-
safeValidate(data: any): z.
|
|
8
|
+
safeValidate(data: any): z.ZodSafeParseResult<z.infer<T>>;
|
|
9
9
|
validate(data: any): z.infer<T>;
|
|
10
10
|
formValidate(data: any, message?: string): z.infer<T>;
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaValidator.d.ts","sourceRoot":"","sources":["../../src/services/schemaValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"schemaValidator.d.ts","sourceRoot":"","sources":["../../src/services/schemaValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiBjC,cAAM,eAAe,CAAC,CAAC,SAAS,OAAO;IAIzB,QAAQ,CAAC,MAAM,EAAE,CAAC;IAH9B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;gBAEE,MAAM,EAAE,CAAC;IAM9B,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO;IAI3B,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAIzD,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAQ/B,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;CAoBtD;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,32 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkyn/server",
|
|
3
|
-
"version": "3.0.1-beta.
|
|
3
|
+
"version": "3.0.1-beta.41",
|
|
4
4
|
"author": "Arkyn | Lucas Gonçalves",
|
|
5
|
-
"main": "./dist/
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
6
|
"module": "./src/index.ts",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"@aws-sdk/client-s3": "^3.782.0",
|
|
10
|
-
"@mjackson/multipart-parser": "^0.8.2",
|
|
11
|
-
"sharp": "^0.33.5",
|
|
12
|
-
"zod": "^3.24.2"
|
|
13
|
-
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"bun-types": "latest",
|
|
16
|
-
"vitest": "^3.1.1",
|
|
17
|
-
"typescript": "^5.8.3"
|
|
18
|
-
},
|
|
19
|
-
"peerDependencies": {
|
|
20
|
-
"@react-router/node": ">=7.6.0"
|
|
21
|
-
},
|
|
22
|
-
"description": "Server-side utilities for projects.",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"types": "./src/index.ts",
|
|
23
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": "https://github.com/Lucas-Eduardo-Goncalves/arkyn.git",
|
|
26
|
+
"directory": "packages/server"
|
|
27
|
+
},
|
|
24
28
|
"scripts": {
|
|
25
29
|
"clean": "rm -rf dist",
|
|
26
30
|
"build": "bun run clean && bunx tsc --project tsconfig.json",
|
|
27
31
|
"test": "vitest --config vitest.config.ts",
|
|
28
32
|
"typecheck": "bunx tsc --project tsconfig.json --noEmit"
|
|
29
33
|
},
|
|
30
|
-
"
|
|
31
|
-
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@arkyn/shared": "*",
|
|
36
|
+
"zod": "^4.0.17"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"bun-types": "latest",
|
|
40
|
+
"vitest": "^3.2.4",
|
|
41
|
+
"typescript": "^5.9.2"
|
|
42
|
+
}
|
|
32
43
|
}
|