@arkyn/server 3.0.1-beta.55 → 3.0.1-beta.56

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 (36) hide show
  1. package/package.json +3 -3
  2. package/src/api/arkynLogRequest.ts +0 -118
  3. package/src/api/deleteRequest.ts +0 -22
  4. package/src/api/getRequest.ts +0 -20
  5. package/src/api/makeRequest.ts +0 -118
  6. package/src/api/patchRequest.ts +0 -22
  7. package/src/api/postRequest.ts +0 -22
  8. package/src/api/putRequest.ts +0 -22
  9. package/src/http/badResponses/badGateway.ts +0 -63
  10. package/src/http/badResponses/badRequest.ts +0 -63
  11. package/src/http/badResponses/conflict.ts +0 -63
  12. package/src/http/badResponses/forbidden.ts +0 -63
  13. package/src/http/badResponses/notFound.ts +0 -63
  14. package/src/http/badResponses/notImplemented.ts +0 -63
  15. package/src/http/badResponses/serverError.ts +0 -63
  16. package/src/http/badResponses/unauthorized.ts +0 -63
  17. package/src/http/badResponses/unprocessableEntity.ts +0 -79
  18. package/src/http/successResponses/created.ts +0 -64
  19. package/src/http/successResponses/found.ts +0 -67
  20. package/src/http/successResponses/noContent.ts +0 -42
  21. package/src/http/successResponses/success.ts +0 -64
  22. package/src/http/successResponses/updated.ts +0 -64
  23. package/src/index.ts +0 -29
  24. package/src/mapper/arkynLogRequestMapper.ts +0 -73
  25. package/src/services/apiService.ts +0 -148
  26. package/src/services/arkynLogService.ts +0 -70
  27. package/src/services/decodeErrorMessageFromRequest.ts +0 -36
  28. package/src/services/decodeRequestBody.ts +0 -43
  29. package/src/services/errorHandler.ts +0 -99
  30. package/src/services/formParse.ts +0 -86
  31. package/src/services/getCaller.ts +0 -81
  32. package/src/services/getScopedParams.ts +0 -43
  33. package/src/services/httpDebug.ts +0 -104
  34. package/src/services/measureRouteExecution.ts +0 -31
  35. package/src/services/schemaValidator.ts +0 -66
  36. package/src/types/ApiResponseDTO.ts +0 -19
