@arkyn/server 3.0.1-beta.99 → 3.0.3

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 (265) hide show
  1. package/LICENSE.txt +184 -1
  2. package/README.md +277 -224
  3. package/dist/http/api/_deleteRequest.d.ts +17 -0
  4. package/dist/http/api/_deleteRequest.d.ts.map +1 -0
  5. package/dist/http/api/_getRequest.d.ts +16 -0
  6. package/dist/http/api/_getRequest.d.ts.map +1 -0
  7. package/dist/http/api/_logMapperService.d.ts +86 -0
  8. package/dist/http/api/_logMapperService.d.ts.map +1 -0
  9. package/dist/{api/arkynLogRequest.d.ts → http/api/_logRequest.d.ts} +22 -19
  10. package/dist/{api/arkynLogRequest.d.ts.map → http/api/_logRequest.d.ts.map} +1 -1
  11. package/dist/http/api/_makeRequest.d.ts +61 -0
  12. package/dist/http/api/_makeRequest.d.ts.map +1 -0
  13. package/dist/http/api/_patchRequest.d.ts +17 -0
  14. package/dist/http/api/_patchRequest.d.ts.map +1 -0
  15. package/dist/http/api/_postRequest.d.ts +17 -0
  16. package/dist/http/api/_postRequest.d.ts.map +1 -0
  17. package/dist/http/api/_putRequest.d.ts +17 -0
  18. package/dist/http/api/_putRequest.d.ts.map +1 -0
  19. package/dist/http/badResponses/_badResponse.d.ts +21 -7
  20. package/dist/http/badResponses/_badResponse.d.ts.map +1 -1
  21. package/dist/http/badResponses/badGateway.d.ts +12 -23
  22. package/dist/http/badResponses/badGateway.d.ts.map +1 -1
  23. package/dist/http/badResponses/badRequest.d.ts +10 -23
  24. package/dist/http/badResponses/badRequest.d.ts.map +1 -1
  25. package/dist/http/badResponses/conflict.d.ts +10 -23
  26. package/dist/http/badResponses/conflict.d.ts.map +1 -1
  27. package/dist/http/badResponses/forbidden.d.ts +10 -23
  28. package/dist/http/badResponses/forbidden.d.ts.map +1 -1
  29. package/dist/http/badResponses/notFound.d.ts +10 -23
  30. package/dist/http/badResponses/notFound.d.ts.map +1 -1
  31. package/dist/http/badResponses/notImplemented.d.ts +10 -23
  32. package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
  33. package/dist/http/badResponses/serverError.d.ts +10 -23
  34. package/dist/http/badResponses/serverError.d.ts.map +1 -1
  35. package/dist/http/badResponses/unauthorized.d.ts +10 -23
  36. package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
  37. package/dist/http/badResponses/unprocessableEntity.d.ts +23 -33
  38. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
  39. package/dist/http/successResponses/_successResponse.d.ts +21 -7
  40. package/dist/http/successResponses/_successResponse.d.ts.map +1 -1
  41. package/dist/http/successResponses/created.d.ts +11 -29
  42. package/dist/http/successResponses/created.d.ts.map +1 -1
  43. package/dist/http/successResponses/found.d.ts +11 -32
  44. package/dist/http/successResponses/found.d.ts.map +1 -1
  45. package/dist/http/successResponses/noContent.d.ts +10 -16
  46. package/dist/http/successResponses/noContent.d.ts.map +1 -1
  47. package/dist/http/successResponses/success.d.ts +11 -29
  48. package/dist/http/successResponses/success.d.ts.map +1 -1
  49. package/dist/http/successResponses/updated.d.ts +12 -29
  50. package/dist/http/successResponses/updated.d.ts.map +1 -1
  51. package/dist/index.d.ts +9 -10
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +1069 -38
  54. package/dist/index.js.map +1 -0
  55. package/dist/modules/http/api/_deleteRequest.js +15 -0
  56. package/dist/modules/http/api/_deleteRequest.js.map +1 -0
  57. package/dist/modules/http/api/_getRequest.js +14 -0
  58. package/dist/modules/http/api/_getRequest.js.map +1 -0
  59. package/dist/modules/http/api/_logMapperService.js +33 -0
  60. package/dist/modules/http/api/_logMapperService.js.map +1 -0
  61. package/dist/modules/http/api/_logRequest.js +58 -0
  62. package/dist/modules/http/api/_logRequest.js.map +1 -0
  63. package/dist/modules/http/api/_makeRequest.js +72 -0
  64. package/dist/modules/http/api/_makeRequest.js.map +1 -0
  65. package/dist/modules/http/api/_patchRequest.js +15 -0
  66. package/dist/modules/http/api/_patchRequest.js.map +1 -0
  67. package/dist/modules/http/api/_postRequest.js +15 -0
  68. package/dist/modules/http/api/_postRequest.js.map +1 -0
  69. package/dist/modules/http/api/_putRequest.js +15 -0
  70. package/dist/modules/http/api/_putRequest.js.map +1 -0
  71. package/dist/modules/http/badResponses/_badResponse.js +65 -0
  72. package/dist/modules/http/badResponses/_badResponse.js.map +1 -0
  73. package/dist/modules/http/badResponses/badGateway.js +26 -0
  74. package/dist/modules/http/badResponses/badGateway.js.map +1 -0
  75. package/dist/modules/http/badResponses/badRequest.js +26 -0
  76. package/dist/modules/http/badResponses/badRequest.js.map +1 -0
  77. package/dist/modules/http/badResponses/conflict.js +26 -0
  78. package/dist/modules/http/badResponses/conflict.js.map +1 -0
  79. package/dist/modules/http/badResponses/forbidden.js +26 -0
  80. package/dist/modules/http/badResponses/forbidden.js.map +1 -0
  81. package/dist/modules/http/badResponses/notFound.js +26 -0
  82. package/dist/modules/http/badResponses/notFound.js.map +1 -0
  83. package/dist/modules/http/badResponses/notImplemented.js +26 -0
  84. package/dist/modules/http/badResponses/notImplemented.js.map +1 -0
  85. package/dist/modules/http/badResponses/serverError.js +26 -0
  86. package/dist/modules/http/badResponses/serverError.js.map +1 -0
  87. package/dist/modules/http/badResponses/unauthorized.js +26 -0
  88. package/dist/modules/http/badResponses/unauthorized.js.map +1 -0
  89. package/dist/modules/http/badResponses/unprocessableEntity.js +30 -0
  90. package/dist/modules/http/badResponses/unprocessableEntity.js.map +1 -0
  91. package/dist/modules/http/successResponses/_successResponse.js +64 -0
  92. package/dist/modules/http/successResponses/_successResponse.js.map +1 -0
  93. package/dist/modules/http/successResponses/created.js +26 -0
  94. package/dist/modules/http/successResponses/created.js.map +1 -0
  95. package/dist/modules/http/successResponses/found.js +26 -0
  96. package/dist/modules/http/successResponses/found.js.map +1 -0
  97. package/dist/modules/http/successResponses/noContent.js +19 -0
  98. package/dist/modules/http/successResponses/noContent.js.map +1 -0
  99. package/dist/modules/http/successResponses/success.js +26 -0
  100. package/dist/modules/http/successResponses/success.js.map +1 -0
  101. package/dist/modules/http/successResponses/updated.js +26 -0
  102. package/dist/modules/http/successResponses/updated.js.map +1 -0
  103. package/dist/modules/services/apiService.js +111 -0
  104. package/dist/modules/services/apiService.js.map +1 -0
  105. package/dist/modules/services/debugService.js +38 -0
  106. package/dist/modules/services/debugService.js.map +1 -0
  107. package/dist/modules/services/logService.js +23 -0
  108. package/dist/modules/services/logService.js.map +1 -0
  109. package/dist/modules/utilities/decodeRequestBody.js +22 -0
  110. package/dist/modules/utilities/decodeRequestBody.js.map +1 -0
  111. package/dist/modules/utilities/decodeRequestErrorMessage.js +8 -0
  112. package/dist/modules/utilities/decodeRequestErrorMessage.js.map +1 -0
  113. package/dist/modules/utilities/errorHandler.js +41 -0
  114. package/dist/modules/utilities/errorHandler.js.map +1 -0
  115. package/dist/modules/utilities/flushDebugLogs.js +18 -0
  116. package/dist/modules/utilities/flushDebugLogs.js.map +1 -0
  117. package/dist/modules/utilities/formAsyncParse.js +16 -0
  118. package/dist/modules/utilities/formAsyncParse.js.map +1 -0
  119. package/dist/modules/utilities/formParse.js +16 -0
  120. package/dist/modules/utilities/formParse.js.map +1 -0
  121. package/dist/modules/utilities/getScopedParams.js +11 -0
  122. package/dist/modules/utilities/getScopedParams.js.map +1 -0
  123. package/dist/modules/utilities/schemaValidator.js +57 -0
  124. package/dist/modules/utilities/schemaValidator.js.map +1 -0
  125. package/dist/modules/validations/validateCep.js +11 -0
  126. package/dist/modules/validations/validateCep.js.map +1 -0
  127. package/dist/modules/validations/validateCnpj.js +56 -0
  128. package/dist/modules/validations/validateCnpj.js.map +1 -0
  129. package/dist/modules/validations/validateCpf.js +29 -0
  130. package/dist/modules/validations/validateCpf.js.map +1 -0
  131. package/dist/modules/validations/validateDate.js +28 -0
  132. package/dist/modules/validations/validateDate.js.map +1 -0
  133. package/dist/modules/validations/validateEmail.js +56 -0
  134. package/dist/modules/validations/validateEmail.js.map +1 -0
  135. package/dist/modules/validations/validatePassword.js +14 -0
  136. package/dist/modules/validations/validatePassword.js.map +1 -0
  137. package/dist/modules/validations/validatePhone.js +12 -0
  138. package/dist/modules/validations/validatePhone.js.map +1 -0
  139. package/dist/modules/validations/validateRg.js +10 -0
  140. package/dist/modules/validations/validateRg.js.map +1 -0
  141. package/dist/services/apiService.d.ts +25 -26
  142. package/dist/services/apiService.d.ts.map +1 -1
  143. package/dist/services/debugService.d.ts +15 -32
  144. package/dist/services/debugService.d.ts.map +1 -1
  145. package/dist/services/logService.d.ts +33 -0
  146. package/dist/services/logService.d.ts.map +1 -0
  147. package/dist/utilities/decodeRequestBody.d.ts +18 -0
  148. package/dist/utilities/decodeRequestBody.d.ts.map +1 -0
  149. package/dist/utilities/decodeRequestErrorMessage.d.ts +19 -0
  150. package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -0
  151. package/dist/utilities/errorHandler.d.ts +25 -0
  152. package/dist/utilities/errorHandler.d.ts.map +1 -0
  153. package/dist/utilities/flushDebugLogs.d.ts +24 -0
  154. package/dist/utilities/flushDebugLogs.d.ts.map +1 -0
  155. package/dist/utilities/formAsyncParse.d.ts +38 -0
  156. package/dist/utilities/formAsyncParse.d.ts.map +1 -0
  157. package/dist/utilities/formParse.d.ts +38 -0
  158. package/dist/utilities/formParse.d.ts.map +1 -0
  159. package/dist/utilities/getScopedParams.d.ts +19 -0
  160. package/dist/utilities/getScopedParams.d.ts.map +1 -0
  161. package/dist/utilities/schemaValidator.d.ts +75 -0
  162. package/dist/utilities/schemaValidator.d.ts.map +1 -0
  163. package/dist/validations/validateCep.d.ts +6 -11
  164. package/dist/validations/validateCep.d.ts.map +1 -1
  165. package/dist/validations/validateCnpj.d.ts +2 -3
  166. package/dist/validations/validateCnpj.d.ts.map +1 -1
  167. package/dist/validations/validateCpf.d.ts +4 -12
  168. package/dist/validations/validateCpf.d.ts.map +1 -1
  169. package/dist/validations/validateDate.d.ts +13 -24
  170. package/dist/validations/validateDate.d.ts.map +1 -1
  171. package/dist/validations/validateEmail.d.ts +3 -4
  172. package/dist/validations/validateEmail.d.ts.map +1 -1
  173. package/dist/validations/validatePassword.d.ts +3 -4
  174. package/dist/validations/validatePassword.d.ts.map +1 -1
  175. package/dist/validations/validatePhone.d.ts +7 -20
  176. package/dist/validations/validatePhone.d.ts.map +1 -1
  177. package/dist/validations/validateRg.d.ts +1 -2
  178. package/dist/validations/validateRg.d.ts.map +1 -1
  179. package/package.json +317 -15
  180. package/dist/api/arkynLogRequest.js +0 -88
  181. package/dist/api/deleteRequest.d.ts +0 -13
  182. package/dist/api/deleteRequest.d.ts.map +0 -1
  183. package/dist/api/deleteRequest.js +0 -14
  184. package/dist/api/getRequest.d.ts +0 -12
  185. package/dist/api/getRequest.d.ts.map +0 -1
  186. package/dist/api/getRequest.js +0 -13
  187. package/dist/api/makeRequest.d.ts +0 -38
  188. package/dist/api/makeRequest.d.ts.map +0 -1
  189. package/dist/api/makeRequest.js +0 -107
  190. package/dist/api/patchRequest.d.ts +0 -13
  191. package/dist/api/patchRequest.d.ts.map +0 -1
  192. package/dist/api/patchRequest.js +0 -14
  193. package/dist/api/postRequest.d.ts +0 -13
  194. package/dist/api/postRequest.d.ts.map +0 -1
  195. package/dist/api/postRequest.js +0 -14
  196. package/dist/api/putRequest.d.ts +0 -13
  197. package/dist/api/putRequest.d.ts.map +0 -1
  198. package/dist/api/putRequest.js +0 -14
  199. package/dist/bundle.js +0 -1507
  200. package/dist/bundle.umd.cjs +0 -10
  201. package/dist/http/badResponses/_badResponse.js +0 -20
  202. package/dist/http/badResponses/badGateway.js +0 -58
  203. package/dist/http/badResponses/badRequest.js +0 -58
  204. package/dist/http/badResponses/conflict.js +0 -58
  205. package/dist/http/badResponses/forbidden.js +0 -58
  206. package/dist/http/badResponses/notFound.js +0 -58
  207. package/dist/http/badResponses/notImplemented.js +0 -58
  208. package/dist/http/badResponses/serverError.js +0 -58
  209. package/dist/http/badResponses/unauthorized.js +0 -58
  210. package/dist/http/badResponses/unprocessableEntity.js +0 -65
  211. package/dist/http/successResponses/_successResponse.js +0 -37
  212. package/dist/http/successResponses/created.js +0 -57
  213. package/dist/http/successResponses/found.js +0 -60
  214. package/dist/http/successResponses/noContent.js +0 -38
  215. package/dist/http/successResponses/success.js +0 -57
  216. package/dist/http/successResponses/updated.js +0 -57
  217. package/dist/mapper/arkynLogRequestMapper.d.ts +0 -30
  218. package/dist/mapper/arkynLogRequestMapper.d.ts.map +0 -1
  219. package/dist/mapper/arkynLogRequestMapper.js +0 -44
  220. package/dist/services/apiService.js +0 -133
  221. package/dist/services/arkynLogService.d.ts +0 -44
  222. package/dist/services/arkynLogService.d.ts.map +0 -1
  223. package/dist/services/arkynLogService.js +0 -46
  224. package/dist/services/debugService.js +0 -57
  225. package/dist/services/decodeErrorMessageFromRequest.d.ts +0 -17
  226. package/dist/services/decodeErrorMessageFromRequest.d.ts.map +0 -1
  227. package/dist/services/decodeErrorMessageFromRequest.js +0 -30
  228. package/dist/services/decodeRequestBody.d.ts +0 -17
  229. package/dist/services/decodeRequestBody.d.ts.map +0 -1
  230. package/dist/services/decodeRequestBody.js +0 -38
  231. package/dist/services/errorHandler.d.ts +0 -44
  232. package/dist/services/errorHandler.d.ts.map +0 -1
  233. package/dist/services/errorHandler.js +0 -93
  234. package/dist/services/flushDebugLogs.d.ts +0 -8
  235. package/dist/services/flushDebugLogs.d.ts.map +0 -1
  236. package/dist/services/flushDebugLogs.js +0 -20
  237. package/dist/services/formAsyncParse.d.ts +0 -59
  238. package/dist/services/formAsyncParse.d.ts.map +0 -1
  239. package/dist/services/formAsyncParse.js +0 -58
  240. package/dist/services/formParse.d.ts +0 -59
  241. package/dist/services/formParse.d.ts.map +0 -1
  242. package/dist/services/formParse.js +0 -58
  243. package/dist/services/getCaller.d.ts +0 -17
  244. package/dist/services/getCaller.d.ts.map +0 -1
  245. package/dist/services/getCaller.js +0 -60
  246. package/dist/services/getScopedParams.d.ts +0 -28
  247. package/dist/services/getScopedParams.d.ts.map +0 -1
  248. package/dist/services/getScopedParams.js +0 -34
  249. package/dist/services/measureRouteExecution.d.ts +0 -3
  250. package/dist/services/measureRouteExecution.d.ts.map +0 -1
  251. package/dist/services/measureRouteExecution.js +0 -24
  252. package/dist/services/schemaValidator.d.ts +0 -158
  253. package/dist/services/schemaValidator.d.ts.map +0 -1
  254. package/dist/services/schemaValidator.js +0 -207
  255. package/dist/types/ApiResponseDTO.d.ts +0 -17
  256. package/dist/types/ApiResponseDTO.d.ts.map +0 -1
  257. package/dist/types/ApiResponseDTO.js +0 -1
  258. package/dist/validations/validateCep.js +0 -33
  259. package/dist/validations/validateCnpj.js +0 -52
  260. package/dist/validations/validateCpf.js +0 -54
  261. package/dist/validations/validateDate.js +0 -73
  262. package/dist/validations/validateEmail.js +0 -123
  263. package/dist/validations/validatePassword.js +0 -34
  264. package/dist/validations/validatePhone.js +0 -44
  265. package/dist/validations/validateRg.js +0 -31
