@arkyn/server 2.0.1-beta.9 → 2.0.2

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 (128) hide show
  1. package/LICENSE.txt +24 -0
  2. package/README.md +116 -0
  3. package/dist/api/deleteRequest.d.ts +13 -0
  4. package/dist/api/deleteRequest.d.ts.map +1 -0
  5. package/dist/api/deleteRequest.js +14 -0
  6. package/dist/api/getRequest.d.ts +12 -0
  7. package/dist/api/getRequest.d.ts.map +1 -0
  8. package/dist/api/getRequest.js +13 -0
  9. package/dist/api/inboxFlowRequest.d.ts +40 -0
  10. package/dist/api/inboxFlowRequest.d.ts.map +1 -0
  11. package/dist/api/inboxFlowRequest.js +63 -0
  12. package/dist/api/makeRequest.d.ts +38 -0
  13. package/dist/api/makeRequest.d.ts.map +1 -0
  14. package/dist/api/makeRequest.js +103 -0
  15. package/dist/api/patchRequest.d.ts +13 -0
  16. package/dist/api/patchRequest.d.ts.map +1 -0
  17. package/dist/api/patchRequest.js +14 -0
  18. package/dist/api/postRequest.d.ts +13 -0
  19. package/dist/api/postRequest.d.ts.map +1 -0
  20. package/dist/api/postRequest.js +14 -0
  21. package/dist/api/putRequest.d.ts +13 -0
  22. package/dist/api/putRequest.d.ts.map +1 -0
  23. package/dist/api/putRequest.js +14 -0
  24. package/dist/config/apiInstance.d.ts +80 -0
  25. package/dist/config/apiInstance.d.ts.map +1 -0
  26. package/dist/config/apiInstance.js +111 -0
  27. package/dist/config/inboxFlowInstance.d.ts +44 -0
  28. package/dist/config/inboxFlowInstance.d.ts.map +1 -0
  29. package/dist/config/inboxFlowInstance.js +46 -0
  30. package/dist/http/badResponses/badGateway.d.ts +23 -0
  31. package/dist/http/badResponses/badGateway.d.ts.map +1 -1
  32. package/dist/http/badResponses/badGateway.js +24 -1
  33. package/dist/http/badResponses/badRequest.d.ts +23 -0
  34. package/dist/http/badResponses/badRequest.d.ts.map +1 -1
  35. package/dist/http/badResponses/badRequest.js +24 -1
  36. package/dist/http/badResponses/conflict.d.ts +23 -0
  37. package/dist/http/badResponses/conflict.d.ts.map +1 -1
  38. package/dist/http/badResponses/conflict.js +24 -1
  39. package/dist/http/badResponses/forbidden.d.ts +23 -0
  40. package/dist/http/badResponses/forbidden.d.ts.map +1 -1
  41. package/dist/http/badResponses/forbidden.js +25 -2
  42. package/dist/http/badResponses/notFound.d.ts +23 -0
  43. package/dist/http/badResponses/notFound.d.ts.map +1 -1
  44. package/dist/http/badResponses/notFound.js +24 -1
  45. package/dist/http/badResponses/notImplemented.d.ts +23 -0
  46. package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
  47. package/dist/http/badResponses/notImplemented.js +24 -1
  48. package/dist/http/badResponses/serverError.d.ts +23 -0
  49. package/dist/http/badResponses/serverError.d.ts.map +1 -1
  50. package/dist/http/badResponses/serverError.js +24 -1
  51. package/dist/http/badResponses/unauthorized.d.ts +23 -0
  52. package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
  53. package/dist/http/badResponses/unauthorized.js +24 -1
  54. package/dist/http/badResponses/unprocessableEntity.d.ts +28 -1
  55. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
  56. package/dist/http/badResponses/unprocessableEntity.js +30 -3
  57. package/dist/http/successResponses/created.d.ts +25 -0
  58. package/dist/http/successResponses/created.d.ts.map +1 -1
  59. package/dist/http/successResponses/created.js +25 -0
  60. package/dist/http/successResponses/found.d.ts +28 -0
  61. package/dist/http/successResponses/found.d.ts.map +1 -1
  62. package/dist/http/successResponses/found.js +28 -0
  63. package/dist/http/successResponses/noContent.d.ts +16 -1
  64. package/dist/http/successResponses/noContent.d.ts.map +1 -1
  65. package/dist/http/successResponses/noContent.js +16 -8
  66. package/dist/http/successResponses/success.d.ts +25 -0
  67. package/dist/http/successResponses/success.d.ts.map +1 -1
  68. package/dist/http/successResponses/success.js +25 -0
  69. package/dist/http/successResponses/updated.d.ts +25 -0
  70. package/dist/http/successResponses/updated.d.ts.map +1 -1
  71. package/dist/http/successResponses/updated.js +25 -0
  72. package/dist/index.d.ts +6 -0
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +10 -0
  75. package/dist/services/decodeErrorMessageFromRequest.d.ts +17 -0
  76. package/dist/services/decodeErrorMessageFromRequest.d.ts.map +1 -0
  77. package/dist/services/decodeErrorMessageFromRequest.js +30 -0
  78. package/dist/services/decodeRequestBody.d.ts.map +1 -1
  79. package/dist/services/decodeRequestBody.js +12 -16
  80. package/dist/services/errorHandler.d.ts +42 -1
  81. package/dist/services/errorHandler.d.ts.map +1 -1
  82. package/dist/services/errorHandler.js +42 -0
  83. package/dist/services/formParse.d.ts.map +1 -1
  84. package/dist/services/formParse.js +4 -2
  85. package/dist/services/getCaller.d.ts +17 -0
  86. package/dist/services/getCaller.d.ts.map +1 -0
  87. package/dist/services/getCaller.js +45 -0
  88. package/dist/services/httpDebug.d.ts +35 -0
  89. package/dist/services/httpDebug.d.ts.map +1 -0
  90. package/dist/services/httpDebug.js +56 -0
  91. package/dist/services/schemaValidator.d.ts +13 -0
  92. package/dist/services/schemaValidator.d.ts.map +1 -0
  93. package/dist/services/schemaValidator.js +51 -0
  94. package/package.json +11 -5
  95. package/src/api/deleteRequest.ts +22 -0
  96. package/src/api/getRequest.ts +20 -0
  97. package/src/api/inboxFlowRequest.ts +76 -0
  98. package/src/api/makeRequest.ts +117 -0
  99. package/src/api/patchRequest.ts +22 -0
  100. package/src/api/postRequest.ts +22 -0
  101. package/src/api/putRequest.ts +22 -0
  102. package/src/config/apiInstance.ts +148 -0
  103. package/src/config/inboxFlowInstance.ts +65 -0
  104. package/src/http/badResponses/badGateway.ts +29 -2
  105. package/src/http/badResponses/badRequest.ts +29 -2
  106. package/src/http/badResponses/conflict.ts +29 -2
  107. package/src/http/badResponses/forbidden.ts +30 -3
  108. package/src/http/badResponses/notFound.ts +29 -2
  109. package/src/http/badResponses/notImplemented.ts +29 -2
  110. package/src/http/badResponses/serverError.ts +29 -2
  111. package/src/http/badResponses/unauthorized.ts +29 -2
  112. package/src/http/badResponses/unprocessableEntity.ts +33 -2
  113. package/src/http/successResponses/created.ts +31 -2
  114. package/src/http/successResponses/found.ts +32 -0
  115. package/src/http/successResponses/noContent.ts +20 -11
  116. package/src/http/successResponses/success.ts +31 -2
  117. package/src/http/successResponses/updated.ts +31 -2
  118. package/src/index.ts +9 -1
  119. package/src/services/decodeErrorMessageFromRequest.ts +36 -0
  120. package/src/services/decodeRequestBody.ts +11 -15
  121. package/src/services/errorHandler.ts +45 -1
  122. package/src/services/formParse.ts +4 -5
  123. package/src/services/getCaller.ts +39 -18
  124. package/src/services/httpDebug.ts +46 -5
  125. package/vitest.config.ts +5 -0
  126. package/dist/http/httpDebug.d.ts +0 -3
  127. package/dist/http/httpDebug.d.ts.map +0 -1
  128. package/dist/http/httpDebug.js +0 -15
