@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.
Files changed (221) hide show
  1. package/README.md +368 -65
  2. package/dist/bundle.js +1518 -0
  3. package/dist/bundle.umd.cjs +5 -0
  4. package/dist/{api/arkynLogRequest.d.ts → http/api/_logRequest.d.ts} +22 -19
  5. package/dist/{api/arkynLogRequest.d.ts.map → http/api/_logRequest.d.ts.map} +1 -1
  6. package/dist/http/api/_logRequest.js +88 -0
  7. package/dist/http/api/_makeRequest.d.ts +61 -0
  8. package/dist/http/api/_makeRequest.d.ts.map +1 -0
  9. package/dist/{api/makeRequest.js → http/api/_makeRequest.js} +33 -20
  10. package/dist/http/api/deleteRequest.d.ts +17 -0
  11. package/dist/http/api/deleteRequest.d.ts.map +1 -0
  12. package/dist/http/api/deleteRequest.js +18 -0
  13. package/dist/http/api/getRequest.d.ts +16 -0
  14. package/dist/http/api/getRequest.d.ts.map +1 -0
  15. package/dist/http/api/getRequest.js +17 -0
  16. package/dist/http/api/patchRequest.d.ts +17 -0
  17. package/dist/http/api/patchRequest.d.ts.map +1 -0
  18. package/dist/http/api/patchRequest.js +18 -0
  19. package/dist/http/api/postRequest.d.ts +17 -0
  20. package/dist/http/api/postRequest.d.ts.map +1 -0
  21. package/dist/http/api/postRequest.js +18 -0
  22. package/dist/http/api/putRequest.d.ts +17 -0
  23. package/dist/http/api/putRequest.d.ts.map +1 -0
  24. package/dist/http/api/putRequest.js +18 -0
  25. package/dist/http/badResponses/_badResponse.d.ts +22 -0
  26. package/dist/http/badResponses/_badResponse.d.ts.map +1 -0
  27. package/dist/http/badResponses/_badResponse.js +51 -0
  28. package/dist/http/badResponses/badGateway.d.ts +6 -9
  29. package/dist/http/badResponses/badGateway.d.ts.map +1 -1
  30. package/dist/http/badResponses/badGateway.js +12 -14
  31. package/dist/http/badResponses/badRequest.d.ts +6 -9
  32. package/dist/http/badResponses/badRequest.d.ts.map +1 -1
  33. package/dist/http/badResponses/badRequest.js +12 -14
  34. package/dist/http/badResponses/conflict.d.ts +6 -9
  35. package/dist/http/badResponses/conflict.d.ts.map +1 -1
  36. package/dist/http/badResponses/conflict.js +12 -14
  37. package/dist/http/badResponses/forbidden.d.ts +6 -9
  38. package/dist/http/badResponses/forbidden.d.ts.map +1 -1
  39. package/dist/http/badResponses/forbidden.js +12 -14
  40. package/dist/http/badResponses/notFound.d.ts +6 -9
  41. package/dist/http/badResponses/notFound.d.ts.map +1 -1
  42. package/dist/http/badResponses/notFound.js +12 -14
  43. package/dist/http/badResponses/notImplemented.d.ts +6 -9
  44. package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
  45. package/dist/http/badResponses/notImplemented.js +12 -14
  46. package/dist/http/badResponses/serverError.d.ts +6 -9
  47. package/dist/http/badResponses/serverError.d.ts.map +1 -1
  48. package/dist/http/badResponses/serverError.js +12 -14
  49. package/dist/http/badResponses/unauthorized.d.ts +4 -7
  50. package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
  51. package/dist/http/badResponses/unauthorized.js +10 -12
  52. package/dist/http/badResponses/unprocessableEntity.d.ts +15 -19
  53. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
  54. package/dist/http/badResponses/unprocessableEntity.js +18 -21
  55. package/dist/http/successResponses/_successResponse.d.ts +33 -0
  56. package/dist/http/successResponses/_successResponse.d.ts.map +1 -0
  57. package/dist/http/successResponses/_successResponse.js +66 -0
  58. package/dist/http/successResponses/created.d.ts +9 -19
  59. package/dist/http/successResponses/created.d.ts.map +1 -1
  60. package/dist/http/successResponses/created.js +16 -25
  61. package/dist/http/successResponses/found.d.ts +10 -23
  62. package/dist/http/successResponses/found.d.ts.map +1 -1
  63. package/dist/http/successResponses/found.js +17 -29
  64. package/dist/http/successResponses/noContent.d.ts +6 -13
  65. package/dist/http/successResponses/noContent.d.ts.map +1 -1
  66. package/dist/http/successResponses/noContent.js +12 -17
  67. package/dist/http/successResponses/success.d.ts +9 -19
  68. package/dist/http/successResponses/success.d.ts.map +1 -1
  69. package/dist/http/successResponses/success.js +16 -25
  70. package/dist/http/successResponses/updated.d.ts +9 -19
  71. package/dist/http/successResponses/updated.d.ts.map +1 -1
  72. package/dist/http/successResponses/updated.js +16 -25
  73. package/dist/index.d.ts +19 -10
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +22 -13
  76. package/dist/services/apiService.d.ts +63 -0
  77. package/dist/services/apiService.d.ts.map +1 -0
  78. package/dist/services/apiService.js +158 -0
  79. package/dist/services/debugService.d.ts +69 -0
  80. package/dist/services/debugService.d.ts.map +1 -0
  81. package/dist/services/debugService.js +114 -0
  82. package/dist/services/logMapperService.d.ts +86 -0
  83. package/dist/services/logMapperService.d.ts.map +1 -0
  84. package/dist/services/logMapperService.js +68 -0
  85. package/dist/services/logService.d.ts +38 -0
  86. package/dist/services/logService.d.ts.map +1 -0
  87. package/dist/services/logService.js +40 -0
  88. package/dist/{services → utilities}/decodeRequestBody.d.ts +3 -4
  89. package/dist/utilities/decodeRequestBody.d.ts.map +1 -0
  90. package/dist/{services → utilities}/decodeRequestBody.js +5 -5
  91. package/dist/{services/decodeErrorMessageFromRequest.d.ts → utilities/decodeRequestErrorMessage.d.ts} +6 -6
  92. package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -0
  93. package/dist/{services/decodeErrorMessageFromRequest.js → utilities/decodeRequestErrorMessage.js} +5 -5
  94. package/dist/utilities/errorHandler.d.ts +50 -0
  95. package/dist/utilities/errorHandler.d.ts.map +1 -0
  96. package/dist/{services → utilities}/errorHandler.js +34 -28
  97. package/dist/utilities/flushDebugLogs.d.ts +46 -0
  98. package/dist/utilities/flushDebugLogs.d.ts.map +1 -0
  99. package/dist/utilities/flushDebugLogs.js +59 -0
  100. package/dist/utilities/formAsyncParse.d.ts +59 -0
  101. package/dist/utilities/formAsyncParse.d.ts.map +1 -0
  102. package/dist/utilities/formAsyncParse.js +58 -0
  103. package/dist/{services → utilities}/formParse.d.ts +6 -6
  104. package/dist/utilities/formParse.d.ts.map +1 -0
  105. package/dist/{services → utilities}/formParse.js +10 -8
  106. package/dist/{services → utilities}/getScopedParams.d.ts +3 -4
  107. package/dist/utilities/getScopedParams.d.ts.map +1 -0
  108. package/dist/{services → utilities}/getScopedParams.js +4 -4
  109. package/dist/utilities/schemaValidator.d.ts +146 -0
  110. package/dist/utilities/schemaValidator.d.ts.map +1 -0
  111. package/dist/utilities/schemaValidator.js +191 -0
  112. package/dist/validations/validateCep.d.ts +19 -0
  113. package/dist/validations/validateCep.d.ts.map +1 -0
  114. package/dist/validations/validateCep.js +27 -0
  115. package/dist/validations/validateCnpj.d.ts +21 -0
  116. package/dist/validations/validateCnpj.d.ts.map +1 -0
  117. package/dist/validations/validateCnpj.js +59 -0
  118. package/dist/validations/validateCpf.d.ts +23 -0
  119. package/dist/validations/validateCpf.d.ts.map +1 -0
  120. package/dist/validations/validateCpf.js +61 -0
  121. package/dist/validations/validateDate.d.ts +27 -0
  122. package/dist/validations/validateDate.d.ts.map +1 -0
  123. package/dist/validations/validateDate.js +55 -0
  124. package/dist/validations/validateEmail.d.ts +21 -0
  125. package/dist/validations/validateEmail.d.ts.map +1 -0
  126. package/dist/validations/validateEmail.js +111 -0
  127. package/dist/validations/validatePassword.d.ts +20 -0
  128. package/dist/validations/validatePassword.d.ts.map +1 -0
  129. package/dist/validations/validatePassword.js +34 -0
  130. package/dist/validations/validatePhone.d.ts +28 -0
  131. package/dist/validations/validatePhone.d.ts.map +1 -0
  132. package/dist/validations/validatePhone.js +44 -0
  133. package/dist/validations/validateRg.d.ts +21 -0
  134. package/dist/validations/validateRg.d.ts.map +1 -0
  135. package/dist/validations/validateRg.js +31 -0
  136. package/package.json +34 -18
  137. package/dist/api/arkynLogRequest.js +0 -82
  138. package/dist/api/deleteRequest.d.ts +0 -13
  139. package/dist/api/deleteRequest.d.ts.map +0 -1
  140. package/dist/api/deleteRequest.js +0 -14
  141. package/dist/api/getRequest.d.ts +0 -12
  142. package/dist/api/getRequest.d.ts.map +0 -1
  143. package/dist/api/getRequest.js +0 -13
  144. package/dist/api/makeRequest.d.ts +0 -38
  145. package/dist/api/makeRequest.d.ts.map +0 -1
  146. package/dist/api/patchRequest.d.ts +0 -13
  147. package/dist/api/patchRequest.d.ts.map +0 -1
  148. package/dist/api/patchRequest.js +0 -14
  149. package/dist/api/postRequest.d.ts +0 -13
  150. package/dist/api/postRequest.d.ts.map +0 -1
  151. package/dist/api/postRequest.js +0 -14
  152. package/dist/api/putRequest.d.ts +0 -13
  153. package/dist/api/putRequest.d.ts.map +0 -1
  154. package/dist/api/putRequest.js +0 -14
  155. package/dist/config/apiInstance.d.ts +0 -80
  156. package/dist/config/apiInstance.d.ts.map +0 -1
  157. package/dist/config/apiInstance.js +0 -111
  158. package/dist/config/arkynLogInstance.d.ts +0 -44
  159. package/dist/config/arkynLogInstance.d.ts.map +0 -1
  160. package/dist/config/arkynLogInstance.js +0 -49
  161. package/dist/mapper/arkynLogRequestMapper.d.ts +0 -30
  162. package/dist/mapper/arkynLogRequestMapper.d.ts.map +0 -1
  163. package/dist/mapper/arkynLogRequestMapper.js +0 -44
  164. package/dist/services/decodeErrorMessageFromRequest.d.ts.map +0 -1
  165. package/dist/services/decodeRequestBody.d.ts.map +0 -1
  166. package/dist/services/errorHandler.d.ts +0 -44
  167. package/dist/services/errorHandler.d.ts.map +0 -1
  168. package/dist/services/formParse.d.ts.map +0 -1
  169. package/dist/services/getCaller.d.ts +0 -17
  170. package/dist/services/getCaller.d.ts.map +0 -1
  171. package/dist/services/getCaller.js +0 -65
  172. package/dist/services/getScopedParams.d.ts.map +0 -1
  173. package/dist/services/httpDebug.d.ts +0 -35
  174. package/dist/services/httpDebug.d.ts.map +0 -1
  175. package/dist/services/httpDebug.js +0 -52
  176. package/dist/services/measureRouteExecution.d.ts +0 -3
  177. package/dist/services/measureRouteExecution.d.ts.map +0 -1
  178. package/dist/services/measureRouteExecution.js +0 -24
  179. package/dist/services/schemaValidator.d.ts +0 -13
  180. package/dist/services/schemaValidator.d.ts.map +0 -1
  181. package/dist/services/schemaValidator.js +0 -51
  182. package/dist/types/ApiResponseDTO.d.ts +0 -17
  183. package/dist/types/ApiResponseDTO.d.ts.map +0 -1
  184. package/dist/types/ApiResponseDTO.js +0 -1
  185. package/src/api/arkynLogRequest.ts +0 -118
  186. package/src/api/deleteRequest.ts +0 -22
  187. package/src/api/getRequest.ts +0 -20
  188. package/src/api/makeRequest.ts +0 -118
  189. package/src/api/patchRequest.ts +0 -22
  190. package/src/api/postRequest.ts +0 -22
  191. package/src/api/putRequest.ts +0 -22
  192. package/src/config/apiInstance.ts +0 -148
  193. package/src/config/arkynLogInstance.ts +0 -70
  194. package/src/http/badResponses/badGateway.ts +0 -63
  195. package/src/http/badResponses/badRequest.ts +0 -63
  196. package/src/http/badResponses/conflict.ts +0 -63
  197. package/src/http/badResponses/forbidden.ts +0 -63
  198. package/src/http/badResponses/notFound.ts +0 -63
  199. package/src/http/badResponses/notImplemented.ts +0 -63
  200. package/src/http/badResponses/serverError.ts +0 -63
  201. package/src/http/badResponses/unauthorized.ts +0 -63
  202. package/src/http/badResponses/unprocessableEntity.ts +0 -79
  203. package/src/http/successResponses/created.ts +0 -64
  204. package/src/http/successResponses/found.ts +0 -67
  205. package/src/http/successResponses/noContent.ts +0 -42
  206. package/src/http/successResponses/success.ts +0 -64
  207. package/src/http/successResponses/updated.ts +0 -64
  208. package/src/index.ts +0 -31
  209. package/src/mapper/arkynLogRequestMapper.ts +0 -73
  210. package/src/services/decodeErrorMessageFromRequest.ts +0 -36
  211. package/src/services/decodeRequestBody.ts +0 -43
  212. package/src/services/errorHandler.ts +0 -99
  213. package/src/services/formParse.ts +0 -83
  214. package/src/services/getCaller.ts +0 -82
  215. package/src/services/getScopedParams.ts +0 -43
  216. package/src/services/httpDebug.ts +0 -61
  217. package/src/services/measureRouteExecution.ts +0 -31
  218. package/src/services/schemaValidator.ts +0 -66
  219. package/src/types/ApiResponseDTO.ts +0 -19
  220. package/tsconfig.json +0 -21
  221. package/vitest.config.ts +0 -5