@@ -1,30 +0,0 @@
1
- /**
2
- * Decodes an error message from a given request data object or response object.
3
- *
4
- * This function attempts to extract a meaningful error message from the provided
5
- * `data` or `response` objects by checking various properties in a specific order.
6
- * If no valid error message is found, it returns a default message: "Missing error message".
7
- *
8
- * @param data - The data object that may contain error information. It can have properties
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
11
- * representing the HTTP status text.
12
- * @returns A string representing the decoded error message, or a default message
13
- * if no error message is found.
14
- */
15
- function decodeErrorMessageFromRequest(data, response) {
16
- if (data?.message && typeof data?.message === "string") {
17
- return data?.message;
18
- }
19
- if (data?.error && typeof data?.error === "string") {
20
- return data?.error;
21
- }
22
- if (data?.error?.message && typeof data?.error?.message === "string") {
23
- return data?.error?.message;
24
- }
25
- if (response?.statusText && typeof response?.statusText === "string") {
26
- return response?.statusText;
27
- }
28
- return "Missing error message";
29
- }
30
- export { decodeErrorMessageFromRequest };
@@ -1,17 +0,0 @@
1
- type DecodeRequestBodyFunction = (request: Request) => Promise<any>;
2
- /**
3
- * Decodes the body of an incoming request into a JavaScript object.
4
- *
5
- * This function attempts to parse the request body in the following order:
6
- * 1. Tries to parse the body as JSON.
7
- * 2. If JSON parsing fails, attempts to parse the body as URL-encoded form data.
8
- * 3. If both parsing attempts fail, logs the errors and returns an empty object.
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.
12
- *
13
- * @throws Logs errors to the console if the request body cannot be read or parsed.
14
- */
15
- declare const decodeRequestBody: DecodeRequestBodyFunction;
16
- export { decodeRequestBody };
17
- //# sourceMappingURL=decodeRequestBody.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decodeRequestBody.d.ts","sourceRoot":"","sources":["../../src/services/decodeRequestBody.ts"],"names":[],"mappings":"AAEA,KAAK,yBAAyB,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEpE;;;;;;;;;;;;GAYG;AAEH,QAAA,MAAM,iBAAiB,EAAE,yBAsBxB,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,38 +0,0 @@
1
- import { BadRequest } from "../http/badResponses/badRequest";
2
- /**
3
- * Decodes the body of an incoming request into a JavaScript object.
4
- *
5
- * This function attempts to parse the request body in the following order:
6
- * 1. Tries to parse the body as JSON.
7
- * 2. If JSON parsing fails, attempts to parse the body as URL-encoded form data.
8
- * 3. If both parsing attempts fail, logs the errors and returns an empty object.
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.
12
- *
13
- * @throws Logs errors to the console if the request body cannot be read or parsed.
14
- */
15
- const decodeRequestBody = async (req) => {
16
- let data;
17
- const arrayBuffer = await req.arrayBuffer();
18
- const text = new TextDecoder().decode(arrayBuffer);
19
- try {
20
- data = JSON.parse(text);
21
- }
22
- catch (jsonError) {
23
- try {
24
- if (text.includes("=")) {
25
- const formData = new URLSearchParams(text);
26
- data = Object.fromEntries(formData.entries());
27
- }
28
- else {
29
- throw new BadRequest("Invalid URLSearchParams format");
30
- }
31
- }
32
- catch (formDataError) {
33
- throw new BadRequest("Failed to extract data from request");
34
- }
35
- }
36
- return data;
37
- };
38
- export { decodeRequestBody };
@@ -1,44 +0,0 @@
1
- /**
2
- * Handles errors and converts them into appropriate HTTP responses.
3
- *
4
- * This function takes an error object and determines its type to return
5
- * the corresponding HTTP response. It supports both success and error
6
- * response types, converting them into a standardized format using the
7
- * `toResponse` method when applicable.
8
- *
9
- * @param error - The error object to handle. It can be an instance of various
10
- * HTTP response classes or a generic error.
11
- *
12
- * @returns The corresponding HTTP response object if the error matches a known
13
- * type, or `undefined` if no match is found.
14
- *
15
- * ### Supported Success Responses:
16
- * - `Found`
17
- * - `Created`
18
- * - `Updated`
19
- * - `Success`
20
- * - `NoContent`
21
- *
22
- * ### Supported Error Responses:
23
- * - `BadGateway`
24
- * - `BadRequest`
25
- * - `Conflict`
26
- * - `Forbidden`
27
- * - `NotFound`
28
- * - `NotImplemented`
29
- * - `ServerError`
30
- * - `Unauthorized`
31
- * - `UnprocessableEntity`
32
- *
33
- * ### Example Usage:
34
- * ```typescript
35
- * try {
36
- * // Some operation that might throw an error
37
- * } catch (error) {
38
- * return errorHandler(error);
39
- * }
40
- * ```
41
- */
42
- declare function errorHandler(error: any): Response;
43
- export { errorHandler };
44
- //# sourceMappingURL=errorHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/services/errorHandler.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,iBAAS,YAAY,CAAC,KAAK,EAAE,GAAG,GAAG,QAAQ,CAsC1C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,93 +0,0 @@
1
- import { BadGateway } from "../http/badResponses/badGateway";
2
- import { BadRequest } from "../http/badResponses/badRequest";
3
- import { Conflict } from "../http/badResponses/conflict";
4
- import { Forbidden } from "../http/badResponses/forbidden";
5
- import { NotFound } from "../http/badResponses/notFound";
6
- import { NotImplemented } from "../http/badResponses/notImplemented";
7
- import { ServerError } from "../http/badResponses/serverError";
8
- import { Unauthorized } from "../http/badResponses/unauthorized";
9
- import { UnprocessableEntity } from "../http/badResponses/unprocessableEntity";
10
- import { Created } from "../http/successResponses/created";
11
- import { Found } from "../http/successResponses/found";
12
- import { NoContent } from "../http/successResponses/noContent";
13
- import { Success } from "../http/successResponses/success";
14
- import { Updated } from "../http/successResponses/updated";
15
- /**
16
- * Handles errors and converts them into appropriate HTTP responses.
17
- *
18
- * This function takes an error object and determines its type to return
19
- * the corresponding HTTP response. It supports both success and error
20
- * response types, converting them into a standardized format using the
21
- * `toResponse` method when applicable.
22
- *
23
- * @param error - The error object to handle. It can be an instance of various
24
- * HTTP response classes or a generic error.
25
- *
26
- * @returns The corresponding HTTP response object if the error matches a known
27
- * type, or `undefined` if no match is found.
28
- *
29
- * ### Supported Success Responses:
30
- * - `Found`
31
- * - `Created`
32
- * - `Updated`
33
- * - `Success`
34
- * - `NoContent`
35
- *
36
- * ### Supported Error Responses:
37
- * - `BadGateway`
38
- * - `BadRequest`
39
- * - `Conflict`
40
- * - `Forbidden`
41
- * - `NotFound`
42
- * - `NotImplemented`
43
- * - `ServerError`
44
- * - `Unauthorized`
45
- * - `UnprocessableEntity`
46
- *
47
- * ### Example Usage:
48
- * ```typescript
49
- * try {
50
- * // Some operation that might throw an error
51
- * } catch (error) {
52
- * return errorHandler(error);
53
- * }
54
- * ```
55
- */
56
- function errorHandler(error) {
57
- switch (true) {
58
- case error instanceof Response:
59
- return error;
60
- case error instanceof Found:
61
- return error.toResponse();
62
- case error instanceof Created:
63
- return error.toResponse();
64
- case error instanceof Updated:
65
- return error.toResponse();
66
- case error instanceof Success:
67
- return error.toResponse();
68
- case error instanceof NoContent:
69
- return error.toResponse();
70
- }
71
- switch (true) {
72
- case error instanceof BadGateway:
73
- return error.toResponse();
74
- case error instanceof BadRequest:
75
- return error.toResponse();
76
- case error instanceof Conflict:
77
- return error.toResponse();
78
- case error instanceof Forbidden:
79
- return error.toResponse();
80
- case error instanceof NotFound:
81
- return error.toResponse();
82
- case error instanceof NotImplemented:
83
- return error.toResponse();
84
- case error instanceof ServerError:
85
- return error.toResponse();
86
- case error instanceof Unauthorized:
87
- return error.toResponse();
88
- case error instanceof UnprocessableEntity:
89
- return error.toResponse();
90
- }
91
- return new ServerError("Server error", error).toResponse();
92
- }
93
- export { errorHandler };
@@ -1,8 +0,0 @@
1
- type FlushDebugLogsProps = {
2
- scheme: "yellow" | "cyan" | "red" | "green";
3
- name: string;
4
- debugs: string[];
5
- };
6
- declare function flushDebugLogs(props: FlushDebugLogsProps): void;
7
- export { flushDebugLogs };
8
- //# sourceMappingURL=flushDebugLogs.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,20 +0,0 @@
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,59 +0,0 @@
1
- import type { ZodType } from "zod";
2
- type SuccessResponse<T extends FormParseProps> = {
3
- success: true;
4
- data: T[1] extends ZodType<infer U> ? U : never;
5
- };
6
- type ErrorResponse = {
7
- success: false;
8
- fields: {
9
- [x: string]: string;
10
- };
11
- fieldErrors: {
12
- [x: string]: string;
13
- };
14
- };
15
- type FormParseProps = [formData: {
16
- [k: string]: any;
17
- }, schema: ZodType];
18
- type FormParseReturnType<T extends FormParseProps> = SuccessResponse<T> | ErrorResponse;
19
- /**
20
- * Asynchronously parses form data using a Zod schema and returns the result.
21
- *
22
- * @template T - A type that extends `FormParseProps`.
23
- *
24
- * @param {T} param0 - An array containing the form data and the Zod schema.
25
- * @param {T[0]} param0[0] - The form data to be validated.
26
- * @param {T[1]} param0[1] - The Zod schema used for validation.
27
- *
28
- * @returns {Promise<FormParseReturnType<T>>} A promise that resolves to an object containing the validation result.
29
- * - If validation fails, it includes:
30
- * - `success`: A boolean indicating the validation status (false).
31
- * - `fieldErrors`: An object mapping field names to their respective error messages.
32
- * - `fields`: The original form data.
33
- * - If validation succeeds, it includes:
34
- * - `success`: A boolean indicating the validation status (true).
35
- * - `data`: The parsed and validated data.
36
- *
37
- * @example
38
- * ```typescript
39
- * import { z } from "zod";
40
- *
41
- * const schema = z.object({
42
- * name: z.string().min(1, "Name is required"),
43
- * age: z.number().min(18, "Must be at least 18"),
44
- * });
45
- *
46
- * const formData = { name: "", age: 17 };
47
- *
48
- * const result = await formAsyncParse([formData, schema]);
49
- *
50
- * if (!result.success) {
51
- * console.log(result.fieldErrors); // { name: "Name is required", age: "Must be at least 18" }
52
- * } else {
53
- * console.log(result.data); // Parsed data
54
- * }
55
- * ```
56
- */
57
- declare function formAsyncParse<T extends FormParseProps>([formData, schema,]: T): Promise<FormParseReturnType<T>>;
58
- export { formAsyncParse };
59
- //# sourceMappingURL=formAsyncParse.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,58 +0,0 @@
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,59 +0,0 @@
1
- import type { ZodType } from "zod";
2
- type SuccessResponse<T extends FormParseProps> = {
3
- success: true;
4
- data: T[1] extends ZodType<infer U> ? U : never;
5
- };
6
- type ErrorResponse = {
7
- success: false;
8
- fields: {
9
- [x: string]: string;
10
- };
11
- fieldErrors: {
12
- [x: string]: string;
13
- };
14
- };
15
- type FormParseProps = [formData: {
16
- [k: string]: any;
17
- }, schema: ZodType];
18
- type FormParseReturnType<T extends FormParseProps> = SuccessResponse<T> | ErrorResponse;
19
- /**
20
- * Parses form data using a Zod schema and returns the result.
21
- *
22
- * @template T - A type that extends `FormParseProps`.
23
- *
24
- * @param {T} param0 - An array containing the form data and the Zod schema.
25
- * @param {T[0]} param0[0] - The form data to be validated.
26
- * @param {T[1]} param0[1] - The Zod schema used for validation.
27
- *
28
- * @returns {FormParseReturnType<T>} An object containing the validation result.
29
- * - If validation fails, it includes:
30
- * - `success`: A boolean indicating the validation status (false).
31
- * - `fieldErrors`: An object mapping field names to their respective error messages.
32
- * - `fields`: The original form data.
33
- * - If validation succeeds, it includes:
34
- * - `success`: A boolean indicating the validation status (true).
35
- * - `data`: The parsed and validated data.
36
- *
37
- * @example
38
- * ```typescript
39
- * import { z } from "zod";
40
- *
41
- * const schema = z.object({
42
- * name: z.string().min(1, "Name is required"),
43
- * age: z.number().min(18, "Must be at least 18"),
44
- * });
45
- *
46
- * const formData = { name: "", age: 17 };
47
- *
48
- * const result = formParse([formData, schema]);
49
- *
50
- * if (!result.success) {
51
- * console.log(result.fieldErrors); // { name: "Name is required", age: "Must be at least 18" }
52
- * } else {
53
- * console.log(result.data); // Parsed data
54
- * }
55
- * ```
56
- */
57
- declare function formParse<T extends FormParseProps>([formData, schema,]: T): FormParseReturnType<T>;
58
- export { formParse };
59
- //# sourceMappingURL=formParse.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,58 +0,0 @@
1
- /**
2
- * 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 {FormParseReturnType<T>} 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 = formParse([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
- function formParse([formData, schema,]) {
40
- const zodResponse = schema.safeParse(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 { formParse };
@@ -1,17 +0,0 @@
1
- /**
2
- * Retrieves information about the caller of the current function.
3
- *
4
- * This function analyzes the stack trace to determine the file path and function name
5
- * of the caller. It excludes stack trace entries related to the `@arkyn/server` package
6
- * and attempts to resolve the file path relative to the project root directory.
7
- *
8
- * @returns An object containing:
9
- * - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
10
- * - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
11
- */
12
- declare function getCaller(): {
13
- functionName: string;
14
- callerInfo: string;
15
- };
16
- export { getCaller };
17
- //# sourceMappingURL=getCaller.d.ts.map
@@ -1 +0,0 @@
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,60 +0,0 @@
1
- import path from "path";
2
- import { DebugService } from "./debugService";
3
- /**
4
- * Retrieves information about the caller of the current function.
5
- *
6
- * This function analyzes the stack trace to determine the file path and function name
7
- * of the caller. It excludes stack trace entries related to the `@arkyn/server` package
8
- * and attempts to resolve the file path relative to the project root directory.
9
- *
10
- * @returns An object containing:
11
- * - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
12
- * - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
13
- */
14
- function getCaller() {
15
- const projectRoot = process.cwd();
16
- const err = new Error();
17
- const stack = err.stack || "";
18
- const stackLines = stack.split("\n").map((line) => line.trim());
19
- const ignoreFiles = DebugService.ignoreFiles;
20
- let callerIndex = 2;
21
- while (callerIndex < stackLines.length &&
22
- (stackLines[callerIndex].includes("node:internal") ||
23
- stackLines[callerIndex].includes("/node_modules/"))) {
24
- callerIndex++;
25
- }
26
- if (ignoreFiles.length > 0) {
27
- while (callerIndex < stackLines.length &&
28
- ignoreFiles.some((ignoreFile) => stackLines[callerIndex].includes(ignoreFile))) {
29
- callerIndex++;
30
- }
31
- }
32
- const callerLine = stackLines[callerIndex] || "";
33
- let functionName = "Unknown function";
34
- let callerInfo = "Unknown caller";
35
- const namedFunctionMatch = callerLine.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
36
- if (namedFunctionMatch) {
37
- functionName = namedFunctionMatch[1];
38
- callerInfo = namedFunctionMatch[2];
39
- }
40
- else {
41
- const anonymousFunctionMatch = callerLine.match(/at\s+(.+)/);
42
- if (anonymousFunctionMatch) {
43
- callerInfo = anonymousFunctionMatch[1];
44
- const objectMethodMatch = callerInfo.match(/at\s+([^(\s]+)\s+/);
45
- if (objectMethodMatch && objectMethodMatch[1] !== "new") {
46
- functionName = objectMethodMatch[1];
47
- }
48
- }
49
- }
50
- if (callerInfo.includes("(")) {
51
- callerInfo = callerInfo.substring(callerInfo.indexOf("(") + 1, callerInfo.lastIndexOf(")"));
52
- }
53
- callerInfo = callerInfo.split(":").slice(0, -2).join(":");
54
- try {
55
- callerInfo = path.relative(projectRoot, callerInfo);
56
- }
57
- catch (e) { }
58
- return { functionName, callerInfo };
59
- }
60
- export { getCaller };
@@ -1,28 +0,0 @@
1
- type GetScopedParamsFunction = (request: Request, scope?: string) => URLSearchParams;
2
- /**
3
- * Extracts and returns scoped query parameters from a request URL.
4
- *
5
- * @param request - The incoming request object containing the URL.
6
- * @param scope - An optional string representing the scope prefix for filtering query parameters.
7
- * If no scope is provided, all query parameters are returned.
8
- *
9
- * @returns A `URLSearchParams` object containing the scoped query parameters.
10
- * If a scope is provided, only parameters with keys starting with the scope
11
- * (e.g., `scope:key`) are included, and the scope prefix is removed from the keys.
12
- * If no scope is provided, all query parameters are returned as-is.
13
- *
14
- * @example
15
- * // Example 1: No scope provided
16
- * const request = { url: "https://example.com?key1=value1&key2=value2" };
17
- * const params = getScopedParams(request);
18
- * console.log(params.toString()); // Output: "key1=value1&key2=value2"
19
- *
20
- * @example
21
- * // Example 2: Scope provided
22
- * const request = { url: "https://example.com?scope:key1=value1&scope:key2=value2&key3=value3" };
23
- * const params = getScopedParams(request, "scope");
24
- * console.log(params.toString()); // Output: "key1=value1&key2=value2"
25
- */
26
- declare const getScopedParams: GetScopedParamsFunction;
27
- export { getScopedParams };
28
- //# sourceMappingURL=getScopedParams.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getScopedParams.d.ts","sourceRoot":"","sources":["../../src/services/getScopedParams.ts"],"names":[],"mappings":"AAAA,KAAK,uBAAuB,GAAG,CAC7B,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,MAAM,KACX,eAAe,CAAC;AACrB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,QAAA,MAAM,eAAe,EAAE,uBAWtB,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -1,34 +0,0 @@
1
- /**
2
- * Extracts and returns scoped query parameters from a request URL.
3
- *
4
- * @param request - The incoming request object containing the URL.
5
- * @param scope - An optional string representing the scope prefix for filtering query parameters.
6
- * If no scope is provided, all query parameters are returned.
7
- *
8
- * @returns A `URLSearchParams` object containing the scoped query parameters.
9
- * If a scope is provided, only parameters with keys starting with the scope
10
- * (e.g., `scope:key`) are included, and the scope prefix is removed from the keys.
11
- * If no scope is provided, all query parameters are returned as-is.
12
- *
13
- * @example
14
- * // Example 1: No scope provided
15
- * const request = { url: "https://example.com?key1=value1&key2=value2" };
16
- * const params = getScopedParams(request);
17
- * console.log(params.toString()); // Output: "key1=value1&key2=value2"
18
- *
19
- * @example
20
- * // Example 2: Scope provided
21
- * const request = { url: "https://example.com?scope:key1=value1&scope:key2=value2&key3=value3" };
22
- * const params = getScopedParams(request, "scope");
23
- * console.log(params.toString()); // Output: "key1=value1&key2=value2"
24
- */
25
- const getScopedParams = (request, scope = "") => {
26
- const url = new URL(request.url);
27
- if (scope === "")
28
- return url.searchParams;
29
- const scopedSearchParams = Array.from(url.searchParams.entries())
30
- .filter(([key]) => key.startsWith(`${scope}:`))
31
- .map(([key, value]) => [key.replace(`${scope}:`, ""), value]);
32
- return new URLSearchParams(scopedSearchParams);
33
- };
34
- export { getScopedParams };