@arkyn/server 3.0.1-beta.21 → 3.0.1-beta.23

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 (39) hide show
  1. package/README.md +368 -65
  2. package/package.json +19 -5
  3. package/src/api/arkynLogRequest.ts +0 -118
  4. package/src/api/deleteRequest.ts +0 -22
  5. package/src/api/getRequest.ts +0 -20
  6. package/src/api/makeRequest.ts +0 -118
  7. package/src/api/patchRequest.ts +0 -22
  8. package/src/api/postRequest.ts +0 -22
  9. package/src/api/putRequest.ts +0 -22
  10. package/src/config/apiInstance.ts +0 -148
  11. package/src/config/arkynLogInstance.ts +0 -70
  12. package/src/http/badResponses/badGateway.ts +0 -63
  13. package/src/http/badResponses/badRequest.ts +0 -63
  14. package/src/http/badResponses/conflict.ts +0 -63
  15. package/src/http/badResponses/forbidden.ts +0 -63
  16. package/src/http/badResponses/notFound.ts +0 -63
  17. package/src/http/badResponses/notImplemented.ts +0 -63
  18. package/src/http/badResponses/serverError.ts +0 -63
  19. package/src/http/badResponses/unauthorized.ts +0 -63
  20. package/src/http/badResponses/unprocessableEntity.ts +0 -79
  21. package/src/http/successResponses/created.ts +0 -64
  22. package/src/http/successResponses/found.ts +0 -67
  23. package/src/http/successResponses/noContent.ts +0 -42
  24. package/src/http/successResponses/success.ts +0 -64
  25. package/src/http/successResponses/updated.ts +0 -64
  26. package/src/index.ts +0 -31
  27. package/src/mapper/arkynLogRequestMapper.ts +0 -73
  28. package/src/services/decodeErrorMessageFromRequest.ts +0 -36
  29. package/src/services/decodeRequestBody.ts +0 -43
  30. package/src/services/errorHandler.ts +0 -99
  31. package/src/services/formParse.ts +0 -86
  32. package/src/services/getCaller.ts +0 -82
  33. package/src/services/getScopedParams.ts +0 -43
  34. package/src/services/httpDebug.ts +0 -61
  35. package/src/services/measureRouteExecution.ts +0 -31
  36. package/src/services/schemaValidator.ts +0 -66
  37. package/src/types/ApiResponseDTO.ts +0 -19
  38. package/tsconfig.json +0 -21
  39. package/vitest.config.ts +0 -5