@@ -1,9 +1,24 @@
1
+ /**
2
+ * Represents a successful HTTP response with a status code of 200 (OK) or other custom status codes.
3
+ * This class is used to standardize the structure of an "Updated" response,
4
+ * including the response body, headers, status, and status text.
5
+ *
6
+ * @template T - The type of the response body.
7
+ */
8
+
1
9
  class Updated<T> {
2
10
  body: T;
3
11
  headers: ResponseInit["headers"];
4
12
  status: number;
5
13
  statusText: string;
6
14
 
15
+ /**
16
+ * Creates an instance of the `Updated` class.
17
+ *
18
+ * @param body - The response body to be included in the HTTP response.
19
+ * @param init - Optional initialization object for customizing headers, status, and status text.
20
+ */
21
+
7
22
  constructor(body: T, init?: ResponseInit) {
8
23
  this.body = body;
9
24
  this.headers = init?.headers || {};
@@ -11,7 +26,14 @@ class Updated<T> {
11
26
  this.statusText = init?.statusText || "Resource updated successfully";
12
27
  }
13
28
 
14
- toResponse() {
29
+ /**
30
+ * Converts the `Updated` instance into a `Response` object with a JSON body.
31
+ * This method ensures the response has the appropriate headers, status, and status text.
32
+ *
33
+ * @returns A `Response` object with the serialized JSON body and response metadata.
34
+ */
35
+
36
+ toResponse(): Response {
15
37
  const responseInit: ResponseInit = {
16
38
  headers: { "Content-Type": "application/json", ...this.headers },
17
39
  status: this.status,
@@ -21,7 +43,14 @@ class Updated<T> {
21
43
  return new Response(JSON.stringify(this.body), responseInit);
22
44
  }
23
45
 
24
- toJson() {
46
+ /**
47
+ * Converts the `Updated` instance into a `Response` object using the `Response.json` method.
48
+ * This method is an alternative to `toResponse` for generating JSON responses.
49
+ *
50
+ * @returns A `Response` object with the JSON body and response metadata.
51
+ */
52
+
53
+ toJson(): Response {
25
54
  const responseInit: ResponseInit = {
26
55
  headers: this.headers,
27
56
  status: this.status,
package/src/index.ts CHANGED
@@ -1,3 +1,8 @@
1
+ // config
2
+ export { ApiInstance } from "./config/apiInstance";
3
+ export { InboxFlowInstance } from "./config/inboxFlowInstance";
4
+
5
+ // http bad responses
1
6
  export { BadGateway } from "./http/badResponses/badGateway";
2
7
  export { BadRequest } from "./http/badResponses/badRequest";
3
8
  export { Conflict } from "./http/badResponses/conflict";
@@ -8,17 +13,20 @@ export { ServerError } from "./http/badResponses/serverError";
8
13
  export { Unauthorized } from "./http/badResponses/unauthorized";
9
14
  export { UnprocessableEntity } from "./http/badResponses/unprocessableEntity";
10
15
 
16
+ // http success responses
11
17
  export { Created } from "./http/successResponses/created";
12
18
  export { Found } from "./http/successResponses/found";
13
19
  export { NoContent } from "./http/successResponses/noContent";
14
20
  export { Success } from "./http/successResponses/success";
15
21
  export { Updated } from "./http/successResponses/updated";
16
22
 
23
+ // services
24
+ export { decodeErrorMessageFromRequest } from "./services/decodeErrorMessageFromRequest";
17
25
  export { decodeRequestBody } from "./services/decodeRequestBody";
18
26
  export { errorHandler } from "./services/errorHandler";
19
27
  export { formParse } from "./services/formParse";
20
28
  export { getCaller } from "./services/getCaller";
21
29
  export { getScopedParams } from "./services/getScopedParams";
22
30
  export { httpDebug } from "./services/httpDebug";
23
- export { sendFileToS3 } from "./services/sendFileToS3";
24
31
  export { SchemaValidator } from "./services/schemaValidator";
32
+ export { sendFileToS3 } from "./services/sendFileToS3";
@@ -0,0 +1,36 @@
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
+
16
+ function decodeErrorMessageFromRequest(data: any, response: Response): string {
17
+ if (data?.message && typeof data?.message === "string") {
18
+ return data?.message;
19
+ }
20
+
21
+ if (data?.error && typeof data?.error === "string") {
22
+ return data?.error;
23
+ }
24
+
25
+ if (data?.error?.message && typeof data?.error?.message === "string") {
26
+ return data?.error?.message;
27
+ }
28
+
29
+ if (response?.statusText && typeof response?.statusText === "string") {
30
+ return response?.statusText;
31
+ }
32
+
33
+ return "Missing error message";
34
+ }
35
+
36
+ export { decodeErrorMessageFromRequest };
@@ -1,4 +1,5 @@
1
1
  import type { DecodeRequestBodyFunction } from "@arkyn/types";
2
+ import { BadRequest } from "../http/badResponses/badRequest";
2
3
 
3
4
  /**
4
5
  * Decodes the body of an incoming request into a JavaScript object.
@@ -17,27 +18,22 @@ import type { DecodeRequestBodyFunction } from "@arkyn/types";
17
18
  const decodeRequestBody: DecodeRequestBodyFunction = async (req) => {
18
19
  let data: any;
19
20
 
20
- try {
21
- const arrayBuffer = await req.arrayBuffer();
22
- const text = new TextDecoder().decode(arrayBuffer);
21
+ const arrayBuffer = await req.arrayBuffer();
22
+ const text = new TextDecoder().decode(arrayBuffer);
23
23
 
24
+ try {
25
+ data = JSON.parse(text);
26
+ } catch (jsonError) {
24
27
  try {
25
- data = JSON.parse(text);
26
- } catch (jsonError) {
27
- try {
28
+ if (text.includes("=")) {
28
29
  const formData = new URLSearchParams(text);
29
30
  data = Object.fromEntries(formData.entries());
30
- } catch (formDataError) {
31
- console.error("Failed to extract data from request:", {
32
- jsonError,
33
- formDataError,
34
- });
35
- data = {};
31
+ } else {
32
+ throw new BadRequest("Invalid URLSearchParams format");
36
33
  }
34
+ } catch (formDataError) {
35
+ throw new BadRequest("Failed to extract data from request");
37
36
  }
38
- } catch (error) {
39
- console.error("Failed to read request body:", error);
40
- data = {};
41
37
  }
42
38
 
43
39
  return data;
@@ -14,7 +14,49 @@ import { NoContent } from "../http/successResponses/noContent";
14
14
  import { Success } from "../http/successResponses/success";
15
15
  import { Updated } from "../http/successResponses/updated";
16
16
 
17
- function errorHandler(error: any) {
17
+ /**
18
+ * Handles errors and converts them into appropriate HTTP responses.
19
+ *
20
+ * This function takes an error object and determines its type to return
21
+ * the corresponding HTTP response. It supports both success and error
22
+ * response types, converting them into a standardized format using the
23
+ * `toResponse` method when applicable.
24
+ *
25
+ * @param error - The error object to handle. It can be an instance of various
26
+ * HTTP response classes or a generic error.
27
+ *
28
+ * @returns The corresponding HTTP response object if the error matches a known
29
+ * type, or `undefined` if no match is found.
30
+ *
31
+ * ### Supported Success Responses:
32
+ * - `Found`
33
+ * - `Created`
34
+ * - `Updated`
35
+ * - `Success`
36
+ * - `NoContent`
37
+ *
38
+ * ### Supported Error Responses:
39
+ * - `BadGateway`
40
+ * - `BadRequest`
41
+ * - `Conflict`
42
+ * - `Forbidden`
43
+ * - `NotFound`
44
+ * - `NotImplemented`
45
+ * - `ServerError`
46
+ * - `Unauthorized`
47
+ * - `UnprocessableEntity`
48
+ *
49
+ * ### Example Usage:
50
+ * ```typescript
51
+ * try {
52
+ * // Some operation that might throw an error
53
+ * } catch (error) {
54
+ * return errorHandler(error);
55
+ * }
56
+ * ```
57
+ */
58
+
59
+ function errorHandler(error: any): Response {
18
60
  switch (true) {
19
61
  case error instanceof Response:
20
62
  return error;
@@ -50,6 +92,8 @@ function errorHandler(error: any) {
50
92
  case error instanceof UnprocessableEntity:
51
93
  return error.toResponse();
52
94
  }
95
+
96
+ return new ServerError("Server error").toResponse();
53
97
  }
54
98
 
55
99
  export { errorHandler };
@@ -46,12 +46,11 @@ function formParse<T extends FormParseProps>([
46
46
  const zodResponse = schema.safeParse(formData);
47
47
 
48
48
  if (zodResponse.success === false) {
49
- const errorsArray = Object.entries(
50
- zodResponse.error.formErrors.fieldErrors
51
- );
52
-
53
49
  const errorsObject = Object.fromEntries(
54
- errorsArray.map((item) => [item[0], item[1]?.[0] || "Error"])
50
+ zodResponse.error.errors.map((item) => [
51
+ item.path.join("."),
52
+ item.message,
53
+ ])
55
54
  );
56
55
 
57
56
  return {
@@ -1,33 +1,54 @@
1
1
  import path from "path";
2
2
 
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
+
3
15
  function getCaller() {
4
- // Diretório raiz do projeto
5
16
  const projectRoot = process.cwd();
6
17
 
7
- // Captura a stack trace
8
18
  const error = new Error();
9
19
  const stackLines = error.stack?.split("\n").map((line) => line.trim()) || [];
10
20
 
11
21
  let callerInfo = "Unknown caller";
12
22
  let functionName = "Unknown function";
13
23
 
14
- for (const line of stackLines) {
15
- // Ignora chamadas dentro de @arkyn/server
16
- if (!line.includes("@arkyn/server")) {
17
- // Captura diferentes formatos de stack trace
18
- const match = line.match(/at (.+?) \((.+?)\)/) || line.match(/at (.+)/);
19
- if (match) {
20
- functionName = match[1].split(" ")[0]; // Nome da função
21
- let fullPath = match[2] || match[1]; // Caminho absoluto do arquivo
22
-
23
- // Transforma caminho absoluto em relativo ao projeto
24
- if (fullPath.startsWith(projectRoot)) {
25
- fullPath = path.relative(projectRoot, fullPath);
26
- }
27
-
28
- callerInfo = fullPath;
29
- break;
24
+ const relevantLines = stackLines.filter(
25
+ (line) => !line.includes("@arkyn/server")
26
+ );
27
+
28
+ let foundGetCaller = false;
29
+ for (const line of relevantLines) {
30
+ if (!foundGetCaller) {
31
+ if (line.includes("getCaller")) {
32
+ foundGetCaller = true;
33
+ }
34
+ continue;
35
+ }
36
+
37
+ const match = line.match(/at (.+?) \((.+?)\)/) || line.match(/at (.+)/);
38
+ if (match) {
39
+ const rawFuncName = match[1]?.split(" ")[0] || "";
40
+
41
+ functionName =
42
+ rawFuncName && !rawFuncName.includes("/")
43
+ ? rawFuncName
44
+ : "Unknown function";
45
+
46
+ let fullPath = match[2] || match[1];
47
+ if (fullPath.startsWith(projectRoot)) {
48
+ fullPath = path.relative(projectRoot, fullPath);
30
49
  }
50
+ callerInfo = fullPath;
51
+ break;
31
52
  }
32
53
  }
33
54
 
@@ -1,5 +1,39 @@
1
+ import { InboxFlowInstance } from "../config/inboxFlowInstance";
1
2
  import { getCaller } from "../services/getCaller";
2
3
 
4
+ /**
5
+ * Logs debug information to the console when in development mode or when the
6
+ * `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
7
+ *
8
+ * This function provides detailed information about the caller function,
9
+ * its location, and the provided body and cause, if any.
10
+ *
11
+ * @param name - A string representing the name or context of the debug log.
12
+ * @param body - The main content or data to be logged.
13
+ * @param cause - (Optional) Additional information or error cause to be logged.
14
+ *
15
+ * @remarks
16
+ * The debug logs are only displayed when the application is running in
17
+ * development mode (`NODE_ENV === "development"`) or when the
18
+ * `SHOW_ERRORS_IN_CONSOLE` environment variable is explicitly set to "true".
19
+ *
20
+ * The logs include:
21
+ * - The name of the debug context.
22
+ * - The caller function name and its location.
23
+ * - The provided body content.
24
+ * - The optional cause, if provided.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * httpDebug("FetchUserData", { userId: 123 });
29
+ * ```
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * httpDebug("FetchUserDataError", { userId: 123 }, new Error("User not found"));
34
+ * ```
35
+ */
36
+
3
37
  function httpDebug(name: string, body: any, cause?: any) {
4
38
  const isDebugMode =
5
39
  process.env.NODE_ENV === "development" ||
@@ -12,11 +46,18 @@ function httpDebug(name: string, body: any, cause?: any) {
12
46
  const debugName = `${cyan}[ARKYN-DEBUG]${reset}`;
13
47
  const { callerInfo, functionName } = getCaller();
14
48
 
15
- console.log(`${debugName} ${name} initialized`);
16
- console.log(`${debugName} Caller Function: ${functionName}`);
17
- console.log(`${debugName} Caller Location: ${callerInfo}`);
18
- console.log(`${debugName} Body:`, body);
19
- if (cause) console.log(`[ARKYN-DEBUG] Cause:`, cause);
49
+ let consoleData = `${debugName} ${name} initialized\n`;
50
+ consoleData += `${debugName} Caller Function: ${functionName}\n`;
51
+ consoleData += `${debugName} Caller Location: ${callerInfo}\n`;
52
+ consoleData += `${debugName} Body: ${JSON.stringify(body, null, 2)}\n`;
53
+
54
+ if (cause) {
55
+ consoleData += `${debugName} Cause: ${JSON.stringify(cause, null, 2)}\n`;
56
+ }
57
+
58
+ console.log(consoleData);
59
+ const arkynKeys = InboxFlowInstance.getInboxConfig();
60
+ if (arkynKeys) console.log(arkynKeys);
20
61
  }
21
62
  }
22
63
 
@@ -0,0 +1,5 @@
1
+ import { defineConfig } from "vite";
2
+
3
+ export default defineConfig({
4
+ resolve: { mainFields: ["module"] },
5
+ });
@@ -1,3 +0,0 @@
1
- declare function httpDebug(name: string, body: any, cause?: any): void;
2
- export { httpDebug };
3
- //# sourceMappingURL=httpDebug.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"httpDebug.d.ts","sourceRoot":"","sources":["../../src/http/httpDebug.ts"],"names":[],"mappings":"AAAA,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,QAetD;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,15 +0,0 @@
1
- function httpDebug(name, body, cause) {
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 cyan = "\x1b[36m";
7
- const pathname = new URL(import.meta.url).pathname;
8
- console.log(`${cyan}[ARKYN-DEBUG]${reset} ${name} initialized`);
9
- console.log(`${cyan}[ARKYN-DEBUG]${reset} Pathname:`, pathname);
10
- console.log(`${cyan}[ARKYN-DEBUG]${reset} Body:`, body);
11
- if (cause)
12
- console.log(`[ARKYN-DEBUG] Cause:`, cause);
13
- }
14
- }
15
- export { httpDebug };