@arkyn/server 3.0.1-beta.6 → 3.0.1-beta.60
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.
- package/README.md +368 -65
- package/dist/api/arkynLogRequest.d.ts +1 -1
- package/dist/api/arkynLogRequest.d.ts.map +1 -1
- package/dist/api/arkynLogRequest.js +6 -8
- package/dist/api/makeRequest.d.ts +1 -1
- package/dist/api/makeRequest.d.ts.map +1 -1
- package/dist/api/makeRequest.js +3 -6
- package/dist/bundle.js +1090 -0
- package/dist/bundle.umd.cjs +8 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/mapper/arkynLogRequestMapper.js +2 -2
- package/dist/{config/apiInstance.d.ts → services/apiService.d.ts} +21 -21
- package/dist/{config/apiInstance.d.ts.map → services/apiService.d.ts.map} +1 -1
- package/dist/{config/apiInstance.js → services/apiService.js} +18 -18
- package/dist/{config/arkynLogInstance.d.ts → services/arkynLogService.d.ts} +5 -5
- package/dist/services/arkynLogService.d.ts.map +1 -0
- package/dist/{config/arkynLogInstance.js → services/arkynLogService.js} +4 -5
- package/dist/services/formParse.d.ts +3 -3
- package/dist/services/formParse.d.ts.map +1 -1
- package/dist/services/formParse.js +8 -5
- package/dist/services/getCaller.d.ts.map +1 -1
- package/dist/services/getCaller.js +9 -14
- package/dist/services/httpDebug.d.ts +40 -1
- package/dist/services/httpDebug.d.ts.map +1 -1
- package/dist/services/httpDebug.js +42 -1
- package/dist/services/measureRouteExecution.d.ts +3 -0
- package/dist/services/measureRouteExecution.d.ts.map +1 -0
- package/dist/services/measureRouteExecution.js +24 -0
- package/dist/services/schemaValidator.d.ts +3 -3
- package/dist/services/schemaValidator.d.ts.map +1 -1
- package/dist/services/schemaValidator.js +1 -1
- package/package.json +33 -18
- package/dist/config/arkynLogInstance.d.ts.map +0 -1
- package/src/api/arkynLogRequest.ts +0 -116
- package/src/api/deleteRequest.ts +0 -22
- package/src/api/getRequest.ts +0 -20
- package/src/api/makeRequest.ts +0 -122
- package/src/api/patchRequest.ts +0 -22
- package/src/api/postRequest.ts +0 -22
- package/src/api/putRequest.ts +0 -22
- package/src/config/apiInstance.ts +0 -148
- package/src/config/arkynLogInstance.ts +0 -75
- package/src/http/badResponses/badGateway.ts +0 -63
- package/src/http/badResponses/badRequest.ts +0 -63
- package/src/http/badResponses/conflict.ts +0 -63
- package/src/http/badResponses/forbidden.ts +0 -63
- package/src/http/badResponses/notFound.ts +0 -63
- package/src/http/badResponses/notImplemented.ts +0 -63
- package/src/http/badResponses/serverError.ts +0 -63
- package/src/http/badResponses/unauthorized.ts +0 -63
- package/src/http/badResponses/unprocessableEntity.ts +0 -79
- package/src/http/successResponses/created.ts +0 -64
- package/src/http/successResponses/found.ts +0 -67
- package/src/http/successResponses/noContent.ts +0 -42
- package/src/http/successResponses/success.ts +0 -64
- package/src/http/successResponses/updated.ts +0 -64
- package/src/index.ts +0 -31
- package/src/mapper/arkynLogRequestMapper.ts +0 -73
- package/src/services/decodeErrorMessageFromRequest.ts +0 -36
- package/src/services/decodeRequestBody.ts +0 -43
- package/src/services/errorHandler.ts +0 -99
- package/src/services/formParse.ts +0 -83
- package/src/services/getCaller.ts +0 -82
- package/src/services/getScopedParams.ts +0 -43
- package/src/services/httpDebug.ts +0 -61
- package/src/services/schemaValidator.ts +0 -66
- package/src/types/ApiResponseDTO.ts +0 -19
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -5
|
@@ -1,75 +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
|
-
arkynLogBaseApiUrl.replace(
|
|
44
|
-
":trafficSourceId",
|
|
45
|
-
arkynConfig.arkynTrafficSourceId
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
this.arkynConfig = {
|
|
49
|
-
arkynTrafficSourceId: arkynConfig.arkynTrafficSourceId,
|
|
50
|
-
arkynUserToken: arkynConfig.arkynUserToken,
|
|
51
|
-
arkynApiUrl: arkynLogBaseApiUrl,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Retrieves the current arkyn configuration for the ArkynLogInstance.
|
|
57
|
-
*
|
|
58
|
-
* @returns {ArkynConfigProps | undefined} The current arkyn configuration if set,
|
|
59
|
-
* or `undefined` if no configuration has been initialized.
|
|
60
|
-
*/
|
|
61
|
-
static getArkynConfig(): ArkynConfigProps | undefined {
|
|
62
|
-
return this.arkynConfig;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Resets the arkyn configuration to `undefined`.
|
|
67
|
-
* This method can be used to clear the current configuration.
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
static resetArkynConfig() {
|
|
71
|
-
this.arkynConfig = undefined;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
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 };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an HTTP error response with a status code of 404 (Not Found).
|
|
5
|
-
* This class is used to standardize the structure of a "Not Found" error response,
|
|
6
|
-
* including the response body, headers, status, and status text.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class NotFound {
|
|
10
|
-
body: any;
|
|
11
|
-
cause?: any;
|
|
12
|
-
status: number = 404;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `NotFound` class.
|
|
17
|
-
*
|
|
18
|
-
* @param message - A descriptive message explaining the reason the resource was not found.
|
|
19
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.body = { name: "NotFound", message: message };
|
|
24
|
-
this.statusText = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
httpDebug("NotFound", this.body, this.cause);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `NotFound` 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 `NotFound` 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 { NotFound };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an HTTP error response with a status code of 501 (Not Implemented).
|
|
5
|
-
* This class is used to standardize the structure of a "Not Implemented" error response,
|
|
6
|
-
* including the response body, headers, status, and status text.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class NotImplemented {
|
|
10
|
-
body: any;
|
|
11
|
-
cause?: any;
|
|
12
|
-
status: number = 501;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `NotImplemented` class.
|
|
17
|
-
*
|
|
18
|
-
* @param message - A descriptive message explaining why the functionality is not implemented.
|
|
19
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.body = { name: "NotImplemented", message: message };
|
|
24
|
-
this.statusText = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
httpDebug("NotImplemented", this.body, this.cause);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `NotImplemented` 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 `NotImplemented` 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 { NotImplemented };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an HTTP error response with a status code of 500 (Internal Server Error).
|
|
5
|
-
* This class is used to standardize the structure of a "Server Error" response,
|
|
6
|
-
* including the response body, headers, status, and status text.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class ServerError {
|
|
10
|
-
body: any;
|
|
11
|
-
cause?: any;
|
|
12
|
-
status: number = 500;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `ServerError` class.
|
|
17
|
-
*
|
|
18
|
-
* @param message - A descriptive message explaining the cause of the server 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: "ServerError", message: message };
|
|
24
|
-
this.statusText = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
httpDebug("ServerError", this.body, this.cause);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `ServerError` 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 `ServerError` 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 { ServerError };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents an HTTP error response with a status code of 401 (Unauthorized).
|
|
5
|
-
* This class is used to standardize the structure of an "Unauthorized" error response,
|
|
6
|
-
* including the response body, headers, status, and status text.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
class Unauthorized {
|
|
10
|
-
body: any;
|
|
11
|
-
cause?: any;
|
|
12
|
-
status: number = 401;
|
|
13
|
-
statusText: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the `Unauthorized` class.
|
|
17
|
-
*
|
|
18
|
-
* @param message - A descriptive message explaining why the request is unauthorized.
|
|
19
|
-
* @param cause - Optional additional information about the cause of the error.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.body = { name: "Unauthorized", message: message };
|
|
24
|
-
this.statusText = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
httpDebug("Unauthorized", this.body, this.cause);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Converts the `Unauthorized` 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 `Unauthorized` 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 { Unauthorized };
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { httpDebug } from "../../services/httpDebug";
|
|
2
|
-
|
|
3
|
-
type UnprocessableEntityProps = {
|
|
4
|
-
data?: any;
|
|
5
|
-
fieldErrors?: Record<string, string>;
|
|
6
|
-
fields?: Record<string, string>;
|
|
7
|
-
message?: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Represents an HTTP error response with a status code of 422 (Unprocessable Entity).
|
|
12
|
-
* This class is used to standardize the structure of an "Unprocessable Entity" error response,
|
|
13
|
-
* including the response body, headers, status, and status text.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
class UnprocessableEntity {
|
|
17
|
-
body: any;
|
|
18
|
-
status: number = 422;
|
|
19
|
-
statusText: string;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Creates an instance of the `UnprocessableEntity` class.
|
|
23
|
-
*
|
|
24
|
-
* @param props - An object containing details about the error, such as:
|
|
25
|
-
* - `data`: Additional data related to the error.
|
|
26
|
-
* - `fieldErrors`: A record of field-specific error messages.
|
|
27
|
-
* - `fields`: A record of field values that caused the error.
|
|
28
|
-
* - `message`: A descriptive message explaining the error.
|
|
29
|
-
* @param enableDebug - A boolean indicating whether to enable debug logging for this error.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
constructor(props: UnprocessableEntityProps, enableDebug = false) {
|
|
33
|
-
this.statusText = props.message || "Unprocessable Entity";
|
|
34
|
-
this.body = {
|
|
35
|
-
name: "UnprocessableEntity",
|
|
36
|
-
message: props.message || null,
|
|
37
|
-
data: props.data,
|
|
38
|
-
fieldErrors: props.fieldErrors,
|
|
39
|
-
fields: props.fields,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
enableDebug && httpDebug("UnprocessableEntity", this.body);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
|
|
47
|
-
* This method ensures the response has the appropriate headers, status, and status text.
|
|
48
|
-
*
|
|
49
|
-
* @returns A `Response` object with the serialized JSON body and response metadata.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
toResponse(): Response {
|
|
53
|
-
const responseInit: ResponseInit = {
|
|
54
|
-
headers: { "Content-Type": "application/json" },
|
|
55
|
-
status: this.status,
|
|
56
|
-
statusText: this.statusText,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return new Response(JSON.stringify(this.body), responseInit);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Converts the `UnprocessableEntity` instance into a `Response` object using the `Response.json` method.
|
|
64
|
-
* This method is an alternative to `toResponse` for generating JSON error responses.
|
|
65
|
-
*
|
|
66
|
-
* @returns A `Response` object with the JSON body and response metadata.
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
toJson(): Response {
|
|
70
|
-
const responseInit: ResponseInit = {
|
|
71
|
-
status: this.status,
|
|
72
|
-
statusText: this.statusText,
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
return Response.json(this.body, responseInit);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export { UnprocessableEntity };
|