@kiwiproject/kiwi-js 0.10.0 → 0.12.0
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.
|
@@ -11,6 +11,7 @@ export declare const KiwiStandardResponsesExpress: {
|
|
|
11
11
|
standardErrorResponse: (res: Response, status: number, errorMessage: string, errors?: Array<ErrorMessage>, identifierField?: string, identifier?: unknown) => void;
|
|
12
12
|
standardUnauthorizedResponse: (res: Response, errorMessage: string) => void;
|
|
13
13
|
standardForbiddenResponse: (res: Response, errorMessage: string) => void;
|
|
14
|
+
standardForbiddenResponseWithEntity: (res: Response, entity: unknown) => void;
|
|
14
15
|
standardNotFoundResponse: (res: Response, notFoundMessage: string, identifierField?: string, identifier?: unknown) => void;
|
|
15
16
|
standardBadRequestResponse: (res: Response, errorMessage: string, errors?: Array<ErrorMessage>, identifierField?: string, identifier?: unknown) => void;
|
|
16
17
|
};
|
|
@@ -12,11 +12,12 @@ const error_response_1 = require("../model/error-response");
|
|
|
12
12
|
* @param entity the entity or undefined
|
|
13
13
|
*/
|
|
14
14
|
const standardGetResponseWithIdentifier = (res, identifierField, identifier, entity) => {
|
|
15
|
-
if (entity
|
|
16
|
-
res
|
|
15
|
+
if (entity === undefined || entity === null) {
|
|
16
|
+
standardNotFoundResponse(res, `Object with ${identifierField} ${identifier} not found`, identifierField, identifier);
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
res.status(200).json(entity);
|
|
20
|
+
return;
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
23
|
* Returns a 200 OK response if the entity is non-null. Otherwise, returns a 404 Not Found response with
|
|
@@ -27,11 +28,12 @@ const standardGetResponseWithIdentifier = (res, identifierField, identifier, ent
|
|
|
27
28
|
* @param notFoundMessage the specific message to use in the 404 response (if entity is undefined)
|
|
28
29
|
*/
|
|
29
30
|
const standardGetResponseWithMessage = (res, entity, notFoundMessage) => {
|
|
30
|
-
if (entity
|
|
31
|
-
res
|
|
31
|
+
if (entity === undefined || entity === null) {
|
|
32
|
+
standardNotFoundResponse(res, notFoundMessage);
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
+
res.status(200).json(entity);
|
|
36
|
+
return;
|
|
35
37
|
};
|
|
36
38
|
/**
|
|
37
39
|
* Returns a 404 Not Found response containing an {@link ErrorResponse} entity which uses {@code notFoundMessage}
|
|
@@ -118,6 +120,15 @@ const standardUnauthorizedResponse = (res, errorMessage) => {
|
|
|
118
120
|
const standardForbiddenResponse = (res, errorMessage) => {
|
|
119
121
|
res.status(403).json(new error_response_1.ErrorResponse(errorMessage).toMap());
|
|
120
122
|
};
|
|
123
|
+
/**
|
|
124
|
+
* Returns a 403 Forbidden response containing a provided entity.
|
|
125
|
+
*
|
|
126
|
+
* @param res the Express Response
|
|
127
|
+
* @param entity the entity to use
|
|
128
|
+
*/
|
|
129
|
+
const standardForbiddenResponseWithEntity = (res, entity) => {
|
|
130
|
+
res.status(403).json(entity);
|
|
131
|
+
};
|
|
121
132
|
/**
|
|
122
133
|
* Returns a response having the given status and an {@link ErrorResponse} entity which uses {@code errorMessage}
|
|
123
134
|
* as the detailed error message.
|
|
@@ -158,6 +169,7 @@ exports.KiwiStandardResponsesExpress = {
|
|
|
158
169
|
standardErrorResponse,
|
|
159
170
|
standardUnauthorizedResponse,
|
|
160
171
|
standardForbiddenResponse,
|
|
172
|
+
standardForbiddenResponseWithEntity,
|
|
161
173
|
standardNotFoundResponse,
|
|
162
174
|
standardBadRequestResponse,
|
|
163
175
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiwiproject/kiwi-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "KiwiJS is a utility library. It contains a variety of utilities that we have built over time and find useful. Most of these utilities are ports from the Java Kiwi library.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,21 +22,21 @@
|
|
|
22
22
|
]
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"express": "4.
|
|
25
|
+
"express": "4.21.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@babel/core": "7.
|
|
29
|
-
"@babel/preset-env": "7.
|
|
30
|
-
"@babel/preset-typescript": "7.
|
|
28
|
+
"@babel/core": "7.25.2",
|
|
29
|
+
"@babel/preset-env": "7.25.4",
|
|
30
|
+
"@babel/preset-typescript": "7.24.7",
|
|
31
31
|
"@jest/globals": "29.7.0",
|
|
32
32
|
"@types/express": "4.17.21",
|
|
33
|
-
"@types/node": "
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "
|
|
35
|
-
"@typescript-eslint/parser": "7.0
|
|
33
|
+
"@types/node": "22.5.5",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "8.6.0",
|
|
35
|
+
"@typescript-eslint/parser": "8.7.0",
|
|
36
36
|
"babel-jest": "29.7.0",
|
|
37
|
-
"eslint": "
|
|
37
|
+
"eslint": "9.11.0",
|
|
38
38
|
"jest": "29.7.0",
|
|
39
|
-
"prettier": "3.
|
|
40
|
-
"typescript": "5.
|
|
39
|
+
"prettier": "3.3.3",
|
|
40
|
+
"typescript": "5.6.2"
|
|
41
41
|
}
|
|
42
42
|
}
|