@arkyn/server 3.0.1-beta.10 → 3.0.1-beta.102

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +368 -65
  2. package/dist/api/arkynLogRequest.d.ts +1 -1
  3. package/dist/api/arkynLogRequest.d.ts.map +1 -1
  4. package/dist/api/arkynLogRequest.js +24 -18
  5. package/dist/api/makeRequest.d.ts.map +1 -1
  6. package/dist/api/makeRequest.js +6 -2
  7. package/dist/bundle.js +1507 -0
  8. package/dist/bundle.umd.cjs +10 -0
  9. package/dist/http/badResponses/_badResponse.d.ts +11 -0
  10. package/dist/http/badResponses/_badResponse.d.ts.map +1 -0
  11. package/dist/http/badResponses/_badResponse.js +20 -0
  12. package/dist/http/badResponses/badGateway.d.ts +2 -1
  13. package/dist/http/badResponses/badGateway.d.ts.map +1 -1
  14. package/dist/http/badResponses/badGateway.js +9 -3
  15. package/dist/http/badResponses/badRequest.d.ts +2 -1
  16. package/dist/http/badResponses/badRequest.d.ts.map +1 -1
  17. package/dist/http/badResponses/badRequest.js +9 -3
  18. package/dist/http/badResponses/conflict.d.ts +2 -1
  19. package/dist/http/badResponses/conflict.d.ts.map +1 -1
  20. package/dist/http/badResponses/conflict.js +9 -3
  21. package/dist/http/badResponses/forbidden.d.ts +2 -1
  22. package/dist/http/badResponses/forbidden.d.ts.map +1 -1
  23. package/dist/http/badResponses/forbidden.js +9 -3
  24. package/dist/http/badResponses/notFound.d.ts +2 -1
  25. package/dist/http/badResponses/notFound.d.ts.map +1 -1
  26. package/dist/http/badResponses/notFound.js +9 -3
  27. package/dist/http/badResponses/notImplemented.d.ts +2 -1
  28. package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
  29. package/dist/http/badResponses/notImplemented.js +9 -3
  30. package/dist/http/badResponses/serverError.d.ts +2 -1
  31. package/dist/http/badResponses/serverError.d.ts.map +1 -1
  32. package/dist/http/badResponses/serverError.js +9 -3
  33. package/dist/http/badResponses/unauthorized.d.ts +2 -1
  34. package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
  35. package/dist/http/badResponses/unauthorized.js +9 -3
  36. package/dist/http/badResponses/unprocessableEntity.d.ts +3 -2
  37. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
  38. package/dist/http/badResponses/unprocessableEntity.js +9 -4
  39. package/dist/http/successResponses/_successResponse.d.ts +22 -0
  40. package/dist/http/successResponses/_successResponse.d.ts.map +1 -0
  41. package/dist/http/successResponses/_successResponse.js +37 -0
  42. package/dist/http/successResponses/created.d.ts +6 -2
  43. package/dist/http/successResponses/created.d.ts.map +1 -1
  44. package/dist/http/successResponses/created.js +5 -2
  45. package/dist/http/successResponses/found.d.ts +6 -2
  46. package/dist/http/successResponses/found.d.ts.map +1 -1
  47. package/dist/http/successResponses/found.js +5 -2
  48. package/dist/http/successResponses/noContent.d.ts +2 -1
  49. package/dist/http/successResponses/noContent.d.ts.map +1 -1
  50. package/dist/http/successResponses/noContent.js +4 -1
  51. package/dist/http/successResponses/success.d.ts +6 -2
  52. package/dist/http/successResponses/success.d.ts.map +1 -1
  53. package/dist/http/successResponses/success.js +5 -2
  54. package/dist/http/successResponses/updated.d.ts +6 -2
  55. package/dist/http/successResponses/updated.d.ts.map +1 -1
  56. package/dist/http/successResponses/updated.js +5 -2
  57. package/dist/index.d.ts +13 -3
  58. package/dist/index.d.ts.map +1 -1
  59. package/dist/index.js +14 -4
  60. package/dist/{config/apiInstance.d.ts → services/apiService.d.ts} +25 -21
  61. package/dist/services/apiService.d.ts.map +1 -0
  62. package/dist/{config/apiInstance.js → services/apiService.js} +45 -23
  63. package/dist/{config/arkynLogInstance.d.ts → services/arkynLogService.d.ts} +11 -11
  64. package/dist/services/arkynLogService.d.ts.map +1 -0
  65. package/dist/{config/arkynLogInstance.js → services/arkynLogService.js} +8 -11
  66. package/dist/services/debugService.d.ts +54 -0
  67. package/dist/services/debugService.d.ts.map +1 -0
  68. package/dist/services/debugService.js +57 -0
  69. package/dist/services/flushDebugLogs.d.ts +8 -0
  70. package/dist/services/flushDebugLogs.d.ts.map +1 -0
  71. package/dist/services/flushDebugLogs.js +20 -0
  72. package/{src/services/formParse.ts → dist/services/formAsyncParse.d.ts} +20 -44
  73. package/dist/services/formAsyncParse.d.ts.map +1 -0
  74. package/dist/services/formAsyncParse.js +58 -0
  75. package/dist/services/formParse.d.ts +3 -3
  76. package/dist/services/formParse.d.ts.map +1 -1
  77. package/dist/services/formParse.js +7 -5
  78. package/dist/services/getCaller.d.ts.map +1 -1
  79. package/dist/services/getCaller.js +9 -14
  80. package/dist/services/measureRouteExecution.d.ts +3 -0
  81. package/dist/services/measureRouteExecution.d.ts.map +1 -0
  82. package/dist/services/measureRouteExecution.js +24 -0
  83. package/dist/services/schemaValidator.d.ts +148 -3
  84. package/dist/services/schemaValidator.d.ts.map +1 -1
  85. package/dist/services/schemaValidator.js +160 -4
  86. package/dist/validations/validateCep.d.ts +24 -0
  87. package/dist/validations/validateCep.d.ts.map +1 -0
  88. package/dist/validations/validateCep.js +33 -0
  89. package/dist/validations/validateCnpj.d.ts +22 -0
  90. package/dist/validations/validateCnpj.d.ts.map +1 -0
  91. package/dist/validations/validateCnpj.js +52 -0
  92. package/dist/validations/validateCpf.d.ts +24 -0
  93. package/dist/validations/validateCpf.d.ts.map +1 -0
  94. package/dist/validations/validateCpf.js +54 -0
  95. package/dist/validations/validateDate.d.ts +34 -0
  96. package/dist/validations/validateDate.d.ts.map +1 -0
  97. package/dist/validations/validateDate.js +73 -0
  98. package/dist/validations/validateEmail.d.ts +22 -0
  99. package/dist/validations/validateEmail.d.ts.map +1 -0
  100. package/dist/validations/validateEmail.js +123 -0
  101. package/dist/validations/validatePassword.d.ts +21 -0
  102. package/dist/validations/validatePassword.d.ts.map +1 -0
  103. package/dist/validations/validatePassword.js +34 -0
  104. package/dist/validations/validatePhone.d.ts +29 -0
  105. package/dist/validations/validatePhone.d.ts.map +1 -0
  106. package/dist/validations/validatePhone.js +44 -0
  107. package/dist/validations/validateRg.d.ts +22 -0
  108. package/dist/validations/validateRg.d.ts.map +1 -0
  109. package/dist/validations/validateRg.js +31 -0
  110. package/package.json +34 -18
  111. package/dist/config/apiInstance.d.ts.map +0 -1
  112. package/dist/config/arkynLogInstance.d.ts.map +0 -1
  113. package/dist/services/httpDebug.d.ts +0 -35
  114. package/dist/services/httpDebug.d.ts.map +0 -1
  115. package/dist/services/httpDebug.js +0 -52
  116. package/src/api/arkynLogRequest.ts +0 -118
  117. package/src/api/deleteRequest.ts +0 -22
  118. package/src/api/getRequest.ts +0 -20
  119. package/src/api/makeRequest.ts +0 -118
  120. package/src/api/patchRequest.ts +0 -22
  121. package/src/api/postRequest.ts +0 -22
  122. package/src/api/putRequest.ts +0 -22
  123. package/src/config/apiInstance.ts +0 -148
  124. package/src/config/arkynLogInstance.ts +0 -70
  125. package/src/http/badResponses/badGateway.ts +0 -63
  126. package/src/http/badResponses/badRequest.ts +0 -63
  127. package/src/http/badResponses/conflict.ts +0 -63
  128. package/src/http/badResponses/forbidden.ts +0 -63
  129. package/src/http/badResponses/notFound.ts +0 -63
  130. package/src/http/badResponses/notImplemented.ts +0 -63
  131. package/src/http/badResponses/serverError.ts +0 -63
  132. package/src/http/badResponses/unauthorized.ts +0 -63
  133. package/src/http/badResponses/unprocessableEntity.ts +0 -79
  134. package/src/http/successResponses/created.ts +0 -64
  135. package/src/http/successResponses/found.ts +0 -67
  136. package/src/http/successResponses/noContent.ts +0 -42
  137. package/src/http/successResponses/success.ts +0 -64
  138. package/src/http/successResponses/updated.ts +0 -64
  139. package/src/index.ts +0 -31
  140. package/src/mapper/arkynLogRequestMapper.ts +0 -73
  141. package/src/services/decodeErrorMessageFromRequest.ts +0 -36
  142. package/src/services/decodeRequestBody.ts +0 -43
  143. package/src/services/errorHandler.ts +0 -99
  144. package/src/services/getCaller.ts +0 -82
  145. package/src/services/getScopedParams.ts +0 -43
  146. package/src/services/httpDebug.ts +0 -61
  147. package/src/services/schemaValidator.ts +0 -66
  148. package/src/types/ApiResponseDTO.ts +0 -19
  149. package/tsconfig.json +0 -21
  150. package/vitest.config.ts +0 -5