@@ -1,104 +0,0 @@
1
- import { getCaller } from "../services/getCaller";
2
-
3
- /**
4
- * Service for managing HTTP debug configuration and behavior.
5
- *
6
- * This service provides functionality to configure how the `getCaller` function
7
- * identifies the actual caller in the stack trace by allowing specific files
8
- * to be ignored during stack trace analysis.
9
- *
10
- * @example
11
- * ```typescript
12
- * // Configure to ignore httpAdapter.ts in stack traces
13
- * HttpDebugService.setIgnoreFile("httpAdapter.ts");
14
- *
15
- * // Now when httpDebug is called from within httpAdapter.ts,
16
- * // it will show the actual caller (e.g., cart.ts) instead
17
- * ```
18
- */
19
- class HttpDebugService {
20
- /**
21
- * The name of the file to ignore when analyzing the stack trace.
22
- * When set, the `getCaller` function will skip stack frames containing this file name.
23
- */
24
- static ignoreFile?: string;
25
-
26
- /**
27
- * Sets the file name to be ignored during stack trace analysis.
28
- *
29
- * This method configures the debug service to skip specific files when
30
- * determining the actual caller of a function. This is useful when you have
31
- * adapter or wrapper functions that you want to be transparent in the debug output.
32
- *
33
- * @param file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
34
- *
35
- * @example
36
- * ```typescript
37
- * // Ignore the HTTP adapter file so debug shows the actual business logic caller
38
- * HttpDebugService.setIgnoreFile("httpAdapter.ts");
39
- * ```
40
- */
41
- static setIgnoreFile(file: string) {
42
- this.ignoreFile = file;
43
- }
44
- }
45
-
46
- /**
47
- * Logs debug information to the console when in development mode or when the
48
- * `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
49
- *
50
- * This function provides detailed information about the caller function,
51
- * its location, and the provided body and cause, if any.
52
- *
53
- * @param name - A string representing the name or context of the debug log.
54
- * @param body - The main content or data to be logged.
55
- * @param cause - (Optional) Additional information or error cause to be logged.
56
- *
57
- * @remarks
58
- * The debug logs are only displayed when the application is running in
59
- * development mode (`NODE_ENV === "development"`) or when the
60
- * `SHOW_ERRORS_IN_CONSOLE` environment variable is explicitly set to "true".
61
- *
62
- * The logs include:
63
- * - The name of the debug context.
64
- * - The caller function name and its location.
65
- * - The provided body content.
66
- * - The optional cause, if provided.
67
- *
68
- * @example
69
- * ```typescript
70
- * httpDebug("FetchUserData", { userId: 123 });
71
- * ```
72
- *
73
- * @example
74
- * ```typescript
75
- * httpDebug("FetchUserDataError", { userId: 123 }, new Error("User not found"));
76
- * ```
77
- */
78
-
79
- function httpDebug(name: string, body: any, cause?: any) {
80
- const isDebugMode =
81
- process.env.NODE_ENV === "development" ||
82
- process.env?.SHOW_ERRORS_IN_CONSOLE === "true";
83
-
84
- if (isDebugMode) {
85
- const reset = "\x1b[0m";
86
- const cyan = "\x1b[36m";
87
-
88
- const debugName = `${cyan}[ARKYN-DEBUG]${reset}`;
89
- const { callerInfo, functionName } = getCaller();
90
-
91
- let consoleData = `${debugName} ${name} initialized\n`;
92
- consoleData += `${debugName} Caller Function: ${functionName}\n`;
93
- consoleData += `${debugName} Caller Location: ${callerInfo}\n`;
94
- consoleData += `${debugName} Body: ${JSON.stringify(body, null, 2)}\n`;
95
-
96
- if (cause) {
97
- consoleData += `${debugName} Cause: ${JSON.stringify(cause, null, 2)}\n`;
98
- }
99
-
100
- console.log(consoleData);
101
- }
102
- }
103
-
104
- export { httpDebug, HttpDebugService };
@@ -1,31 +0,0 @@
1
- function measureRouteExecution<T = unknown>(
2
- handler: (props: any) => Promise<T>
3
- ) {
4
- return async function measuredHandler(props: any): Promise<T> {
5
- const startTime = performance.now();
6
-
7
- try {
8
- const result = await handler(props);
9
-
10
- const url = new URL(props.request.url);
11
- const endTime = performance.now();
12
-
13
- const duration = (endTime - startTime).toFixed(2);
14
-
15
- console.log({
16
- domain: url.hostname,
17
- pathname: url.pathname,
18
- method: props.request.method,
19
- duration,
20
- });
21
-
22
- return result as T;
23
- } catch (error) {
24
- const endTime = performance.now();
25
- console.error("");
26
- throw error;
27
- }
28
- };
29
- }
30
-
31
- export { measureRouteExecution };
@@ -1,66 +0,0 @@
1
- import { ZodType, z } from "zod";
2
-
3
- import { ServerError } from "../http/badResponses/serverError";
4
- import { UnprocessableEntity } from "../http/badResponses/unprocessableEntity";
5
- import { formParse } from "./formParse";
6
- import { getCaller } from "./getCaller";
7
- import { httpDebug } from "./httpDebug";
8
-
9
- function formatErrorMessage(error: z.ZodError) {
10
- const title = "Error validating:";
11
- const lines = error.issues.map(
12
- ({ path, message }) => `-> ${path.join(".")}: ${message}`
13
- );
14
-
15
- return [title, ...lines].join("\n");
16
- }
17
-
18
- class SchemaValidator<T extends ZodType> {
19
- functionName: string;
20
- callerInfo: string;
21
-
22
- constructor(readonly schema: T) {
23
- const { callerInfo, functionName } = getCaller();
24
- this.callerInfo = callerInfo;
25
- this.functionName = functionName;
26
- }
27
-
28
- isValid(data: any): boolean {
29
- return this.schema.safeParse(data).success;
30
- }
31
-
32
- safeValidate(data: any): z.ZodSafeParseResult<z.infer<T>> {
33
- return this.schema.safeParse(data);
34
- }
35
-
36
- validate(data: any): z.infer<T> {
37
- try {
38
- return this.schema.parse(data);
39
- } catch (error: any) {
40
- throw new ServerError(formatErrorMessage(error));
41
- }
42
- }
43
-
44
- formValidate(data: any, message?: string): z.infer<T> {
45
- const formParsed = formParse([data, this.schema]);
46
-
47
- if (!formParsed.success) {
48
- httpDebug("UnprocessableEntity", formParsed);
49
- const firstErrorKey = Object.keys(formParsed.fieldErrors)[0];
50
-
51
- throw new UnprocessableEntity(
52
- {
53
- fields: formParsed.fields,
54
- fieldErrors: formParsed.fieldErrors,
55
- data: { scrollTo: firstErrorKey },
56
- message,
57
- },
58
- false
59
- );
60
- }
61
-
62
- return formParsed.data as z.infer<T>;
63
- }
64
- }
65
-
66
- export { SchemaValidator };
@@ -1,19 +0,0 @@
1
- type ApiSuccessResponse<T = any> = {
2
- success: true;
3
- status: number;
4
- message: string;
5
- response: T;
6
- cause: null;
7
- };
8
-
9
- type ApiFailedResponse = {
10
- success: false;
11
- status: number;
12
- message: string;
13
- response: any;
14
- cause: string | Error | null;
15
- };
16
-
17
- type ApiResponseDTO<T = any> = ApiSuccessResponse<T> | ApiFailedResponse;
18
-
19
- export type { ApiResponseDTO };