@@ -0,0 +1,158 @@
1
+ import { deleteRequest } from "../http/api/deleteRequest";
2
+ import { getRequest } from "../http/api/getRequest";
3
+ import { patchRequest } from "../http/api/patchRequest";
4
+ import { postRequest } from "../http/api/postRequest";
5
+ import { putRequest } from "../http/api/putRequest";
6
+ import { flushDebugLogs } from "../utilities/flushDebugLogs";
7
+ class ApiService {
8
+ baseUrl;
9
+ baseHeaders;
10
+ baseToken;
11
+ enableDebug;
12
+ constructor(props) {
13
+ this.baseUrl = props.baseUrl;
14
+ this.baseHeaders = props.baseHeaders || undefined;
15
+ this.baseToken = props.baseToken || undefined;
16
+ this.enableDebug = props.enableDebug || false;
17
+ }
18
+ onDebug(endpoint, method, data) {
19
+ if (this.enableDebug) {
20
+ const debugs = [];
21
+ const json = (data) => JSON.stringify(data, null, 2);
22
+ debugs.push(`Base URL: ${this.baseUrl}`);
23
+ debugs.push(`Endpoint: ${endpoint}`);
24
+ debugs.push(`Status/Method: ${method} => ${data.status}`);
25
+ debugs.push(`Message: ${data.message}`);
26
+ if (data.headers)
27
+ debugs.push(`Headers: ${json(data.headers)}`);
28
+ if (data.body)
29
+ debugs.push(`Body: ${json(data.body)}`);
30
+ flushDebugLogs({ debugs, name: "ApiDebug", scheme: "yellow" });
31
+ }
32
+ }
33
+ generateHeaders(initHeaders, token) {
34
+ let headers = {};
35
+ if (this.baseToken)
36
+ headers = { Authorization: `Bearer ${this.baseToken}` };
37
+ if (this.baseHeaders)
38
+ headers = { ...headers, ...this.baseHeaders };
39
+ if (initHeaders)
40
+ headers = { ...headers, ...initHeaders };
41
+ if (token)
42
+ headers = { ...headers, Authorization: `Bearer ${token}` };
43
+ return headers;
44
+ }
45
+ /**
46
+ * Sends a get request to the specified endpoint.
47
+ * @param endpoint - The API endpoint to send the get request to.
48
+ * @param data - The request data, including optional headers and token.
49
+ * @returns The API response data.
50
+ */
51
+ async get(endpoint, data) {
52
+ const headers = this.generateHeaders(data?.headers || {}, data?.token);
53
+ const response = await getRequest({
54
+ url: this.baseUrl + endpoint,
55
+ urlParams: data?.urlParams || {},
56
+ headers,
57
+ });
58
+ this.onDebug(endpoint, "get", {
59
+ headers,
60
+ message: response.message,
61
+ status: response.status,
62
+ });
63
+ return response;
64
+ }
65
+ /**
66
+ * Sends a post request to the specified endpoint.
67
+ * @param endpoint - The API endpoint to send the post request to.
68
+ * @param data - The request data, including body, optional headers, and token.
69
+ * @returns The API response data.
70
+ */
71
+ async post(endpoint, data) {
72
+ const headers = this.generateHeaders(data?.headers || {}, data?.token);
73
+ const body = data?.body;
74
+ const response = await postRequest({
75
+ url: this.baseUrl + endpoint,
76
+ urlParams: data?.urlParams || {},
77
+ headers,
78
+ body,
79
+ });
80
+ this.onDebug(endpoint, "post", {
81
+ headers,
82
+ body,
83
+ message: response.message,
84
+ status: response.status,
85
+ });
86
+ return response;
87
+ }
88
+ /**
89
+ * Sends a put request to the specified endpoint.
90
+ * @param endpoint - The API endpoint to send the put request to.
91
+ * @param data - The request data, including body, optional headers, and token.
92
+ * @returns The API response data.
93
+ */
94
+ async put(endpoint, data) {
95
+ const headers = this.generateHeaders(data?.headers || {}, data?.token);
96
+ const body = data?.body;
97
+ const response = await putRequest({
98
+ url: this.baseUrl + endpoint,
99
+ urlParams: data?.urlParams || {},
100
+ headers,
101
+ body,
102
+ });
103
+ this.onDebug(endpoint, "put", {
104
+ headers,
105
+ body,
106
+ message: response.message,
107
+ status: response.status,
108
+ });
109
+ return response;
110
+ }
111
+ /**
112
+ * Sends a patch request to the specified endpoint.
113
+ * @param endpoint - The API endpoint to send the patch request to.
114
+ * @param data - The request data, including body, optional headers, and token.
115
+ * @returns The API response data.
116
+ */
117
+ async patch(endpoint, data) {
118
+ const headers = this.generateHeaders(data?.headers || {}, data?.token);
119
+ const body = data?.body;
120
+ const response = await patchRequest({
121
+ url: this.baseUrl + endpoint,
122
+ urlParams: data?.urlParams || {},
123
+ headers,
124
+ body,
125
+ });
126
+ this.onDebug(endpoint, "patch", {
127
+ headers,
128
+ body,
129
+ message: response.message,
130
+ status: response.status,
131
+ });
132
+ return response;
133
+ }
134
+ /**
135
+ * Sends a delete request to the specified endpoint.
136
+ * @param endpoint - The API endpoint to send the delete request to.
137
+ * @param data - The request data, including body, optional headers, and token.
138
+ * @returns The API response data.
139
+ */
140
+ async delete(endpoint, data) {
141
+ const headers = this.generateHeaders(data?.headers || {}, data?.token);
142
+ const body = data?.body;
143
+ const response = await deleteRequest({
144
+ url: this.baseUrl + endpoint,
145
+ urlParams: data?.urlParams || {},
146
+ headers,
147
+ body,
148
+ });
149
+ this.onDebug(endpoint, "delete", {
150
+ headers,
151
+ body,
152
+ message: response.message,
153
+ status: response.status,
154
+ });
155
+ return response;
156
+ }
157
+ }
158
+ export { ApiService };
@@ -0,0 +1,69 @@
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 {string} 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
+ * Retrieves information about the caller of the current function.
54
+ *
55
+ * This function analyzes the stack trace to determine the file path and function name
56
+ * of the caller. It excludes stack trace entries related to the `@arkyn/server` package
57
+ * and attempts to resolve the file path relative to the project root directory.
58
+ *
59
+ * @returns An object containing:
60
+ * - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
61
+ * - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
62
+ */
63
+ static getCaller(): {
64
+ functionName: string;
65
+ callerInfo: string;
66
+ };
67
+ }
68
+ export { DebugService };
69
+ //# sourceMappingURL=debugService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debugService.d.ts","sourceRoot":"","sources":["../../src/services/debugService.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AAEH,cAAM,YAAY;IAChB;;;OAGG;IACH,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,CAAM;IAElC;;;;;;;;;;;;;;OAcG;IAEH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxC;;;;;;;;;;;OAWG;IAEH,MAAM,CAAC,gBAAgB,IAAI,IAAI;IAI/B;;;;;;;;;;OAUG;IAEH,MAAM,CAAC,SAAS;;;;CAgEjB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,114 @@
1
+ import path from "path";
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 DebugService {
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 ignoreFiles = [];
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 {string} 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
+ * DebugService.setIgnoreFile("httpAdapter.ts");
37
+ * ```
38
+ */
39
+ static setIgnoreFile(file) {
40
+ this.ignoreFiles.push(file);
41
+ }
42
+ /**
43
+ * Clears all configured ignore files.
44
+ *
45
+ * This method resets the ignore file configuration, allowing all files to be
46
+ * considered in stack trace analysis again.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Clear all ignore file configurations
51
+ * DebugService.clearIgnoreFiles();
52
+ * ```
53
+ */
54
+ static clearIgnoreFiles() {
55
+ this.ignoreFiles = [];
56
+ }
57
+ /**
58
+ * Retrieves information about the caller of the current function.
59
+ *
60
+ * This function analyzes the stack trace to determine the file path and function name
61
+ * of the caller. It excludes stack trace entries related to the `@arkyn/server` package
62
+ * and attempts to resolve the file path relative to the project root directory.
63
+ *
64
+ * @returns An object containing:
65
+ * - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
66
+ * - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
67
+ */
68
+ static getCaller() {
69
+ const projectRoot = process.cwd();
70
+ const err = new Error();
71
+ const stack = err.stack || "";
72
+ const stackLines = stack.split("\n").map((line) => line.trim());
73
+ let callerIndex = 2;
74
+ while (callerIndex < stackLines.length &&
75
+ (stackLines[callerIndex].includes("node:internal") ||
76
+ stackLines[callerIndex].includes("/node_modules/"))) {
77
+ callerIndex++;
78
+ }
79
+ if (this.ignoreFiles.length > 0) {
80
+ while (callerIndex < stackLines.length &&
81
+ this.ignoreFiles.some((ignoreFile) => stackLines[callerIndex].includes(ignoreFile))) {
82
+ callerIndex++;
83
+ }
84
+ }
85
+ const callerLine = stackLines[callerIndex] || "";
86
+ let functionName = "Unknown function";
87
+ let callerInfo = "Unknown caller";
88
+ const namedFunctionMatch = callerLine.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
89
+ if (namedFunctionMatch) {
90
+ functionName = namedFunctionMatch[1];
91
+ callerInfo = namedFunctionMatch[2];
92
+ }
93
+ else {
94
+ const anonymousFunctionMatch = callerLine.match(/at\s+(.+)/);
95
+ if (anonymousFunctionMatch) {
96
+ callerInfo = anonymousFunctionMatch[1];
97
+ const objectMethodMatch = callerInfo.match(/at\s+([^(\s]+)\s+/);
98
+ if (objectMethodMatch && objectMethodMatch[1] !== "new") {
99
+ functionName = objectMethodMatch[1];
100
+ }
101
+ }
102
+ }
103
+ if (callerInfo.includes("(")) {
104
+ callerInfo = callerInfo.substring(callerInfo.indexOf("(") + 1, callerInfo.lastIndexOf(")"));
105
+ }
106
+ callerInfo = callerInfo.split(":").slice(0, -2).join(":");
107
+ try {
108
+ callerInfo = path.relative(projectRoot, callerInfo);
109
+ }
110
+ catch (e) { }
111
+ return { functionName, callerInfo };
112
+ }
113
+ }
114
+ export { DebugService };
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Input properties for log mapping.
3
+ *
4
+ * @typedef {object} InputProps
5
+ * @property {number} status - HTTP response status code.
6
+ * @property {string} url - The request URL.
7
+ * @property {"GET" | "POST" | "PUT" | "DELETE" | "PATCH"} method - HTTP method used.
8
+ * @property {HeadersInit} requestHeaders - Headers sent with the request.
9
+ * @property {HeadersInit} responseHeaders - Headers received in the response.
10
+ * @property {any} requestBody - Body of the request.
11
+ * @property {number} elapsedTime - Time elapsed for the request in milliseconds.
12
+ * @property {any} responseBody - Body of the response.
13
+ * @property {URLSearchParams} queryParams - Query parameters from the URL.
14
+ */
15
+ type InputProps = {
16
+ status: number;
17
+ rawUrl: string;
18
+ urlParams?: Record<string, string>;
19
+ method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
20
+ requestHeaders: HeadersInit;
21
+ responseHeaders: HeadersInit;
22
+ requestBody: any;
23
+ elapsedTime: number;
24
+ responseBody: any;
25
+ queryParams: URLSearchParams;
26
+ };
27
+ /**
28
+ * Output properties after log mapping transformation.
29
+ *
30
+ * @typedef {object} OutputProps
31
+ * @property {string} rawUrl - The original request URL.
32
+ * @property {number} status - HTTP response status code.
33
+ * @property {"GET" | "POST" | "PUT" | "DELETE" | "PATCH"} method - HTTP method used.
34
+ * @property {string | null} token - Authentication token (if present).
35
+ * @property {number} elapsedTime - Time elapsed for the request in milliseconds.
36
+ * @property {Record<string, string>} requestHeaders - Mapped request headers.
37
+ * @property {Record<string, string>} requestBody - Mapped request body.
38
+ * @property {Record<string, string>} queryParams - Mapped query parameters.
39
+ * @property {Record<string, string>} responseHeaders - Mapped response headers.
40
+ * @property {any} responseBody - The response body.
41
+ */
42
+ type OutputProps = {
43
+ rawUrl: string;
44
+ status: number;
45
+ method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
46
+ token: string | null;
47
+ elapsedTime: number;
48
+ requestHeaders: Record<string, string>;
49
+ requestBody: Record<string, string>;
50
+ queryParams: Record<string, string>;
51
+ responseHeaders: Record<string, string>;
52
+ responseBody: any;
53
+ };
54
+ /**
55
+ * Static service for mapping HTTP request/response data into a standardized log format.
56
+ *
57
+ * Provides utilities to transform headers and query parameters into plain objects,
58
+ * and produces a unified output structure for logging purposes.
59
+ */
60
+ declare class LogMapperService {
61
+ /**
62
+ * Converts various header formats into a plain key-value object.
63
+ *
64
+ * @param {HeadersInit} headers - The headers to map.
65
+ * @returns {Record<string, string>} A plain object with header key-value pairs.
66
+ * @private
67
+ */
68
+ private static mapHeaders;
69
+ /**
70
+ * Converts URLSearchParams into a plain key-value object.
71
+ *
72
+ * @param {URLSearchParams} queryParams - The query parameters to map.
73
+ * @returns {Record<string, string>} A plain object with query parameter key-value pairs.
74
+ * @private
75
+ */
76
+ private static mapQueryParams;
77
+ /**
78
+ * Transforms raw HTTP request/response data into a standardized log output format.
79
+ *
80
+ * @param {InputProps} props - The input properties containing request/response data.
81
+ * @returns {OutputProps} The mapped output object ready for logging.
82
+ */
83
+ static handle(props: InputProps): OutputProps;
84
+ }
85
+ export { LogMapperService };
86
+ //# sourceMappingURL=logMapperService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logMapperService.d.ts","sourceRoot":"","sources":["../../src/services/logMapperService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,KAAK,UAAU,GAAG;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,cAAc,EAAE,WAAW,CAAC;IAC5B,eAAe,EAAE,WAAW,CAAC;IAC7B,WAAW,EAAE,GAAG,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,WAAW,EAAE,eAAe,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,YAAY,EAAE,GAAG,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,cAAM,gBAAgB;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAiBzB;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAQ7B;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW;CAiB9C;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Static service for mapping HTTP request/response data into a standardized log format.
3
+ *
4
+ * Provides utilities to transform headers and query parameters into plain objects,
5
+ * and produces a unified output structure for logging purposes.
6
+ */
7
+ class LogMapperService {
8
+ /**
9
+ * Converts various header formats into a plain key-value object.
10
+ *
11
+ * @param {HeadersInit} headers - The headers to map.
12
+ * @returns {Record<string, string>} A plain object with header key-value pairs.
13
+ * @private
14
+ */
15
+ static mapHeaders(headers) {
16
+ if (headers instanceof Headers) {
17
+ return Object.fromEntries(headers.entries());
18
+ }
19
+ else if (typeof headers === "object") {
20
+ return Object.entries(headers).reduce((acc, [key, value]) => {
21
+ if (typeof value === "string")
22
+ acc[key] = value;
23
+ else if (Array.isArray(value))
24
+ acc[key] = value.join(", ");
25
+ else
26
+ acc[key] = JSON.stringify(value);
27
+ return acc;
28
+ }, {});
29
+ }
30
+ return {};
31
+ }
32
+ /**
33
+ * Converts URLSearchParams into a plain key-value object.
34
+ *
35
+ * @param {URLSearchParams} queryParams - The query parameters to map.
36
+ * @returns {Record<string, string>} A plain object with query parameter key-value pairs.
37
+ * @private
38
+ */
39
+ static mapQueryParams(queryParams) {
40
+ const params = {};
41
+ queryParams.forEach((value, key) => (params[key] = value));
42
+ return params;
43
+ }
44
+ /**
45
+ * Transforms raw HTTP request/response data into a standardized log output format.
46
+ *
47
+ * @param {InputProps} props - The input properties containing request/response data.
48
+ * @returns {OutputProps} The mapped output object ready for logging.
49
+ */
50
+ static handle(props) {
51
+ return {
52
+ rawUrl: props.rawUrl,
53
+ status: props.status,
54
+ method: props.method,
55
+ token: null,
56
+ elapsedTime: props.elapsedTime,
57
+ requestHeaders: this.mapHeaders(props.requestHeaders),
58
+ requestBody: props.requestBody || null,
59
+ queryParams: {
60
+ ...this.mapQueryParams(props.queryParams),
61
+ ...props.urlParams,
62
+ },
63
+ responseHeaders: this.mapHeaders(props.responseHeaders),
64
+ responseBody: props.responseBody || null,
65
+ };
66
+ }
67
+ }
68
+ export { LogMapperService };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Static service for log endpoint configuration and access.
3
+ *
4
+ * Stores a singleton configuration containing the traffic source identifier,
5
+ * user token, and log ingestion URL.
6
+ */
7
+ declare class LogService {
8
+ private static config?;
9
+ /**
10
+ * Sets the log service configuration only once.
11
+ * If the configuration is already set, the call is ignored.
12
+ *
13
+ * @param {object} config - Service configuration parameters.
14
+ * @param {string} config.trafficSourceId - Traffic source identifier.
15
+ * @param {string} config.userToken - User token for authentication.
16
+ * @param {string} [config.logBaseApiUrl] - Optional base URL for the log service.
17
+ */
18
+ static setConfig(config: {
19
+ trafficSourceId: string;
20
+ userToken: string;
21
+ logBaseApiUrl?: string;
22
+ }): void;
23
+ /**
24
+ * Returns the current service configuration, if it exists.
25
+ * @returns {{ trafficSourceId: string; userToken: string; apiUrl: string } | undefined} The stored configuration or `undefined` if not set.
26
+ */
27
+ static getConfig(): {
28
+ trafficSourceId: string;
29
+ userToken: string;
30
+ apiUrl: string;
31
+ } | undefined;
32
+ /**
33
+ * Resets the stored configuration, allowing a new initialization.
34
+ */
35
+ static resetConfig(): void;
36
+ }
37
+ export { LogService };
38
+ //# sourceMappingURL=logService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logService.d.ts","sourceRoot":"","sources":["../../src/services/logService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAM,UAAU;IACd,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAIpB;IAEF;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE;QACvB,eAAe,EAAE,MAAM,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;QAClB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GAAG,IAAI;IAUR;;;OAGG;IACH,MAAM,CAAC,SAAS,IACZ;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAC9D,SAAS;IAIb;;OAEG;IACH,MAAM,CAAC,WAAW;CAGnB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Static service for log endpoint configuration and access.
3
+ *
4
+ * Stores a singleton configuration containing the traffic source identifier,
5
+ * user token, and log ingestion URL.
6
+ */
7
+ class LogService {
8
+ static config;
9
+ /**
10
+ * Sets the log service configuration only once.
11
+ * If the configuration is already set, the call is ignored.
12
+ *
13
+ * @param {object} config - Service configuration parameters.
14
+ * @param {string} config.trafficSourceId - Traffic source identifier.
15
+ * @param {string} config.userToken - User token for authentication.
16
+ * @param {string} [config.logBaseApiUrl] - Optional base URL for the log service.
17
+ */
18
+ static setConfig(config) {
19
+ if (!!this.config)
20
+ return;
21
+ const { trafficSourceId, userToken, logBaseApiUrl } = config;
22
+ const baseUrl = logBaseApiUrl || `http://95.216.190.158:8081`;
23
+ const apiUrl = `${baseUrl}/ingest-log`;
24
+ this.config = { trafficSourceId, userToken, apiUrl };
25
+ }
26
+ /**
27
+ * Returns the current service configuration, if it exists.
28
+ * @returns {{ trafficSourceId: string; userToken: string; apiUrl: string } | undefined} The stored configuration or `undefined` if not set.
29
+ */
30
+ static getConfig() {
31
+ return this.config;
32
+ }
33
+ /**
34
+ * Resets the stored configuration, allowing a new initialization.
35
+ */
36
+ static resetConfig() {
37
+ this.config = undefined;
38
+ }
39
+ }
40
+ export { LogService };
@@ -1,4 +1,3 @@
1
- type DecodeRequestBodyFunction = (request: Request) => Promise<any>;
2
1
  /**
3
2
  * Decodes the body of an incoming request into a JavaScript object.
4
3
  *
@@ -7,11 +6,11 @@ type DecodeRequestBodyFunction = (request: Request) => Promise<any>;
7
6
  * 2. If JSON parsing fails, attempts to parse the body as URL-encoded form data.
8
7
  * 3. If both parsing attempts fail, logs the errors and returns an empty object.
9
8
  *
10
- * @param req - The incoming request object containing the body to decode.
11
- * @returns A promise that resolves to the decoded data as a JavaScript object.
9
+ * @param {Request} request - The incoming request object containing the body to decode.
10
+ * @returns {Promise<any>} A promise that resolves to the decoded data as a JavaScript object.
12
11
  *
13
12
  * @throws Logs errors to the console if the request body cannot be read or parsed.
14
13
  */
15
- declare const decodeRequestBody: DecodeRequestBodyFunction;
14
+ declare function decodeRequestBody(request: Request): Promise<any>;
16
15
  export { decodeRequestBody };
17
16
  //# sourceMappingURL=decodeRequestBody.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decodeRequestBody.d.ts","sourceRoot":"","sources":["../../src/utilities/decodeRequestBody.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAEH,iBAAe,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAsB/D;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -7,14 +7,14 @@ import { BadRequest } from "../http/badResponses/badRequest";
7
7
  * 2. If JSON parsing fails, attempts to parse the body as URL-encoded form data.
8
8
  * 3. If both parsing attempts fail, logs the errors and returns an empty object.
9
9
  *
10
- * @param req - The incoming request object containing the body to decode.
11
- * @returns A promise that resolves to the decoded data as a JavaScript object.
10
+ * @param {Request} request - The incoming request object containing the body to decode.
11
+ * @returns {Promise<any>} A promise that resolves to the decoded data as a JavaScript object.
12
12
  *
13
13
  * @throws Logs errors to the console if the request body cannot be read or parsed.
14
14
  */
15
- const decodeRequestBody = async (req) => {
15
+ async function decodeRequestBody(request) {
16
16
  let data;
17
- const arrayBuffer = await req.arrayBuffer();
17
+ const arrayBuffer = await request.arrayBuffer();
18
18
  const text = new TextDecoder().decode(arrayBuffer);
19
19
  try {
20
20
  data = JSON.parse(text);
@@ -34,5 +34,5 @@ const decodeRequestBody = async (req) => {
34
34
  }
35
35
  }
36
36
  return data;
37
- };
37
+ }
38
38
  export { decodeRequestBody };
@@ -5,13 +5,13 @@
5
5
  * `data` or `response` objects by checking various properties in a specific order.
6
6
  * If no valid error message is found, it returns a default message: "Missing error message".
7
7
  *
8
- * @param data - The data object that may contain error information. It can have properties
8
+ * @param {any} data - The data object that may contain error information. It can have properties
9
9
  * such as `message`, `error`, or `error.message` that are checked for a string value.
10
- * @param response - The response object that may contain a `statusText` property
10
+ * @param {Response} response - The response object that may contain a `statusText` property
11
11
  * representing the HTTP status text.
12
- * @returns A string representing the decoded error message, or a default message
12
+ * @returns {string} A string representing the decoded error message, or a default message
13
13
  * if no error message is found.
14
14
  */
15
- declare function decodeErrorMessageFromRequest(data: any, response: Response): string;
16
- export { decodeErrorMessageFromRequest };
17
- //# sourceMappingURL=decodeErrorMessageFromRequest.d.ts.map
15
+ declare function decodeRequestErrorMessage(data: any, response: Response): string;
16
+ export { decodeRequestErrorMessage };
17
+ //# sourceMappingURL=decodeRequestErrorMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decodeRequestErrorMessage.d.ts","sourceRoot":"","sources":["../../src/utilities/decodeRequestErrorMessage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,iBAAS,yBAAyB,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAkBxE;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAC"}