@kiwiproject/kiwi-js 0.11.0 → 1.0.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.
- package/README.md +1 -1
- package/dist/errors/kiwi-not-logged-in-error.d.ts +4 -0
- package/dist/errors/kiwi-not-logged-in-error.js +10 -0
- package/dist/errors/kiwi-standard-response-error.d.ts +5 -0
- package/dist/errors/kiwi-standard-response-error.js +19 -0
- package/dist/express/kiwi-express-error-middleware.d.ts +2 -0
- package/dist/express/kiwi-express-error-middleware.js +26 -0
- package/dist/express/kiwi-standard-responses-express.js +8 -6
- package/package.json +32 -18
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
### KiwiJS
|
|
2
|
-
[](https://github.com/kiwiproject/kiwi-js/actions?query=
|
|
2
|
+
[](https://github.com/kiwiproject/kiwi-js/actions/workflows/build.yml?query=branch%3Amain)
|
|
3
3
|
[](https://sonarcloud.io/dashboard?id=kiwiproject_kiwi-js)
|
|
4
4
|
[](https://sonarcloud.io/dashboard?id=kiwiproject_kiwi-js)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const kiwi_standard_response_error_1 = require("./kiwi-standard-response-error");
|
|
4
|
+
class KiwiNotLoggedInError extends kiwi_standard_response_error_1.default {
|
|
5
|
+
constructor(message = "User is not logged in", nestedError) {
|
|
6
|
+
super(message, 401, nestedError);
|
|
7
|
+
this.name = "KiwiNotLoggedInError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.default = KiwiNotLoggedInError;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class KiwiStandardResponseError extends Error {
|
|
4
|
+
constructor(message, statusCode, nestedError) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "KiwiStandardResponseError";
|
|
7
|
+
this.statusCode = statusCode;
|
|
8
|
+
this.nestedError = nestedError;
|
|
9
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
10
|
+
if (Error.captureStackTrace) {
|
|
11
|
+
Error.captureStackTrace(this, KiwiStandardResponseError);
|
|
12
|
+
}
|
|
13
|
+
// If a nested error is provided, append its stack
|
|
14
|
+
if (nestedError && nestedError.stack) {
|
|
15
|
+
this.stack += `\nCaused by: ${nestedError.stack}`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = KiwiStandardResponseError;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupFallback = setupFallback;
|
|
4
|
+
const kiwi_standard_responses_express_1 = require("./kiwi-standard-responses-express");
|
|
5
|
+
function setupFallback(logger = undefined) {
|
|
6
|
+
return (err, req, res, next) => {
|
|
7
|
+
var _a;
|
|
8
|
+
if (err.name === "KiwiNotLoggedInError") {
|
|
9
|
+
return kiwi_standard_responses_express_1.KiwiStandardResponsesExpress.standardUnauthorizedResponse(res, err.message);
|
|
10
|
+
}
|
|
11
|
+
if (logger) {
|
|
12
|
+
logger(`Error while processing path ${req.method} ${req.originalUrl}: ${err.message}`, (_a = err.stack) === null || _a === void 0 ? void 0 : _a.toString());
|
|
13
|
+
}
|
|
14
|
+
if (res.headersSent) {
|
|
15
|
+
next(err);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
if (err.name === "KiwiStandardResponseError") {
|
|
19
|
+
kiwi_standard_responses_express_1.KiwiStandardResponsesExpress.standardErrorResponse(res, err.statusCode, err.message);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
kiwi_standard_responses_express_1.KiwiStandardResponsesExpress.standardErrorResponse(res, 500, err.message);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -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}
|
package/package.json
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiwiproject/kiwi-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.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
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/kiwiproject/kiwi-js.git"
|
|
8
|
+
},
|
|
5
9
|
"main": "dist/index.js",
|
|
6
10
|
"types": "dist/index.d.ts",
|
|
7
11
|
"files": [
|
|
8
12
|
"/dist"
|
|
9
13
|
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"provenance": true
|
|
17
|
+
},
|
|
10
18
|
"scripts": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"format": "npx prettier --ignore-path .gitignore --write \"**/*.+(ts|js|json)\"",
|
|
21
|
+
"lint": "npx eslint --fix src",
|
|
22
|
+
"test": "npx jest --coverage --collectCoverageFrom=src/**/*.ts"
|
|
14
23
|
},
|
|
15
24
|
"jest": {
|
|
16
25
|
"testPathIgnorePatterns": [
|
|
@@ -22,21 +31,26 @@
|
|
|
22
31
|
]
|
|
23
32
|
},
|
|
24
33
|
"dependencies": {
|
|
25
|
-
"express": "
|
|
34
|
+
"express": "5.2.1"
|
|
26
35
|
},
|
|
27
36
|
"devDependencies": {
|
|
28
|
-
"
|
|
29
|
-
"@babel/
|
|
30
|
-
"@babel/preset-
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"prettier": "
|
|
40
|
-
"
|
|
37
|
+
"semantic-release": "^25.0.2",
|
|
38
|
+
"@babel/core": "7.28.6",
|
|
39
|
+
"@babel/preset-env": "7.28.6",
|
|
40
|
+
"@babel/preset-typescript": "7.28.5",
|
|
41
|
+
"@eslint/eslintrc": "3.3.3",
|
|
42
|
+
"@eslint/js": "9.39.2",
|
|
43
|
+
"@jest/globals": "30.2.0",
|
|
44
|
+
"@types/express": "5.0.6",
|
|
45
|
+
"@types/node": "25.0.9",
|
|
46
|
+
"babel-jest": "30.2.0",
|
|
47
|
+
"eslint": "9.39.2",
|
|
48
|
+
"eslint-config-prettier": "10.1.8",
|
|
49
|
+
"eslint-plugin-prettier": "5.5.5",
|
|
50
|
+
"globals": "17.0.0",
|
|
51
|
+
"jest": "30.2.0",
|
|
52
|
+
"prettier": "3.8.0",
|
|
53
|
+
"typescript": "5.9.3",
|
|
54
|
+
"typescript-eslint": "8.53.0"
|
|
41
55
|
}
|
|
42
56
|
}
|