@@ -0,0 +1,37 @@
1
+ import { flushDebugLogs } from "../../services/flushDebugLogs";
2
+ import { getCaller } from "../../services/getCaller";
3
+ /**
4
+ * Base class for handling bad HTTP responses with debugging capabilities.
5
+ * Provides logging functionality to track response errors and their context.
6
+ */
7
+ class SuccessResponse {
8
+ /**
9
+ * Logs debug information for success responses including caller context and response details.
10
+ *
11
+ * @param name - The name/type of the success response being logged
12
+ * @param body - The response body or success data to be logged
13
+ * @param cause - Optional additional cause information for the error
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const SuccessResponse = new SuccessResponse();
18
+ * SuccessResponse.onDebug("ValidationError", { field: "email", message: "Invalid format" });
19
+ * ```
20
+ */
21
+ onDebug(name, body, cause) {
22
+ const debugs = [];
23
+ const { callerInfo, functionName } = getCaller();
24
+ debugs.push(`${name} initialized\n`);
25
+ debugs.push(`Caller Function: ${functionName}\n`);
26
+ debugs.push(`Caller Location: ${callerInfo}\n`);
27
+ debugs.push(`Body: ${JSON.stringify(body, null, 2)}\n`);
28
+ if (cause)
29
+ debugs.push(`Cause: ${JSON.stringify(cause, null, 2)}\n`);
30
+ flushDebugLogs({
31
+ scheme: "green",
32
+ name: "ARKYN-SUCCESS-RESPONSE-DEBUG",
33
+ debugs,
34
+ });
35
+ }
36
+ }
37
+ export { SuccessResponse };
@@ -1,3 +1,7 @@
1
+ import { SuccessResponse } from "./_successResponse";
2
+ type InitProps = ResponseInit & {
3
+ message?: string;
4
+ };
1
5
  /**
2
6
  * Represents a successful HTTP response with a status code of 201 (Created).
3
7
  * This class is used to standardize the structure of a "Created" response,
@@ -5,7 +9,7 @@
5
9
  *
6
10
  * @template T - The type of the response body.
7
11
  */