@@ -1,118 +0,0 @@
1
- import { ArkynLogRequestMapper } from "../mapper/arkynLogRequestMapper";
2
- import { httpDebug } from "../services/httpDebug";
3
- import type { ApiResponseDTO } from "../types/ApiResponseDTO";
4
- import { arkynLogRequest } from "./arkynLogRequest";
5
-
6
- /**
7
- * Makes an HTTP request using the Fetch API and returns a standardized response.
8
- *
9
- * @template T - The expected type of the response data.
10
- * @param method - The HTTP method to use for the request. Supported methods are:
11
- * - "POST": Create a new resource.
12
- * - "PUT": Update an existing resource.
13
- * - "DELETE": Remove a resource.
14
- * - "PATCH": Partially update a resource.
15
- * - "GET": Retrieve a resource.
16
- * @param url - The URL to which the request is sent.
17
- * @param headers - Optional headers to include in the request. Defaults to an empty object.
18
- * @param body - Optional body to include in the request. Should be serializable to JSON.
19
- * @returns A promise that resolves to an `ApiResponseDTO<T>` object containing:
20
- * - `success`: A boolean indicating whether the request was successful.
21
- * - `status`: The HTTP status code of the response.
22
- * - `message`: A message describing the result of the request.
23
- * - `response`: The parsed JSON response data, or `null` if parsing fails.
24
- * - `cause`: Additional error information, if applicable.
25
- *
26
- * @example
27
- * ```typescript
28
- * import { makeRequest } from "./makeRequest";
29
- *
30
- * async function fetchData() {
31
- * const response = await makeRequest("GET", "https://api.example.com/data");
32
- * if (response.success) {
33
- * console.log("Data:", response.response);
34
- * } else {
35
- * console.error("Error:", response.message);
36
- * }
37
- * }
38
- * ```
39
- */
40
-
41
- async function makeRequest<T = any>(
42
- method: "POST" | "PUT" | "DELETE" | "PATCH" | "GET",
43
- url: string,
44
- rawHeaders: HeadersInit = {},
45
- body?: any
46
- ): Promise<ApiResponseDTO<T>> {
47
- const successMessage = {
48
- POST: "Resource created successfully",
49
- PUT: "Resource updated successfully",
50
- DELETE: "Resource deleted successfully",
51
- PATCH: "Resource patched successfully",
52
- GET: "Request successful",
53
- };
54
-
55
- try {
56
- const startTime = performance.now();
57
-
58
- const headers = { ...rawHeaders, "Content-Type": "application/json" };
59
- const response = await fetch(url, {
60
- method,
61
- headers,
62
- body: body ? JSON.stringify(body) : undefined,
63
- });
64
-
65
- const elapsedTime = performance.now() - startTime;
66
- const status = response.status;
67
-
68
- let data: any = null;
69
- try {
70
- data = await response.json();
71
- } catch {
72
- data = null;
73
- }
74
-
75
- const logData = ArkynLogRequestMapper.handle({
76
- elapsedTime,
77
- method,
78
- queryParams: new URL(url).searchParams,
79
- requestHeaders: headers,
80
- requestBody: body,
81
- responseBody: data,
82
- responseHeaders: response.headers,
83
- status,
84
- url,
85
- });
86
-
87
- arkynLogRequest(logData);
88
-
89
- if (!response.ok) {
90
- return {
91
- success: false,
92
- status,
93
- message: data?.message || response.statusText || "Request failed",
94
- response: data,
95
- cause: null,
96
- };
97
- }
98
-
99
- return {
100
- success: true,
101
- status,
102
- message: data?.message || successMessage[method],
103
- response: data,
104
- cause: null,
105
- };
106
- } catch (err) {
107
- httpDebug("Network error or request failed", null, err);
108
- return {
109
- success: false,
110
- status: 0,
111
- message: "Network error or request failed",
112
- response: null,
113
- cause: err instanceof Error ? err.message : String(err),
114
- };
115
- }
116
- }
117
-
118
- export { makeRequest };
@@ -1,22 +0,0 @@
1
- import type { ApiResponseDTO } from "../types/ApiResponseDTO";
2
- import { makeRequest } from "./makeRequest";
3
-
4
- /**
5
- * Sends a PATCH request to the specified URL with optional headers and body.
6
- *
7
- * @template T - The expected type of the response data.
8
- * @param {string} url - The URL to send the PATCH request to.
9
- * @param {HeadersInit} [headers={}] - Optional headers to include in the request.
10
- * @param {any} body - The body to include in the request.
11
- * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
12
- */
13
-
14
- async function patchRequest<T = any>(
15
- url: string,
16
- headers: HeadersInit = {},
17
- body: any
18
- ): Promise<ApiResponseDTO<T>> {
19
- return makeRequest("PATCH", url, headers, body);
20
- }
21
-
22
- export { patchRequest };
@@ -1,22 +0,0 @@
1
- import type { ApiResponseDTO } from "../types/ApiResponseDTO";
2
- import { makeRequest } from "./makeRequest";
3
-
4
- /**
5
- * Sends a PATCH request to the specified URL with optional headers and body.
6
- *
7
- * @template T - The expected type of the response data.
8
- * @param {string} url - The URL to send the PATCH request to.
9
- * @param {HeadersInit} [headers={}] - Optional headers to include in the request.
10
- * @param {any} body - The body to include in the request.
11
- * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
12
- */
13
-
14
- async function postRequest<T = any>(
15
- url: string,
16
- headers: HeadersInit = {},
17
- body: any
18
- ): Promise<ApiResponseDTO<T>> {
19
- return makeRequest("POST", url, headers, body);
20
- }
21
-
22
- export { postRequest };
@@ -1,22 +0,0 @@
1
- import type { ApiResponseDTO } from "../types/ApiResponseDTO";
2
- import { makeRequest } from "./makeRequest";
3
-
4
- /**
5
- * Sends a PATCH request to the specified URL with optional headers and body.
6
- *
7
- * @template T - The expected type of the response data.
8
- * @param {string} url - The URL to send the PATCH request to.
9
- * @param {HeadersInit} [headers={}] - Optional headers to include in the request.
10
- * @param {any} body - The body to include in the request.
11
- * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
12
- */
13
-
14
- async function putRequest<T = any>(
15
- url: string,
16
- headers: HeadersInit = {},
17
- body: any
18
- ): Promise<ApiResponseDTO<T>> {
19
- return makeRequest("PUT", url, headers, body);
20
- }
21
-
22
- export { putRequest };
@@ -1,148 +0,0 @@
1
- import { deleteRequest } from "../api/deleteRequest";
2
- import { getRequest } from "../api/getRequest";
3
- import { patchRequest } from "../api/patchRequest";
4
- import { postRequest } from "../api/postRequest";
5
- import { putRequest } from "../api/putRequest";
6
-
7
- type ApiInstanceConstructorProps = {
8
- baseUrl: string;
9
- baseHeaders?: HeadersInit;
10
- baseToken?: string | null;
11
- };
12
-
13
- type ApiRequestDataWithoutBodyProps = {
14
- headers?: HeadersInit;
15
- token?: string;
16
- };
17
-
18
- type ApiRequestDataWithBodyProps = {
19
- body?: any;
20
- headers?: HeadersInit;
21
- token?: string;
22
- };
23
-
24
- /**
25
- * Class representing an API instance to handle HTTP requests with base configurations.
26
- */
27
-
28
- class ApiInstance {
29
- private baseUrl: string;
30
- private baseHeaders?: HeadersInit;
31
- private baseToken?: string;
32
-
33
- /**
34
- * Creates an instance of ApiInstance.
35
- * @param props - The configuration properties for the API instance.
36
- * @param props.baseUrl - The base URL for the API.
37
- * @param props.baseHeaders - Optional base headers to include in all requests.
38
- * @param props.baseToken - Optional base token for authorization.
39
- */
40
-
41
- constructor(props: ApiInstanceConstructorProps) {
42
- this.baseUrl = props.baseUrl;
43
- this.baseHeaders = props.baseHeaders || undefined;
44
- this.baseToken = props.baseToken || undefined;
45
- }
46
-
47
- /**
48
- * Generates the full URL by appending the route to the base URL.
49
- * @param route - The route to append to the base URL.
50
- * @returns The full URL as a string.
51
- */
52
-
53
- private generateURL(route: string) {
54
- return this.baseUrl + route;
55
- }
56
-
57
- /**
58
- * Generates the headers for a request by merging base headers, provided headers, and tokens.
59
- * @param initHeaders - Initial headers to include in the request.
60
- * @param token - Optional token to override the base token.
61
- * @returns The merged headers as a HeadersInit object.
62
- */
63
-
64
- private generateHeaders(
65
- initHeaders: HeadersInit,
66
- token?: string
67
- ): HeadersInit {
68
- let headers: HeadersInit = {};
69
- if (this.baseToken) headers = { Authorization: `Bearer ${this.baseToken}` };
70
- if (this.baseHeaders) headers = { ...headers, ...this.baseHeaders };
71
-
72
- if (initHeaders) headers = { ...headers, ...initHeaders };
73
- if (token) headers = { ...headers, Authorization: `Bearer ${token}` };
74
-
75
- return headers;
76
- }
77
-
78
- /**
79
- * Sends a get request to the specified route.
80
- * @param route - The API route to send the get request to.
81
- * @param data - The request data, including optional headers and token.
82
- * @returns The API response data.
83
- */
84
-
85
- async get(route: string, data?: ApiRequestDataWithoutBodyProps) {
86
- const url = this.generateURL(route);
87
- const headers = this.generateHeaders(data?.headers || {}, data?.token);
88
- return await getRequest(url, headers);
89
- }
90
-
91
- /**
92
- * Sends a post request to the specified route.
93
- * @param route - The API route to send the post request to.
94
- * @param data - The request data, including body, optional headers, and token.
95
- * @returns The API response data.
96
- */
97
-
98
- async post(route: string, data?: ApiRequestDataWithBodyProps) {
99
- const url = this.generateURL(route);
100
- const headers = this.generateHeaders(data?.headers || {}, data?.token);
101
- const body = data?.body;
102
- return await postRequest(url, headers, body);
103
- }
104
-
105
- /**
106
- * Sends a put request to the specified route.
107
- * @param route - The API route to send the put request to.
108
- * @param data - The request data, including body, optional headers, and token.
109
- * @returns The API response data.
110
- */
111
-
112
- async put(route: string, data?: ApiRequestDataWithBodyProps) {
113
- const url = this.generateURL(route);
114
- const headers = this.generateHeaders(data?.headers || {}, data?.token);
115
- const body = data?.body;
116
- return await putRequest(url, headers, body);
117
- }
118
-
119
- /**
120
- * Sends a patch request to the specified route.
121
- * @param route - The API route to send the patch request to.
122
- * @param data - The request data, including body, optional headers, and token.
123
- * @returns The API response data.
124
- */
125
-
126
- async patch(route: string, data?: ApiRequestDataWithBodyProps) {
127
- const url = this.generateURL(route);
128
- const headers = this.generateHeaders(data?.headers || {}, data?.token);
129
- const body = data?.body;
130
- return await patchRequest(url, headers, body);
131
- }
132
-
133
- /**
134
- * Sends a delete request to the specified route.
135
- * @param route - The API route to send the delete request to.
136
- * @param data - The request data, including body, optional headers, and token.
137
- * @returns The API response data.
138
- */
139
-
140
- async delete(route: string, data?: ApiRequestDataWithBodyProps) {
141
- const url = this.generateURL(route);
142
- const headers = this.generateHeaders(data?.headers || {}, data?.token);
143
- const body = data?.body;
144
- return await deleteRequest(url, headers, body);
145
- }
146
- }
147
-
148
- export { ApiInstance };
@@ -1,70 +0,0 @@
1
- type ArkynConfigProps = {
2
- arkynTrafficSourceId: string;
3
- arkynUserToken: string;
4
- arkynApiUrl: string;
5
- };
6
-
7
- type SetArkynConfigProps = {
8
- arkynTrafficSourceId: string;
9
- arkynUserToken: string;
10
- arkynLogBaseApiUrl?: string;
11
- };
12
-
13
- /**
14
- * The `ArkynLogInstance` class manages the configuration for the arkyn flow.
15
- * It allows you to set and retrieve the arkyn configuration, including the traffic source ID,
16
- * user token, and API URL.
17
- */
18
-
19
- class ArkynLogInstance {
20
- private static arkynConfig?: ArkynConfigProps;
21
-
22
- /**
23
- * Sets the configuration for the arkyn. This method initializes the arkyn configuration
24
- * with the provided `arkynConfig` values. If the configuration has already been set,
25
- * the method will return early without making any changes.
26
- *
27
- * @param arkynConfig - An object containing the arkyn configuration properties.
28
- * @param arkynConfig.arkynTrafficSourceId - The key used to identify the arkyn.
29
- * @param arkynConfig.arkynUserToken - The user token for authenticating with the arkyn.
30
- * @param arkynConfig.arkynLogBaseApiUrl - (Optional) The API URL for the arkyn. If not provided,
31
- * a default URL will be used.
32
- */
33
-
34
- static setArkynConfig(arkynConfig: SetArkynConfigProps) {
35
- if (!!this.arkynConfig) return;
36
-
37
- let defaultArkynURL = `https://logs-arkyn-flow-logs.vw6wo7.easypanel.host`;
38
- let arkynLogBaseApiUrl = arkynConfig.arkynLogBaseApiUrl || defaultArkynURL;
39
-
40
- arkynLogBaseApiUrl =
41
- arkynLogBaseApiUrl + "/http-traffic-records/:trafficSourceId";
42
-
43
- this.arkynConfig = {
44
- arkynTrafficSourceId: arkynConfig.arkynTrafficSourceId,
45
- arkynUserToken: arkynConfig.arkynUserToken,
46
- arkynApiUrl: arkynLogBaseApiUrl,
47
- };
48
- }
49
-
50
- /**
51
- * Retrieves the current arkyn configuration for the ArkynLogInstance.
52
- *
53
- * @returns {ArkynConfigProps | undefined} The current arkyn configuration if set,
54
- * or `undefined` if no configuration has been initialized.
55
- */
56
- static getArkynConfig(): ArkynConfigProps | undefined {
57
- return this.arkynConfig;
58
- }
59
-
60
- /**
61
- * Resets the arkyn configuration to `undefined`.
62
- * This method can be used to clear the current configuration.
63
- */
64
-
65
- static resetArkynConfig() {
66
- this.arkynConfig = undefined;
67
- }
68
- }
69
-
70
- export { ArkynLogInstance };
@@ -1,63 +0,0 @@
1
- import { httpDebug } from "../../services/httpDebug";
2
-
3
- /**
4
- * Represents an HTTP error response with a status code of 502 (Bad Gateway).
5
- * This class is used to standardize the structure of a "Bad Gateway" error response,
6
- * including the response body, headers, status, and status text.
7
- */
8
-
9
- class BadGateway {
10
- body: any;
11
- cause?: any;
12
- status: number = 502;
13
- statusText: string;
14
-
15
- /**
16
- * Creates an instance of the `BadGateway` class.
17
- *
18
- * @param message - A descriptive message explaining the cause of the error.
19
- * @param cause - Optional additional information about the cause of the error.
20
- */
21
-
22
- constructor(message: string, cause?: any) {
23
- this.body = { name: "BadGateway", message: message };
24
- this.statusText = message;
25
- this.cause = cause ? JSON.stringify(cause) : undefined;
26
- httpDebug("BadGateway", this.body, this.cause);
27
- }
28
-
29
- /**
30
- * Converts the `BadGateway` 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 {
37
- const responseInit: ResponseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
-
43
- return new Response(JSON.stringify(this.body), responseInit);
44
- }
45
-
46
- /**
47
- * Converts the `BadGateway` instance into a `Response` object using the `Response.json` method.
48
- * This method is an alternative to `toResponse` for generating JSON error responses.
49
- *
50
- * @returns A `Response` object with the JSON body and response metadata.
51
- */
52
-
53
- toJson(): Response {
54
- const responseInit: ResponseInit = {
55
- status: this.status,
56
- statusText: this.statusText,
57
- };
58
-
59
- return Response.json(this.body, responseInit);
60
- }
61
- }
62
-
63
- export { BadGateway };
@@ -1,63 +0,0 @@
1
- import { httpDebug } from "../../services/httpDebug";
2
-
3
- /**
4
- * Represents an HTTP error response with a status code of 400 (Bad Request).
5
- * This class is used to standardize the structure of a "Bad Request" error response,
6
- * including the response body, headers, status, and status text.
7
- */
8
-
9
- class BadRequest {
10
- body: any;
11
- cause?: any;
12
- status: number = 400;
13
- statusText: string;
14
-
15
- /**
16
- * Creates an instance of the `BadRequest` class.
17
- *
18
- * @param message - A descriptive message explaining the cause of the error.
19
- * @param cause - Optional additional information about the cause of the error.
20
- */
21
-
22
- constructor(message: string, cause?: any) {
23
- this.body = { name: "BadRequest", message: message };
24
- this.statusText = message;
25
- this.cause = cause ? JSON.stringify(cause) : undefined;
26
- httpDebug("BadRequest", this.body, this.cause);
27
- }
28
-
29
- /**
30
- * Converts the `BadRequest` 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 {
37
- const responseInit: ResponseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
-
43
- return new Response(JSON.stringify(this.body), responseInit);
44
- }
45
-
46
- /**
47
- * Converts the `BadRequest` instance into a `Response` object using the `Response.json` method.
48
- * This method is an alternative to `toResponse` for generating JSON error responses.
49
- *
50
- * @returns A `Response` object with the JSON body and response metadata.
51
- */
52
-
53
- toJson(): Response {
54
- const responseInit: ResponseInit = {
55
- status: this.status,
56
- statusText: this.statusText,
57
- };
58
-
59
- return Response.json(this.body, responseInit);
60
- }
61
- }
62
-
63
- export { BadRequest };
@@ -1,63 +0,0 @@
1
- import { httpDebug } from "../../services/httpDebug";
2
-
3
- /**
4
- * Represents an HTTP error response with a status code of 409 (Conflict).
5
- * This class is used to standardize the structure of a "Conflict" error response,
6
- * including the response body, headers, status, and status text.
7
- */
8
-
9
- class Conflict {
10
- body: any;
11
- cause?: any;
12
- status: number = 409;
13
- statusText: string;
14
-
15
- /**
16
- * Creates an instance of the `Conflict` class.
17
- *
18
- * @param message - A descriptive message explaining the cause of the conflict.
19
- * @param cause - Optional additional information about the cause of the conflict.
20
- */
21
-
22
- constructor(message: string, cause?: any) {
23
- this.body = { name: "Conflict", message: message };
24
- this.statusText = message;
25
- this.cause = cause ? JSON.stringify(cause) : undefined;
26
- httpDebug("Conflict", this.body, this.cause);
27
- }
28
-
29
- /**
30
- * Converts the `Conflict` 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 {
37
- const responseInit: ResponseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
-
43
- return new Response(JSON.stringify(this.body), responseInit);
44
- }
45
-
46
- /**
47
- * Converts the `Conflict` instance into a `Response` object using the `Response.json` method.
48
- * This method is an alternative to `toResponse` for generating JSON error responses.
49
- *
50
- * @returns A `Response` object with the JSON body and response metadata.
51
- */
52
-
53
- toJson(): Response {
54
- const responseInit: ResponseInit = {
55
- status: this.status,
56
- statusText: this.statusText,
57
- };
58
-
59
- return Response.json(this.body, responseInit);
60
- }
61
- }
62
-
63
- export { Conflict };
@@ -1,63 +0,0 @@
1
- import { httpDebug } from "../../services/httpDebug";
2
-
3
- /**
4
- * Represents an HTTP error response with a status code of 403 (Forbidden).
5
- * This class is used to standardize the structure of a "Forbidden" error response,
6
- * including the response body, headers, status, and status text.
7
- */
8
-
9
- class Forbidden {
10
- body: any;
11
- cause?: any;
12
- status: number = 403;
13
- statusText: string;
14
-
15
- /**
16
- * Creates an instance of the `Forbidden` class.
17
- *
18
- * @param message - A descriptive message explaining why access is forbidden.
19
- * @param cause - Optional additional information about the cause of the error.
20
- */
21
-
22
- constructor(message: string, cause?: any) {
23
- this.body = { name: "Forbidden", message: message };
24
- this.statusText = message;
25
- this.cause = cause ? JSON.stringify(cause) : undefined;
26
- httpDebug("Forbidden", this.body, this.cause);
27
- }
28
-
29
- /**
30
- * Converts the `Forbidden` 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 {
37
- const responseInit: ResponseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
-
43
- return new Response(JSON.stringify(this.body), responseInit);
44
- }
45
-
46
- /**
47
- * Converts the `Forbidden` instance into a `Response` object using the `Response.json` method.
48
- * This method is an alternative to `toResponse` for generating JSON error responses.
49
- *
50
- * @returns A `Response` object with the JSON body and response metadata.
51
- */
52
-
53
- toJson(): Response {
54
- const responseInit: ResponseInit = {
55
- status: this.status,
56
- statusText: this.statusText,
57
- };
58
-
59
- return Response.json(this.body, responseInit);
60
- }
61
- }
62
-
63
- export { Forbidden };