8
- declare class Created<T> {
12
+ declare class Created<T> extends SuccessResponse {
9
13
  body: T;
10
14
  headers: ResponseInit["headers"];
11
15
  status: number;
@@ -16,7 +20,7 @@ declare class Created<T> {
16
20
  * @param body - The response body to be included in the HTTP response.
17
21
  * @param init - Optional initialization object for customizing headers, status, and status text.
18
22
  */
19
- constructor(body: T, init?: ResponseInit);
23
+ constructor(body: T, init?: InitProps);
20
24
  /**
21
25
  * Converts the `Created` instance into a `Response` object with a JSON body.
22
26
  * This method ensures the response has the appropriate headers, status, and status text.
@@ -1 +1 @@
1
- {"version":3,"file":"created.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/created.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CASnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"created.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/created.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,KAAK,SAAS,GAAG,YAAY,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC,CAAE,SAAQ,eAAe;IACtC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;IAWrC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CASnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { SuccessResponse } from "./_successResponse";
1
2
  /**
2
3
  * Represents a successful HTTP response with a status code of 201 (Created).
3
4
  * This class is used to standardize the structure of a "Created" response,
@@ -5,7 +6,7 @@
5
6
  *
6
7
  * @template T - The type of the response body.
7
8
  */
8
- class Created {
9
+ class Created extends SuccessResponse {
9
10
  body;
10
11
  headers;
11
12
  status;
@@ -17,10 +18,12 @@ class Created {
17
18
  * @param init - Optional initialization object for customizing headers, status, and status text.
18
19
  */
19
20
  constructor(body, init) {
20
- this.body = body;
21
+ super();
22
+ this.body = { ...body, name: "Created", message: init?.message };
21
23
  this.headers = init?.headers || {};
22
24
  this.status = init?.status || 201;
23
25
  this.statusText = init?.statusText || "Resource created successfully";
26
+ this.onDebug("Created", body);
24
27
  }
25
28
  /**
26
29
  * Converts the `Created` instance into a `Response` object with a JSON body.
@@ -1,3 +1,7 @@
1
+ import { SuccessResponse } from "./_successResponse";
2
+ type InitProps = ResponseInit & {
3
+ message?: string;
4
+ };
1
5
  /**
2
6
  * Represents an HTTP 302 Found response.
3
7
  * This class is used to create a standardized HTTP response with a status of 302 (Found),
@@ -5,7 +9,7 @@
5
9
  *
6
10
  * @template T - The type of the response body.
7
11
  */
8
- declare class Found<T> {
12
+ declare class Found<T> extends SuccessResponse {
9
13
  body: T;
10
14
  headers: ResponseInit["headers"];
11
15
  status: number;
@@ -19,7 +23,7 @@ declare class Found<T> {
19
23
  * - `status`: HTTP status code (default is 302).
20
24
  * - `statusText`: HTTP status text (default is "Found").
21
25
  */
22
- constructor(body: T, init?: ResponseInit);
26
+ constructor(body: T, init?: InitProps);
23
27
  /**
24
28
  * Converts the `Found` instance into a `Response` object.
25
29
  * This method serializes the response body as JSON and includes the appropriate headers.
@@ -1 +1 @@
1
- {"version":3,"file":"found.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/found.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAM,KAAK,CAAC,CAAC;IACX,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;OAQG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY;IAOxC;;;;;OAKG;IAEH,UAAU;IAUV;;;;;OAKG;IAEH,MAAM;CASP;AAED,OAAO,EAAE,KAAK,EAAE,CAAC"}
1
+ {"version":3,"file":"found.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/found.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,KAAK,SAAS,GAAG,YAAY,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AAEH,cAAM,KAAK,CAAC,CAAC,CAAE,SAAQ,eAAe;IACpC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;OAQG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;IAWrC;;;;;OAKG;IAEH,UAAU;IAUV;;;;;OAKG;IAEH,MAAM;CASP;AAED,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { SuccessResponse } from "./_successResponse";
1
2
  /**
2
3
  * Represents an HTTP 302 Found response.
3
4
  * This class is used to create a standardized HTTP response with a status of 302 (Found),
@@ -5,7 +6,7 @@
5
6
  *
6
7
  * @template T - The type of the response body.
7
8
  */
8
- class Found {
9
+ class Found extends SuccessResponse {
9
10
  body;
10
11
  headers;
11
12
  status;
@@ -20,10 +21,12 @@ class Found {
20
21
  * - `statusText`: HTTP status text (default is "Found").
21
22
  */
22
23
  constructor(body, init) {
23
- this.body = body;
24
+ super();
25
+ this.body = { ...body, name: "Found", message: init?.message };
24
26
  this.headers = init?.headers || {};
25
27
  this.status = init?.status || 302;
26
28
  this.statusText = init?.statusText || "Found";
29
+ this.onDebug("Found", body);
27
30
  }
28
31
  /**
29
32
  * Converts the `Found` instance into a `Response` object.
@@ -1,9 +1,10 @@
1
+ import { SuccessResponse } from "./_successResponse";
1
2
  /**
2
3
  * Represents a successful HTTP response with a status code of 204 (No Content).
3
4
  * This class is used to standardize the structure of a "No Content" response,
4
5
  * including headers, status, and status text.
5
6
  */
6
- declare class NoContent {
7
+ declare class NoContent extends SuccessResponse {
7
8
  headers: ResponseInit["headers"];
8
9
  status: number;
9
10
  statusText: string;
@@ -1 +1 @@
1
- {"version":3,"file":"noContent.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/noContent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAM,SAAS;IACb,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;gBAES,IAAI,CAAC,EAAE,YAAY;IAM/B;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;CASvB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"noContent.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/noContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;GAIG;AAEH,cAAM,SAAU,SAAQ,eAAe;IACrC,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;gBAES,IAAI,CAAC,EAAE,YAAY;IAU/B;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;CASvB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,9 +1,10 @@
1
+ import { SuccessResponse } from "./_successResponse";
1
2
  /**
2
3
  * Represents a successful HTTP response with a status code of 204 (No Content).
3
4
  * This class is used to standardize the structure of a "No Content" response,
4
5
  * including headers, status, and status text.
5
6
  */
6
- class NoContent {
7
+ class NoContent extends SuccessResponse {
7
8
  headers;
8
9
  status;
9
10
  statusText;
@@ -13,9 +14,11 @@ class NoContent {
13
14
  * @param init - Optional initialization object for customizing headers, status, and status text.
14
15
  */
15
16
  constructor(init) {
17
+ super();
16
18
  this.headers = init?.headers || {};
17
19
  this.status = init?.status || 204;
18
20
  this.statusText = init?.statusText ?? "No content";
21
+ this.onDebug("No content", null);
19
22
  }
20
23
  /**
21
24
  * Converts the `NoContent` instance into a `Response` object.
@@ -1,3 +1,7 @@
1
+ import { SuccessResponse } from "./_successResponse";
2
+ type InitProps = ResponseInit & {
3
+ message?: string;
4
+ };
1
5
  /**
2
6
  * Represents a successful HTTP response with a status code of 200 (OK).
3
7
  * This class is used to standardize the structure of a "Success" response,
@@ -5,7 +9,7 @@
5
9
  *
6
10
  * @template T - The type of the response body.
7
11
  */
8
- declare class Success<T> {
12
+ declare class Success<T> extends SuccessResponse {
9
13
  body: T;
10
14
  headers: ResponseInit["headers"];
11
15
  status: number;
@@ -16,7 +20,7 @@ declare class Success<T> {
16
20
  * @param body - The response body to be included in the HTTP response.
17
21
  * @param init - Optional initialization object for customizing headers, status, and status text.
18
22
  */
19
- constructor(body: T, init?: ResponseInit);
23
+ constructor(body: T, init?: InitProps);
20
24
  /**
21
25
  * Converts the `Success` instance into a `Response` object with a JSON body.
22
26
  * This method ensures the response has the appropriate headers, status, and status text.
@@ -1 +1 @@
1
- {"version":3,"file":"success.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/success.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CASnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"success.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/success.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,KAAK,SAAS,GAAG,YAAY,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC,CAAE,SAAQ,eAAe;IACtC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;IAWrC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CASnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { SuccessResponse } from "./_successResponse";
1
2
  /**
2
3
  * Represents a successful HTTP response with a status code of 200 (OK).
3
4
  * This class is used to standardize the structure of a "Success" response,
@@ -5,7 +6,7 @@
5
6
  *
6
7
  * @template T - The type of the response body.
7
8
  */
8
- class Success {
9
+ class Success extends SuccessResponse {
9
10
  body;
10
11
  headers;
11
12
  status;
@@ -17,10 +18,12 @@ class Success {
17
18
  * @param init - Optional initialization object for customizing headers, status, and status text.
18
19
  */
19
20
  constructor(body, init) {
20
- this.body = body;
21
+ super();
22
+ this.body = { ...body, name: "Success", message: init?.message };
21
23
  this.headers = init?.headers || {};
22
24
  this.status = init?.status || 200;
23
25
  this.statusText = init?.statusText ?? "OK";
26
+ this.onDebug("Success", body);
24
27
  }
25
28
  /**
26
29
  * Converts the `Success` instance into a `Response` object with a JSON body.
@@ -1,3 +1,7 @@
1
+ import { SuccessResponse } from "./_successResponse";
2
+ type InitProps = ResponseInit & {
3
+ message?: string;
4
+ };
1
5
  /**
2
6
  * Represents a successful HTTP response with a status code of 200 (OK) or other custom status codes.
3
7
  * This class is used to standardize the structure of an "Updated" response,
@@ -5,7 +9,7 @@
5
9
  *
6
10
  * @template T - The type of the response body.
7
11
  */
8
- declare class Updated<T> {
12
+ declare class Updated<T> extends SuccessResponse {
9
13
  body: T;
10
14
  headers: ResponseInit["headers"];
11
15
  status: number;
@@ -16,7 +20,7 @@ declare class Updated<T> {
16
20
  * @param body - The response body to be included in the HTTP response.
17
21
  * @param init - Optional initialization object for customizing headers, status, and status text.
18
22
  */
19
- constructor(body: T, init?: ResponseInit);
23
+ constructor(body: T, init?: InitProps);
20
24
  /**
21
25
  * Converts the `Updated` instance into a `Response` object with a JSON body.
22
26
  * This method ensures the response has the appropriate headers, status, and status text.
@@ -1 +1 @@
1
- {"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/updated.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CASnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/updated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,KAAK,SAAS,GAAG,YAAY,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC,CAAE,SAAQ,eAAe;IACtC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;IAWrC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CASnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { SuccessResponse } from "./_successResponse";
1
2
  /**
2
3
  * Represents a successful HTTP response with a status code of 200 (OK) or other custom status codes.
3
4
  * This class is used to standardize the structure of an "Updated" response,
@@ -5,7 +6,7 @@
5
6
  *
6
7
  * @template T - The type of the response body.
7
8
  */
8
- class Updated {
9
+ class Updated extends SuccessResponse {
9
10
  body;
10
11
  headers;
11
12
  status;
@@ -17,10 +18,12 @@ class Updated {
17
18
  * @param init - Optional initialization object for customizing headers, status, and status text.
18
19
  */
19
20
  constructor(body, init) {
20
- this.body = body;
21
+ super();
22
+ this.body = { ...body, name: "Updated", message: init?.message };
21
23
  this.headers = init?.headers || {};
22
24
  this.status = init?.status || 200;
23
25
  this.statusText = init?.statusText || "Resource updated successfully";
26
+ this.onDebug("Updated", body);
24
27
  }
25
28
  /**
26
29
  * Converts the `Updated` instance into a `Response` object with a JSON body.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- export { ApiInstance } from "./config/apiInstance";
2
- export { ArkynLogInstance } from "./config/arkynLogInstance";
3
1
  export { BadGateway } from "./http/badResponses/badGateway";
4
2
  export { BadRequest } from "./http/badResponses/badRequest";
5
3
  export { Conflict } from "./http/badResponses/conflict";
@@ -14,12 +12,24 @@ export { Found } from "./http/successResponses/found";
14
12
  export { NoContent } from "./http/successResponses/noContent";
15
13
  export { Success } from "./http/successResponses/success";
16
14
  export { Updated } from "./http/successResponses/updated";
15
+ export { ApiService } from "./services/apiService";
16
+ export { ArkynLogService } from "./services/arkynLogService";
17
+ export { DebugService } from "./services/debugService";
17
18
  export { decodeErrorMessageFromRequest } from "./services/decodeErrorMessageFromRequest";
18
19
  export { decodeRequestBody } from "./services/decodeRequestBody";
19
20
  export { errorHandler } from "./services/errorHandler";
21
+ export { flushDebugLogs } from "./services/flushDebugLogs";
22
+ export { formAsyncParse } from "./services/formAsyncParse";
20
23
  export { formParse } from "./services/formParse";
21
24
  export { getCaller } from "./services/getCaller";
22
25
  export { getScopedParams } from "./services/getScopedParams";
23
- export { httpDebug } from "./services/httpDebug";
24
26
  export { SchemaValidator } from "./services/schemaValidator";
27
+ export { validateCep } from "./validations/validateCep";
28
+ export { validateCnpj } from "./validations/validateCnpj";
29
+ export { validateCpf } from "./validations/validateCpf";
30
+ export { validateDate } from "./validations/validateDate";
31
+ export { validateEmail } from "./validations/validateEmail";
32
+ export { validatePassword } from "./validations/validatePassword";
33
+ export { validatePhone } from "./validations/validatePhone";
34
+ export { validateRg } from "./validations/validateRg";
25
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAG9E,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAG1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAG9E,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- // config
2
- export { ApiInstance } from "./config/apiInstance";
3
- export { ArkynLogInstance } from "./config/arkynLogInstance";
4
1
  // http bad responses
5
2
  export { BadGateway } from "./http/badResponses/badGateway";
6
3
  export { BadRequest } from "./http/badResponses/badRequest";
@@ -18,11 +15,24 @@ export { NoContent } from "./http/successResponses/noContent";
18
15
  export { Success } from "./http/successResponses/success";
19
16
  export { Updated } from "./http/successResponses/updated";
20
17
  // services
18
+ export { ApiService } from "./services/apiService";
19
+ export { ArkynLogService } from "./services/arkynLogService";
20
+ export { DebugService } from "./services/debugService";
21
21
  export { decodeErrorMessageFromRequest } from "./services/decodeErrorMessageFromRequest";
22
22
  export { decodeRequestBody } from "./services/decodeRequestBody";
23
23
  export { errorHandler } from "./services/errorHandler";
24
+ export { flushDebugLogs } from "./services/flushDebugLogs";
25
+ export { formAsyncParse } from "./services/formAsyncParse";
24
26
  export { formParse } from "./services/formParse";
25
27
  export { getCaller } from "./services/getCaller";
26
28
  export { getScopedParams } from "./services/getScopedParams";
27
- export { httpDebug } from "./services/httpDebug";
28
29
  export { SchemaValidator } from "./services/schemaValidator";
30
+ // validates
31
+ export { validateCep } from "./validations/validateCep";
32
+ export { validateCnpj } from "./validations/validateCnpj";
33
+ export { validateCpf } from "./validations/validateCpf";
34
+ export { validateDate } from "./validations/validateDate";
35
+ export { validateEmail } from "./validations/validateEmail";
36
+ export { validatePassword } from "./validations/validatePassword";
37
+ export { validatePhone } from "./validations/validatePhone";
38
+ export { validateRg } from "./validations/validateRg";
@@ -1,7 +1,8 @@
1
- type ApiInstanceContructorProps = {
1
+ type ApiServiceConstructorProps = {
2
2
  baseUrl: string;
3
3
  baseHeaders?: HeadersInit;
4
4
  baseToken?: string | null;
5
+ enableDebug?: boolean;
5
6
  };
6
7
  type ApiRequestDataWithoutBodyProps = {
7
8
  headers?: HeadersInit;
@@ -15,23 +16,26 @@ type ApiRequestDataWithBodyProps = {
15
16
  /**
16
17
  * Class representing an API instance to handle HTTP requests with base configurations.
17
18
  */
18
- declare class ApiInstance {
19
+ declare class ApiService {
19
20
  private baseUrl;
20
21
  private baseHeaders?;
21
22
  private baseToken?;
23
+ private enableDebug?;
22
24
  /**
23
- * Creates an instance of ApiInstance.
25
+ * Creates an instance of ApiService.
24
26
  * @param props - The configuration properties for the API instance.
25
27
  * @param props.baseUrl - The base URL for the API.
26
28
  * @param props.baseHeaders - Optional base headers to include in all requests.
27
29
  * @param props.baseToken - Optional base token for authorization.
30
+ * @param props.enableDebug - Optional flag to enable debug logging for requests.
28
31
  */
29
- constructor(props: ApiInstanceContructorProps);
32
+ constructor(props: ApiServiceConstructorProps);
30
33
  /**
31
34
  * Generates the full URL by appending the route to the base URL.
32
35
  * @param route - The route to append to the base URL.
33
36
  * @returns The full URL as a string.
34
37
  */
38
+ private onDebug;
35
39
  private generateURL;
36
40
  /**
37
41
  * Generates the headers for a request by merging base headers, provided headers, and tokens.
@@ -41,40 +45,40 @@ declare class ApiInstance {
41
45
  */
42
46
  private generateHeaders;
43
47
  /**
44
- * Sends a GET request to the specified route.
45
- * @param route - The API route to send the GET request to.
48
+ * Sends a get request to the specified endpoint.
49
+ * @param endpoint - The API endpoint to send the get request to.
46
50
  * @param data - The request data, including optional headers and token.
47
51
  * @returns The API response data.
48
52
  */
49
- GET(route: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
53
+ get(endpoint: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
50
54
  /**
51
- * Sends a POST request to the specified route.
52
- * @param route - The API route to send the POST request to.
55
+ * Sends a post request to the specified endpoint.
56
+ * @param endpoint - The API endpoint to send the post request to.
53
57
  * @param data - The request data, including body, optional headers, and token.
54
58
  * @returns The API response data.
55
59
  */
56
- POST(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
60
+ post(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
57
61
  /**
58
- * Sends a PUT request to the specified route.
59
- * @param route - The API route to send the PUT request to.
62
+ * Sends a put request to the specified endpoint.
63
+ * @param endpoint - The API endpoint to send the put request to.
60
64
  * @param data - The request data, including body, optional headers, and token.
61
65
  * @returns The API response data.
62
66
  */
63
- PUT(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
67
+ put(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
64
68
  /**
65
- * Sends a PATCH request to the specified route.
66
- * @param route - The API route to send the PATCH request to.
69
+ * Sends a patch request to the specified endpoint.
70
+ * @param endpoint - The API endpoint to send the patch request to.
67
71
  * @param data - The request data, including body, optional headers, and token.
68
72
  * @returns The API response data.
69
73
  */
70
- PATCH(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
74
+ patch(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
71
75
  /**
72
- * Sends a DELETE request to the specified route.
73
- * @param route - The API route to send the DELETE request to.
76
+ * Sends a delete request to the specified endpoint.
77
+ * @param endpoint - The API endpoint to send the delete request to.
74
78
  * @param data - The request data, including body, optional headers, and token.
75
79
  * @returns The API response data.
76
80
  */
77
- DELETE(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
81
+ delete(endpoint: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
78
82
  }
79
- export { ApiInstance };
80
- //# sourceMappingURL=apiInstance.d.ts.map
83
+ export { ApiService };
84
+ //# sourceMappingURL=apiService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../src/services/apiService.ts"],"names":[],"mappings":"AAOA,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,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;IAC3B,OAAO,CAAC,WAAW,CAAC,CAAU;IAE9B;;;;;;;OAOG;gBAES,KAAK,EAAE,0BAA0B;IAO7C;;;;OAIG;IAEH,OAAO,CAAC,OAAO;IAcf,OAAO,CAAC,WAAW;IAInB;;;;;OAKG;IAEH,OAAO,CAAC,eAAe;IAcvB;;;;;OAKG;IAEG,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,8BAA8B;IAQjE;;;;;OAKG;IAEG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS/D;;;;;OAKG;IAEG,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS9D;;;;;OAKG;IAEG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAShE;;;;;OAKG;IAEG,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;CAQlE;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -3,30 +3,47 @@ import { getRequest } from "../api/getRequest";
3
3
  import { patchRequest } from "../api/patchRequest";
4
4
  import { postRequest } from "../api/postRequest";
5
5
  import { putRequest } from "../api/putRequest";
6
+ import { flushDebugLogs } from "./flushDebugLogs";
6
7
  /**
7
8
  * Class representing an API instance to handle HTTP requests with base configurations.
8
9
  */
9
- class ApiInstance {
10
+ class ApiService {
10
11
  baseUrl;
11
12
  baseHeaders;
12
13
  baseToken;
14
+ enableDebug;
13
15
  /**
14
- * Creates an instance of ApiInstance.
16
+ * Creates an instance of ApiService.
15
17
  * @param props - The configuration properties for the API instance.
16
18
  * @param props.baseUrl - The base URL for the API.
17
19
  * @param props.baseHeaders - Optional base headers to include in all requests.
18
20
  * @param props.baseToken - Optional base token for authorization.
21
+ * @param props.enableDebug - Optional flag to enable debug logging for requests.
19
22
  */
20
23
  constructor(props) {
21
24
  this.baseUrl = props.baseUrl;
22
25
  this.baseHeaders = props.baseHeaders || undefined;
23
26
  this.baseToken = props.baseToken || undefined;
27
+ this.enableDebug = props.enableDebug || false;
24
28
  }
25
29
  /**
26
30
  * Generates the full URL by appending the route to the base URL.
27
31
  * @param route - The route to append to the base URL.
28
32
  * @returns The full URL as a string.
29
33
  */
34
+ onDebug(endpoint, method, data) {
35
+ if (this.enableDebug) {
36
+ const debugs = [];
37
+ debugs.push(`Base URL: ${this.baseUrl}`);
38
+ debugs.push(`Endpoint: ${endpoint}`);
39
+ debugs.push(`Method: ${method}`);
40
+ if (data[0])
41
+ debugs.push(`Headers: ${JSON.stringify(data[0])}`);
42
+ if (data[1])
43
+ debugs.push(`Body: ${JSON.stringify(data[1])}`);
44
+ flushDebugLogs({ debugs, name: "ARKYN-API-DEBUG", scheme: "yellow" });
45
+ }
46
+ }
30
47
  generateURL(route) {
31
48
  return this.baseUrl + route;
32
49
  }
@@ -49,63 +66,68 @@ class ApiInstance {
49
66
  return headers;
50
67
  }
51
68
  /**
52
- * Sends a GET request to the specified route.
53
- * @param route - The API route to send the GET request to.
69
+ * Sends a get request to the specified endpoint.
70
+ * @param endpoint - The API endpoint to send the get request to.
54
71
  * @param data - The request data, including optional headers and token.
55
72
  * @returns The API response data.
56
73
  */
57
- async GET(route, data) {
58
- const url = this.generateURL(route);
74
+ async get(endpoint, data) {
75
+ const url = this.generateURL(endpoint);
59
76
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
77
+ this.onDebug(endpoint, "get", [headers]);
60
78
  return await getRequest(url, headers);
61
79
  }
62
80
  /**
63
- * Sends a POST request to the specified route.
64
- * @param route - The API route to send the POST request to.
81
+ * Sends a post request to the specified endpoint.
82
+ * @param endpoint - The API endpoint to send the post request to.
65
83
  * @param data - The request data, including body, optional headers, and token.
66
84
  * @returns The API response data.
67
85
  */
68
- async POST(route, data) {
69
- const url = this.generateURL(route);
86
+ async post(endpoint, data) {
87
+ const url = this.generateURL(endpoint);
70
88
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
71
89
  const body = data?.body;
90
+ this.onDebug(endpoint, "post", [headers, body]);
72
91
  return await postRequest(url, headers, body);
73
92
  }
74
93
  /**
75
- * Sends a PUT request to the specified route.
76
- * @param route - The API route to send the PUT request to.
94
+ * Sends a put request to the specified endpoint.
95
+ * @param endpoint - The API endpoint to send the put request to.
77
96
  * @param data - The request data, including body, optional headers, and token.
78
97
  * @returns The API response data.
79
98
  */
80
- async PUT(route, data) {
81
- const url = this.generateURL(route);
99
+ async put(endpoint, data) {
100
+ const url = this.generateURL(endpoint);
82
101
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
83
102
  const body = data?.body;
103
+ this.onDebug(endpoint, "put", [headers, body]);
84
104
  return await putRequest(url, headers, body);
85
105
  }
86
106
  /**
87
- * Sends a PATCH request to the specified route.
88
- * @param route - The API route to send the PATCH request to.
107
+ * Sends a patch request to the specified endpoint.
108
+ * @param endpoint - The API endpoint to send the patch request to.
89
109
  * @param data - The request data, including body, optional headers, and token.
90
110
  * @returns The API response data.
91
111
  */
92
- async PATCH(route, data) {
93
- const url = this.generateURL(route);
112
+ async patch(endpoint, data) {
113
+ const url = this.generateURL(endpoint);
94
114
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
95
115
  const body = data?.body;
116
+ this.onDebug(endpoint, "patch", [headers, body]);
96
117
  return await patchRequest(url, headers, body);
97
118
  }
98
119
  /**
99
- * Sends a DELETE request to the specified route.
100
- * @param route - The API route to send the DELETE request to.
120
+ * Sends a delete request to the specified endpoint.
121
+ * @param endpoint - The API endpoint to send the delete request to.
101
122
  * @param data - The request data, including body, optional headers, and token.
102
123
  * @returns The API response data.
103
124
  */
104
- async DELETE(route, data) {
105
- const url = this.generateURL(route);
125
+ async delete(endpoint, data) {
126
+ const url = this.generateURL(endpoint);
106
127
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
107
128
  const body = data?.body;
129
+ this.onDebug(endpoint, "delete", [headers, body]);
108
130
  return await deleteRequest(url, headers, body);
109
131
  }
110
132
  }
111
- export { ApiInstance };
133
+ export { ApiService };