@privateaim/server-http-kit 0.8.4 → 0.8.5
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/CHANGELOG.md +27 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +15 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/middlewares/error.d.ts.map +1 -1
- package/dist/middlewares/error.js +14 -5
- package/dist/middlewares/error.js.map +1 -1
- package/dist/request/permission/module.d.ts +1 -1
- package/dist/request/permission/module.d.ts.map +1 -1
- package/dist/services/authup/middleware.js +1 -1
- package/dist/services/authup/middleware.js.map +1 -1
- package/dist/services/authup/permission-provider.d.ts +5 -0
- package/dist/services/authup/permission-provider.d.ts.map +1 -0
- package/dist/services/authup/permission-provider.js +20 -0
- package/dist/services/authup/permission-provider.js.map +1 -0
- package/dist/services/authup/utils.d.ts.map +1 -1
- package/dist/services/authup/utils.js +8 -16
- package/dist/services/authup/utils.js.map +1 -1
- package/package.json +14 -14
- package/src/{validation/index.ts → constants.ts} +5 -5
- package/src/index.ts +1 -1
- package/src/middlewares/error.ts +11 -1
- package/src/request/permission/module.ts +1 -1
- package/src/services/authup/middleware.ts +1 -1
- package/src/services/authup/permission-provider.ts +18 -0
- package/src/services/authup/utils.ts +9 -18
- package/dist/validation/index.d.ts +0 -5
- package/dist/validation/index.d.ts.map +0 -1
- package/dist/validation/index.js +0 -27
- package/dist/validation/index.js.map +0 -1
- package/dist/validation/message.d.ts +0 -2
- package/dist/validation/message.d.ts.map +0 -1
- package/dist/validation/message.js +0 -17
- package/dist/validation/message.js.map +0 -1
- package/dist/validation/module.d.ts +0 -6
- package/dist/validation/module.d.ts.map +0 -1
- package/dist/validation/module.js +0 -45
- package/dist/validation/module.js.map +0 -1
- package/dist/validation/result.d.ts +0 -7
- package/dist/validation/result.d.ts.map +0 -1
- package/dist/validation/result.js +0 -43
- package/dist/validation/result.js.map +0 -1
- package/dist/validation/type.d.ts +0 -15
- package/dist/validation/type.d.ts.map +0 -1
- package/dist/validation/type.js +0 -9
- package/dist/validation/type.js.map +0 -1
- package/src/validation/message.ts +0 -17
- package/src/validation/module.ts +0 -49
- package/src/validation/result.ts +0 -58
- package/src/validation/type.ts +0 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.8.5](https://github.com/PrivateAIM/hub/compare/v0.8.4...v0.8.5) (2025-01-22)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* bump authup dependencies & adjusted code base ([90f7131](https://github.com/PrivateAIM/hub/commit/90f7131723e4e00dad04cb5ababa3e3f232e9c24))
|
|
9
|
+
* migrate to new http create validator syntax ([38ca70e](https://github.com/PrivateAIM/hub/commit/38ca70ee1b060a7d1bd22c87bddcdde21b6fbadc))
|
|
10
|
+
* refactor http controller validation ([#880](https://github.com/PrivateAIM/hub/issues/880)) ([6e11074](https://github.com/PrivateAIM/hub/commit/6e110742f946d4d0e827f4beb497ba2612568b9a))
|
|
11
|
+
* refactoring of master-image workflow ([#845](https://github.com/PrivateAIM/hub/issues/845)) ([7d2b866](https://github.com/PrivateAIM/hub/commit/7d2b8662b24dcf411d3ae8232152fecf53167382))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* **deps:** bump @authup/core-kit from 1.0.0-beta.22 to 1.0.0-beta.23 ([#896](https://github.com/PrivateAIM/hub/issues/896)) ([e0dcfed](https://github.com/PrivateAIM/hub/commit/e0dcfed47320bd53fadbca11a05ca677ed0ef7ff))
|
|
17
|
+
* **deps:** bump @authup/kit from 1.0.0-beta.22 to 1.0.0-beta.23 ([#901](https://github.com/PrivateAIM/hub/issues/901)) ([00a447c](https://github.com/PrivateAIM/hub/commit/00a447ce40ab17b67b0809b41c4233e424303a7c))
|
|
18
|
+
* **deps:** bump authup to v1.0.0-beta.24 ([#963](https://github.com/PrivateAIM/hub/issues/963)) ([90c40c0](https://github.com/PrivateAIM/hub/commit/90c40c0d55018557ee8bb381aad7e3cfbcd29b83))
|
|
19
|
+
* **deps:** bump the minorandpatch group across 1 directory with 31 updates ([#945](https://github.com/PrivateAIM/hub/issues/945)) ([448e9b8](https://github.com/PrivateAIM/hub/commit/448e9b86bf80f83c4aa8bb32ee0a75190a1d5cb8))
|
|
20
|
+
* fake permisison provider for test execution ([480a322](https://github.com/PrivateAIM/hub/commit/480a322595a67efb80809fd0d8319babcf49d63f))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Dependencies
|
|
24
|
+
|
|
25
|
+
* The following workspace dependencies were updated
|
|
26
|
+
* dependencies
|
|
27
|
+
* @privateaim/kit bumped from ^0.8.4 to ^0.8.5
|
|
28
|
+
* @privateaim/server-kit bumped from ^0.8.4 to ^0.8.5
|
|
29
|
+
|
|
3
30
|
## [0.8.4](https://github.com/PrivateAIM/hub/compare/v0.8.3...v0.8.4) (2024-10-24)
|
|
4
31
|
|
|
5
32
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAOA,oBAAY,oBAAoB;IAC5B,MAAM,WAAW;IACjB,MAAM,WAAW;CACpB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HTTPHandlerOperation = void 0;
|
|
10
|
+
var HTTPHandlerOperation;
|
|
11
|
+
(function (HTTPHandlerOperation) {
|
|
12
|
+
HTTPHandlerOperation["CREATE"] = "create";
|
|
13
|
+
HTTPHandlerOperation["UPDATE"] = "update";
|
|
14
|
+
})(HTTPHandlerOperation || (exports.HTTPHandlerOperation = HTTPHandlerOperation = {}));
|
|
15
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC5B,yCAAiB,CAAA;IACjB,yCAAiB,CAAA;AACrB,CAAC,EAHW,oBAAoB,oCAApB,oBAAoB,QAG/B"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -20,9 +20,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
20
20
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./constants"), exports);
|
|
23
24
|
__exportStar(require("./middlewares"), exports);
|
|
24
25
|
__exportStar(require("./request"), exports);
|
|
25
26
|
__exportStar(require("./services"), exports);
|
|
26
27
|
__exportStar(require("./swagger"), exports);
|
|
27
|
-
__exportStar(require("./validation"), exports);
|
|
28
28
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,gDAA8B;AAC9B,4CAA0B;AAC1B,6CAA2B;AAC3B,4CAA0B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,8CAA4B;AAC5B,gDAA8B;AAC9B,4CAA0B;AAC1B,6CAA2B;AAC3B,4CAA0B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/middlewares/error.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/middlewares/error.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMrC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,QAyElD"}
|
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.mountErrorMiddleware = mountErrorMiddleware;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const access_1 = require("@authup/access");
|
|
11
|
+
const kit_1 = require("@privateaim/kit");
|
|
12
12
|
const routup_1 = require("routup");
|
|
13
13
|
const server_kit_1 = require("@privateaim/server-kit");
|
|
14
14
|
const typeorm_extension_1 = require("typeorm-extension");
|
|
15
|
+
const validup_1 = require("validup");
|
|
15
16
|
function mountErrorMiddleware(router) {
|
|
16
17
|
router.use((0, routup_1.errorHandler)((error, req, res) => {
|
|
17
18
|
const isServerError = error.statusCode >= 500 &&
|
|
@@ -22,10 +23,10 @@ function mountErrorMiddleware(router) {
|
|
|
22
23
|
(0, server_kit_1.useLogger)().error(error.cause);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
if (error.cause instanceof
|
|
26
|
+
if (error.cause instanceof access_1.PermissionError) {
|
|
26
27
|
error.expose = true;
|
|
27
28
|
if (error.cause.policy &&
|
|
28
|
-
error.cause.policy.type ===
|
|
29
|
+
error.cause.policy.type === access_1.BuiltInPolicyType.IDENTITY) {
|
|
29
30
|
error.statusCode = 401;
|
|
30
31
|
}
|
|
31
32
|
else {
|
|
@@ -36,6 +37,14 @@ function mountErrorMiddleware(router) {
|
|
|
36
37
|
error.expose = true;
|
|
37
38
|
error.statusCode = 400;
|
|
38
39
|
}
|
|
40
|
+
if (error.cause instanceof validup_1.ValidupNestedError) {
|
|
41
|
+
error.expose = true;
|
|
42
|
+
error.statusCode = 400;
|
|
43
|
+
error.data = {
|
|
44
|
+
children: error.cause.children,
|
|
45
|
+
attributes: error.cause.children.map((child) => child.pathAbsolute),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
39
48
|
// catch and decorate some db errors :)
|
|
40
49
|
switch (error.code) {
|
|
41
50
|
case 'ER_DUP_ENTRY':
|
|
@@ -62,7 +71,7 @@ function mountErrorMiddleware(router) {
|
|
|
62
71
|
statusCode: error.statusCode,
|
|
63
72
|
code: `${error.code}`,
|
|
64
73
|
message: error.message,
|
|
65
|
-
...(exposeError && (0,
|
|
74
|
+
...(exposeError && (0, kit_1.isObject)(error.data) ? error.data : {}),
|
|
66
75
|
};
|
|
67
76
|
}));
|
|
68
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/middlewares/error.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"error.js","sourceR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,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;SAC7D,CAAC;IACN,CAAC,CAAC,CAAC,CAAC;AACR,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PermissionChecker, PermissionCheckerCheckContext } from '@authup/
|
|
1
|
+
import type { PermissionChecker, PermissionCheckerCheckContext } from '@authup/access';
|
|
2
2
|
import type { Request } from 'routup';
|
|
3
3
|
export declare class RequestPermissionChecker {
|
|
4
4
|
protected req: Request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/request/permission/module.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACR,iBAAiB,EACjB,6BAA6B,EAChC,MAAM,
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/request/permission/module.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACR,iBAAiB,EACjB,6BAA6B,EAChC,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAItC,qBAAa,wBAAwB;IACjC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC;IAEvB,SAAS,CAAC,OAAO,EAAE,iBAAiB,CAAC;gBAEzB,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,iBAAiB;IAO9C,KAAK,CAAC,GAAG,EAAE,6BAA6B,GAAI,OAAO,CAAC,IAAI,CAAC;IAIzD,QAAQ,CAAC,GAAG,EAAE,6BAA6B,GAAI,OAAO,CAAC,IAAI,CAAC;IAM5D,aAAa,CAAC,GAAG,EAAE,6BAA6B,GAAI,OAAO,CAAC,IAAI,CAAC;IAIjE,UAAU,CAAC,GAAG,EAAE,6BAA6B,GAAI,OAAO,CAAC,IAAI,CAAC;IAMpE,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,6BAA6B;CAWlE"}
|
|
@@ -37,7 +37,7 @@ function mountAuthupMiddleware(router, options) {
|
|
|
37
37
|
}
|
|
38
38
|
const header = (0, hapic_1.parseAuthorizationHeader)(headerRaw);
|
|
39
39
|
if (header.type === 'Basic') {
|
|
40
|
-
const token = await options.client.token.
|
|
40
|
+
const token = await options.client.token.createWithPassword({
|
|
41
41
|
username: header.username,
|
|
42
42
|
password: header.password,
|
|
43
43
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/services/authup/middleware.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAYH,sDA4FC;AApGD,qEAA+D;AAC/D,iDAAwD;AACxD,iCAAiD;AAEjD,mCAAuD;AAEvD,mCAAsF;AAEtF,SAAgB,qBAAqB,CACjC,MAAc,EACd,OAA4C;IAE5C,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,GAAG,IAAA,uCAA+B,GAAE,CAAC;QAE/C,MAAM,CAAC,GAAG,CAAC,IAAA,oBAAW,EAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACtC,IAAA,kCAA0B,EAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;YAC7D,IAAI,EAAE,CAAC;QACX,CAAC,CAAC,CAAC,CAAC;QAEJ,OAAO;IACX,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,IAAA,oBAAW,EAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC5C,MAAM,SAAS,GAAG,IAAA,yBAAgB,EAAC,GAAG,EAAE,eAAe,CAAC,CAAC;QACzD,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;YAChC,IAAI,EAAE,CAAC;QACX,CAAC;QAED,MAAM,QAAQ,GAAG,wBAAwB,SAAS,EAAE,CAAC;QAErD,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,IAAI,GAAG,MA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J,YAAY,GAAG;YACX,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,UAAU;YACpB,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE;SACvC,CAAC;IACN,CAAC;IAED,IAAI,UAAuD,CAAC;IAC5D,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QACtB,UAAU,GAAG;YACT,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,OAAO,CAAC,WAAW;SAC9B,CAAC;IACN,CAAC;IAED,MAAM,UAAU,GAAG,IAAA,sCAAgB,EAAC;QAChC,aAAa,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE,CAAC,IAAA,yBAAgB,EAAC,GAAG,EAAE,UAAU,CAAC;QACrE,aAAa,EAAE;YACX,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE;YACpC,OAAO,EAAE,YAAY;YACrB,KAAK,EAAE,UAAU;SACpB;QACD,oBAAoB,EAAE,CAClB,GAAG,EACH,IAAI,EACN,EAAE,CAAC,IAAA,kCAA0B,EAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC;KACpE,CAAC,CAAC;IAEH,MAAM,CAAC,GAAG,CAAC,IAAA,oBAAW,EAAC,CACnB,GAAG,EACH,GAAG,EACH,IAAI,EACN,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PermissionGetOptions, PermissionItem, PermissionProvider } from '@authup/access';
|
|
2
|
+
export declare class FakePermissionProvider implements PermissionProvider {
|
|
3
|
+
get(criteria: PermissionGetOptions): Promise<PermissionItem | undefined>;
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=permission-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-provider.d.ts","sourceRoot":"","sources":["../../../src/services/authup/permission-provider.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE/F,qBAAa,sBAAuB,YAAW,kBAAkB;IACvD,GAAG,CAAC,QAAQ,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;CAOjF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.FakePermissionProvider = void 0;
|
|
10
|
+
class FakePermissionProvider {
|
|
11
|
+
async get(criteria) {
|
|
12
|
+
return {
|
|
13
|
+
name: criteria.name,
|
|
14
|
+
realm_id: criteria.realmId,
|
|
15
|
+
policy: null,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.FakePermissionProvider = FakePermissionProvider;
|
|
20
|
+
//# sourceMappingURL=permission-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-provider.js","sourceRoot":"","sources":["../../../src/services/authup/permission-provider.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIH,MAAa,sBAAsB;IAC/B,KAAK,CAAC,GAAG,CAAC,QAA8B;QACpC,OAAO;YACH,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,QAAQ,EAAE,QAAQ,CAAC,OAAO;YAC1B,MAAM,EAAE,IAAI;SACf,CAAC;IACN,CAAC;CACJ;AARD,wDAQC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/authup/utils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/authup/utils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAItC,KAAK,4BAA4B,GAAG,IAAI,CACxC,qBAAqB,EACrB,aAAa,GACb,UAAU,GACV,YAAY,GACZ,KAAK,GACL,UAAU,GACV,UAAU,GACV,OAAO,CACN,CAAC;AAEF,wBAAgB,+BAA+B,IAAI,4BAA4B,CAW9E;AAED,wBAAgB,0BAA0B,CACtC,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,4BAA4B,EAClC,aAAa,CAAC,EAAE,OAAO,QA2B1B"}
|
|
@@ -8,18 +8,10 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createFakeTokenVerificationData = createFakeTokenVerificationData;
|
|
10
10
|
exports.applyTokenVerificationData = applyTokenVerificationData;
|
|
11
|
-
const
|
|
11
|
+
const access_1 = require("@authup/access");
|
|
12
12
|
const core_kit_1 = require("@authup/core-kit");
|
|
13
|
-
const kit_2 = require("@privateaim/kit");
|
|
14
13
|
const request_1 = require("../../request");
|
|
15
|
-
|
|
16
|
-
return Object.values({
|
|
17
|
-
...kit_2.PermissionName,
|
|
18
|
-
...core_kit_1.PermissionName,
|
|
19
|
-
}).map((name) => ({
|
|
20
|
-
name,
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
14
|
+
const permission_provider_1 = require("./permission-provider");
|
|
23
15
|
function createFakeTokenVerificationData() {
|
|
24
16
|
return {
|
|
25
17
|
realm_id: 'd94b2f28-29e3-4ced-b8f1-6923a01dc1ee',
|
|
@@ -27,19 +19,19 @@ function createFakeTokenVerificationData() {
|
|
|
27
19
|
sub_kind: 'user',
|
|
28
20
|
sub: 'd94b2f28-29e3-4ced-b8f1-6923a01dc1ee',
|
|
29
21
|
sub_name: 'admin',
|
|
30
|
-
permissions:
|
|
22
|
+
permissions: [],
|
|
31
23
|
};
|
|
32
24
|
}
|
|
33
25
|
function applyTokenVerificationData(req, data, fakeAbilities) {
|
|
34
|
-
let
|
|
26
|
+
let provider;
|
|
35
27
|
if (fakeAbilities) {
|
|
36
|
-
|
|
28
|
+
provider = new permission_provider_1.FakePermissionProvider();
|
|
37
29
|
}
|
|
38
30
|
else {
|
|
39
|
-
|
|
31
|
+
provider = new access_1.PermissionMemoryProvider(data.permissions);
|
|
40
32
|
}
|
|
41
|
-
const permissionChecker = new
|
|
42
|
-
provider
|
|
33
|
+
const permissionChecker = new access_1.PermissionChecker({
|
|
34
|
+
provider,
|
|
43
35
|
});
|
|
44
36
|
const requestPermissionChecker = new request_1.RequestPermissionChecker(req, permissionChecker);
|
|
45
37
|
(0, request_1.setRequestEnv)(req, 'permissionChecker', requestPermissionChecker);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/services/authup/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/services/authup/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAqBH,0EAWC;AAED,gEA8BC;AA7DD,2CAA6E;AAC7E,+CAAkF;AAGlF,2CAAwE;AACxE,+DAA+D;AAa/D,SAAgB,+BAA+B;IAC3C,OAAO;QACH,QAAQ,EAAE,sCAAsC;QAChD,UAAU,EAAE,4BAAiB;QAE7B,QAAQ,EAAE,MAAM;QAChB,GAAG,EAAE,sCAAsC;QAC3C,QAAQ,EAAE,OAAO;QAEjB,WAAW,EAAE,EAAE;KAClB,CAAC;AACN,CAAC;AAED,SAAgB,0BAA0B,CACtC,GAAY,EACZ,IAAkC,EAClC,aAAuB;IAEvB,IAAI,QAA6B,CAAC;IAClC,IAAI,aAAa,EAAE,CAAC;QAChB,QAAQ,GAAG,IAAI,4CAAsB,EAAE,CAAC;IAC5C,CAAC;SAAM,CAAC;QACJ,QAAQ,GAAG,IAAI,iCAAwB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,iBAAiB,GAAG,IAAI,0BAAiB,CAAC;QAC5C,QAAQ;KACX,CAAC,CAAC;IACH,MAAM,wBAAwB,GAAG,IAAI,kCAAwB,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;IACtF,IAAA,uBAAa,EAAC,GAAG,EAAE,mBAAmB,EAAE,wBAAwB,CAAC,CAAC;IAElE,IAAA,uBAAa,EAAC,GAAG,EAAE,UAAU,EAAE;QAC3B,EAAE,EAAE,IAAI,CAAC,GAAG;QACZ,IAAI,EAAE,IAAI,CAAC,QAAQ;QACnB,OAAO,EAAE,IAAI,CAAC,QAAQ;QACtB,SAAS,EAAE,IAAI,CAAC,UAAU;QAC1B,UAAU,EAAE;YACR,EAAE,EAAE,IAAI,CAAC,GAAG;YACZ,IAAI,EAAE,IAAI,CAAC,QAAQ;SACtB;KACJ,CAAC,CAAC;IAEH,IAAA,uBAAa,EAAC,GAAG,EAAE,QAAQ,EAAE,IAAA,sCAA2B,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@privateaim/server-http-kit",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": {
|
|
@@ -11,33 +11,33 @@
|
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"description": "This package contains the realtime application which connects the API with socket based clients.",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@authup/
|
|
15
|
-
"@authup/
|
|
16
|
-
"@authup/core-
|
|
17
|
-
"@authup/
|
|
18
|
-
"@authup/server-adapter-
|
|
14
|
+
"@authup/access": "^1.0.0-beta.24",
|
|
15
|
+
"@authup/kit": "^1.0.0-beta.24",
|
|
16
|
+
"@authup/core-kit": "^1.0.0-beta.24",
|
|
17
|
+
"@authup/core-http-kit": "^1.0.0-beta.24",
|
|
18
|
+
"@authup/server-adapter-kit": "^1.0.0-beta.24",
|
|
19
|
+
"@authup/server-adapter-http": "^1.0.0-beta.24",
|
|
19
20
|
"@ebec/http": "^2.3.0",
|
|
20
|
-
"@privateaim/kit": "^0.8.
|
|
21
|
-
"@privateaim/server-kit": "^0.8.
|
|
21
|
+
"@privateaim/kit": "^0.8.5",
|
|
22
|
+
"@privateaim/server-kit": "^0.8.5",
|
|
22
23
|
"@routup/basic": "^1.4.1",
|
|
23
24
|
"@routup/decorators": "^3.4.1",
|
|
24
25
|
"@routup/prometheus": "^2.4.0",
|
|
25
26
|
"@routup/rate-limit": "^2.4.0",
|
|
26
27
|
"@routup/swagger": "^2.4.1",
|
|
27
28
|
"cors": "^2.8.5",
|
|
28
|
-
"hapic": "^2.5.
|
|
29
|
-
"locter": "^2.1.4"
|
|
29
|
+
"hapic": "^2.5.2",
|
|
30
|
+
"locter": "^2.1.4",
|
|
31
|
+
"validup": "^0.1.8"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
34
|
"@types/cors": "^2.8.17",
|
|
33
|
-
"
|
|
34
|
-
"redis-extension": "^1.5.0",
|
|
35
|
+
"redis-extension": "^2.0.1",
|
|
35
36
|
"routup": "^4.0.1",
|
|
36
37
|
"typeorm-extension": "^3.6.2"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
39
|
-
"
|
|
40
|
-
"redis-extension": "^1.5.0",
|
|
40
|
+
"redis-extension": "^2.0.1",
|
|
41
41
|
"routup": "^4.0.1",
|
|
42
42
|
"typeorm-extension": "^3.6.2"
|
|
43
43
|
},
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
3
|
* Author Peter Placzek (tada5hi)
|
|
4
4
|
* For the full copyright and license information,
|
|
5
5
|
* view the LICENSE file that was distributed with this source code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export enum HTTPHandlerOperation {
|
|
9
|
+
CREATE = 'create',
|
|
10
|
+
UPDATE = 'update',
|
|
11
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* view the LICENSE file that was distributed with this source code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
export * from './constants';
|
|
8
9
|
export * from './middlewares';
|
|
9
10
|
export * from './request';
|
|
10
11
|
export * from './services';
|
|
11
12
|
export * from './swagger';
|
|
12
|
-
export * from './validation';
|
package/src/middlewares/error.ts
CHANGED
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
* view the LICENSE file that was distributed with this source code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { BuiltInPolicyType, PermissionError } from '@authup/
|
|
8
|
+
import { BuiltInPolicyType, PermissionError } from '@authup/access';
|
|
9
9
|
import { isObject } from '@privateaim/kit';
|
|
10
10
|
import type { Router } from 'routup';
|
|
11
11
|
import { errorHandler } from 'routup';
|
|
12
12
|
import { useLogger } from '@privateaim/server-kit';
|
|
13
13
|
import { EntityRelationLookupError } from 'typeorm-extension';
|
|
14
|
+
import { ValidupNestedError } from 'validup';
|
|
14
15
|
|
|
15
16
|
export function mountErrorMiddleware(router: Router) {
|
|
16
17
|
router.use(errorHandler((error, req, res) => {
|
|
@@ -43,6 +44,15 @@ export function mountErrorMiddleware(router: Router) {
|
|
|
43
44
|
error.statusCode = 400;
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
if (error.cause instanceof ValidupNestedError) {
|
|
48
|
+
error.expose = true;
|
|
49
|
+
error.statusCode = 400;
|
|
50
|
+
error.data = {
|
|
51
|
+
children: error.cause.children,
|
|
52
|
+
attributes: error.cause.children.map((child) => child.pathAbsolute),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
// catch and decorate some db errors :)
|
|
47
57
|
switch (error.code) {
|
|
48
58
|
case 'ER_DUP_ENTRY':
|
|
@@ -9,7 +9,7 @@ import { ScopeName } from '@authup/core-kit';
|
|
|
9
9
|
import type {
|
|
10
10
|
PermissionChecker,
|
|
11
11
|
PermissionCheckerCheckContext,
|
|
12
|
-
} from '@authup/
|
|
12
|
+
} from '@authup/access';
|
|
13
13
|
import type { Request } from 'routup';
|
|
14
14
|
import { useRequestEnv } from '../env';
|
|
15
15
|
import { useRequestIdentity } from '../identity';
|
|
@@ -50,7 +50,7 @@ export function mountAuthupMiddleware(
|
|
|
50
50
|
const header = parseAuthorizationHeader(headerRaw);
|
|
51
51
|
|
|
52
52
|
if (header.type === 'Basic') {
|
|
53
|
-
const token = await options.client.token.
|
|
53
|
+
const token = await options.client.token.createWithPassword({
|
|
54
54
|
username: header.username,
|
|
55
55
|
password: header.password,
|
|
56
56
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { PermissionGetOptions, PermissionItem, PermissionProvider } from '@authup/access';
|
|
9
|
+
|
|
10
|
+
export class FakePermissionProvider implements PermissionProvider {
|
|
11
|
+
async get(criteria: PermissionGetOptions): Promise<PermissionItem | undefined> {
|
|
12
|
+
return {
|
|
13
|
+
name: criteria.name,
|
|
14
|
+
realm_id: criteria.realmId,
|
|
15
|
+
policy: null,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* view the LICENSE file that was distributed with this source code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type {
|
|
9
|
-
import { PermissionChecker, PermissionMemoryProvider } from '@authup/
|
|
10
|
-
import {
|
|
8
|
+
import type { PermissionProvider } from '@authup/access';
|
|
9
|
+
import { PermissionChecker, PermissionMemoryProvider } from '@authup/access';
|
|
10
|
+
import { REALM_MASTER_NAME, transformOAuth2ScopeToArray } from '@authup/core-kit';
|
|
11
11
|
import type { TokenVerificationData } from '@authup/server-adapter-kit';
|
|
12
|
-
import { PermissionName } from '@privateaim/kit';
|
|
13
12
|
import type { Request } from 'routup';
|
|
14
13
|
import { RequestPermissionChecker, setRequestEnv } from '../../request';
|
|
14
|
+
import { FakePermissionProvider } from './permission-provider';
|
|
15
15
|
|
|
16
16
|
type TokenVerificationDataMinimal = Pick<
|
|
17
17
|
TokenVerificationData,
|
|
@@ -24,15 +24,6 @@ TokenVerificationData,
|
|
|
24
24
|
'scope'
|
|
25
25
|
>;
|
|
26
26
|
|
|
27
|
-
function generateAbilities(): PermissionItem[] {
|
|
28
|
-
return Object.values({
|
|
29
|
-
...PermissionName,
|
|
30
|
-
...AuthupPermissionName,
|
|
31
|
-
}).map((name) => ({
|
|
32
|
-
name,
|
|
33
|
-
} satisfies PermissionItem));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
27
|
export function createFakeTokenVerificationData(): TokenVerificationDataMinimal {
|
|
37
28
|
return {
|
|
38
29
|
realm_id: 'd94b2f28-29e3-4ced-b8f1-6923a01dc1ee',
|
|
@@ -42,7 +33,7 @@ export function createFakeTokenVerificationData(): TokenVerificationDataMinimal
|
|
|
42
33
|
sub: 'd94b2f28-29e3-4ced-b8f1-6923a01dc1ee',
|
|
43
34
|
sub_name: 'admin',
|
|
44
35
|
|
|
45
|
-
permissions:
|
|
36
|
+
permissions: [],
|
|
46
37
|
};
|
|
47
38
|
}
|
|
48
39
|
|
|
@@ -51,15 +42,15 @@ export function applyTokenVerificationData(
|
|
|
51
42
|
data: TokenVerificationDataMinimal,
|
|
52
43
|
fakeAbilities?: boolean,
|
|
53
44
|
) {
|
|
54
|
-
let
|
|
45
|
+
let provider : PermissionProvider;
|
|
55
46
|
if (fakeAbilities) {
|
|
56
|
-
|
|
47
|
+
provider = new FakePermissionProvider();
|
|
57
48
|
} else {
|
|
58
|
-
|
|
49
|
+
provider = new PermissionMemoryProvider(data.permissions);
|
|
59
50
|
}
|
|
60
51
|
|
|
61
52
|
const permissionChecker = new PermissionChecker({
|
|
62
|
-
provider
|
|
53
|
+
provider,
|
|
63
54
|
});
|
|
64
55
|
const requestPermissionChecker = new RequestPermissionChecker(req, permissionChecker);
|
|
65
56
|
setRequestEnv(req, 'permissionChecker', requestPermissionChecker);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAOA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
package/dist/validation/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2021-2024.
|
|
4
|
-
* Author Peter Placzek (tada5hi)
|
|
5
|
-
* For the full copyright and license information,
|
|
6
|
-
* view the LICENSE file that was distributed with this source code.
|
|
7
|
-
*/
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
__exportStar(require("./message"), exports);
|
|
24
|
-
__exportStar(require("./module"), exports);
|
|
25
|
-
__exportStar(require("./type"), exports);
|
|
26
|
-
__exportStar(require("./result"), exports);
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,4CAA0B;AAC1B,2CAAyB;AACzB,yCAAuB;AACvB,2CAAyB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/validation/message.ts"],"names":[],"mappings":"AAOA,wBAAgB,+BAA+B,CAC3C,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrD,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,UAO5B"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2024.
|
|
4
|
-
* Author Peter Placzek (tada5hi)
|
|
5
|
-
* For the full copyright and license information,
|
|
6
|
-
* view the LICENSE file that was distributed with this source code.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.buildHTTPValidationErrorMessage = buildHTTPValidationErrorMessage;
|
|
10
|
-
function buildHTTPValidationErrorMessage(name) {
|
|
11
|
-
const names = Array.isArray(name) ? name : [name];
|
|
12
|
-
if (names.length > 1) {
|
|
13
|
-
return `The parameters ${names.join(', ')} is invalid.`;
|
|
14
|
-
}
|
|
15
|
-
return `The parameter ${String(names[0])} is invalid.`;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=message.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/validation/message.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,0EASC;AATD,SAAgB,+BAA+B,CAE7C,IAA2B;IACzB,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAElD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACnB,OAAO,kBAAkB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;IAC5D,CAAC;IACD,OAAO,iBAAiB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC;AAC3D,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { BadRequestError } from '@ebec/http';
|
|
2
|
-
import type { Result, ValidationError } from 'express-validator';
|
|
3
|
-
export declare class HTTPValidationError extends BadRequestError {
|
|
4
|
-
constructor(validation: Result<ValidationError>);
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=module.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/validation/module.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGjE,qBAAa,mBAAoB,SAAQ,eAAe;gBACxC,UAAU,EAAE,MAAM,CAAC,eAAe,CAAC;CAoClD"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2022-2024.
|
|
4
|
-
* Author Peter Placzek (tada5hi)
|
|
5
|
-
* For the full copyright and license information,
|
|
6
|
-
* view the LICENSE file that was distributed with this source code.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.HTTPValidationError = void 0;
|
|
10
|
-
const http_1 = require("@ebec/http");
|
|
11
|
-
const message_1 = require("./message");
|
|
12
|
-
class HTTPValidationError extends http_1.BadRequestError {
|
|
13
|
-
constructor(validation) {
|
|
14
|
-
const errors = validation.array();
|
|
15
|
-
const parameterNames = [];
|
|
16
|
-
for (let i = 0; i < errors.length; i++) {
|
|
17
|
-
const item = errors[i];
|
|
18
|
-
switch (item.type) {
|
|
19
|
-
case 'field': {
|
|
20
|
-
parameterNames.push(item.path);
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
case 'alternative': {
|
|
24
|
-
parameterNames.push(item.nestedErrors.map(((el) => el.path)).join('|'));
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
let message;
|
|
30
|
-
if (parameterNames.length > 0) {
|
|
31
|
-
message = (0, message_1.buildHTTPValidationErrorMessage)(Array.from(new Set(parameterNames)));
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
message = 'An unexpected validation error occurred.';
|
|
35
|
-
}
|
|
36
|
-
super({
|
|
37
|
-
message,
|
|
38
|
-
data: {
|
|
39
|
-
errors,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.HTTPValidationError = HTTPValidationError;
|
|
45
|
-
//# sourceMappingURL=module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/validation/module.ts"],"names":[],"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|
-
import type { Request } from 'routup';
|
|
3
|
-
import type { EntityTarget } from 'typeorm';
|
|
4
|
-
import type { HTTPValidationExtendKeys, HTTPValidationResult } from './type';
|
|
5
|
-
export declare function createHTTPValidationResult<R extends Record<string, any>, M extends Record<string, any> = Record<string, any>>(req: Request, options?: Partial<MatchedDataOptions>): HTTPValidationResult<R, M>;
|
|
6
|
-
export declare function extendHTTPValidationResultWithRelation<R extends Record<string, any>>(result: HTTPValidationResult<R>, target: EntityTarget<any>, keys: HTTPValidationExtendKeys<R>): Promise<HTTPValidationResult<R>>;
|
|
7
|
-
//# sourceMappingURL=result.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/validation/result.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAE7E,wBAAgB,0BAA0B,CACtC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrD,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAM,GAAI,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,CActF;AAED,wBAAsB,sCAAsC,CACxD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAE7B,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAC/B,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,EACzB,IAAI,EAAE,wBAAwB,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAcnC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2022-2024.
|
|
4
|
-
* Author Peter Placzek (tada5hi)
|
|
5
|
-
* For the full copyright and license information,
|
|
6
|
-
* view the LICENSE file that was distributed with this source code.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.createHTTPValidationResult = createHTTPValidationResult;
|
|
10
|
-
exports.extendHTTPValidationResultWithRelation = extendHTTPValidationResultWithRelation;
|
|
11
|
-
const http_1 = require("@ebec/http");
|
|
12
|
-
const kit_1 = require("@privateaim/kit");
|
|
13
|
-
const express_validator_1 = require("express-validator");
|
|
14
|
-
const typeorm_extension_1 = require("typeorm-extension");
|
|
15
|
-
const message_1 = require("./message");
|
|
16
|
-
const module_1 = require("./module");
|
|
17
|
-
function createHTTPValidationResult(req, options = {}) {
|
|
18
|
-
const validation = (0, express_validator_1.validationResult)(req);
|
|
19
|
-
if (!validation.isEmpty()) {
|
|
20
|
-
throw new module_1.HTTPValidationError(validation);
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
data: (0, kit_1.deleteUndefinedObjectProperties)((0, express_validator_1.matchedData)(req, {
|
|
24
|
-
includeOptionals: true,
|
|
25
|
-
...options,
|
|
26
|
-
})),
|
|
27
|
-
meta: {},
|
|
28
|
-
relation: {},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
async function extendHTTPValidationResultWithRelation(result, target, keys) {
|
|
32
|
-
if (result.data[keys.id]) {
|
|
33
|
-
const dataSource = await (0, typeorm_extension_1.useDataSource)();
|
|
34
|
-
const repository = dataSource.getRepository(target);
|
|
35
|
-
const entity = await repository.findOneBy({ id: result.data[keys.id] });
|
|
36
|
-
if (!entity) {
|
|
37
|
-
throw new http_1.BadRequestError((0, message_1.buildHTTPValidationErrorMessage)(keys.id));
|
|
38
|
-
}
|
|
39
|
-
result.relation[keys.entity] = entity;
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=result.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/validation/result.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAaH,gEAiBC;AAED,wFAoBC;AAlDD,qCAA6C;AAC7C,yCAAkE;AAElE,yDAAkE;AAGlE,yDAAkD;AAClD,uCAA4D;AAC5D,qCAA+C;AAG/C,SAAgB,0BAA0B,CAGxC,GAAY,EAAE,UAAuC,EAAE;IACrD,MAAM,UAAU,GAAG,IAAA,oCAAgB,EAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC;QACxB,MAAM,IAAI,4BAAmB,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO;QACH,IAAI,EAAE,IAAA,qCAA+B,EAAC,IAAA,+BAAW,EAAC,GAAG,EAAE;YACnD,gBAAgB,EAAE,IAAI;YACtB,GAAG,OAAO;SACb,CAAC,CAAM;QACR,IAAI,EAAE,EAAO;QACb,QAAQ,EAAE,EAAE;KACf,CAAC;AACN,CAAC;AAEM,KAAK,UAAU,sCAAsC,CAGxD,MAA+B,EAC/B,MAAyB,EACzB,IAAiC;IAEjC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QACvB,MAAM,UAAU,GAAG,MAAM,IAAA,iCAAa,GAAE,CAAC;QAEzC,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACpD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,IAAI,sBAAe,CAAC,IAAA,yCAA+B,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACxE,CAAC;QAED,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAmD,CAAC,GAAG,MAAM,CAAC;IACvF,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type HTTPValidationResultMetaKey<T extends Record<string, any>> = ({
|
|
2
|
-
[K in keyof T]?: T[K] extends Record<string, any> ? T[K] extends Date ? never : K : never;
|
|
3
|
-
})[keyof T];
|
|
4
|
-
export type HTTPValidationResult<T extends Record<string, any>, M extends Record<string, any> = Record<string, any>> = {
|
|
5
|
-
data: Partial<T>;
|
|
6
|
-
relation: {
|
|
7
|
-
[K in HTTPValidationResultMetaKey<T>]?: T[K];
|
|
8
|
-
};
|
|
9
|
-
meta: M;
|
|
10
|
-
};
|
|
11
|
-
export type HTTPValidationExtendKeys<T extends Record<string, any>> = {
|
|
12
|
-
id: keyof T;
|
|
13
|
-
entity: HTTPValidationResultMetaKey<T>;
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/validation/type.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC;KACrE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7C,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC,GAC7B,KAAK;CACZ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAEZ,MAAM,MAAM,oBAAoB,CAC5B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAC/C;IACA,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACjB,QAAQ,EAAE;SACL,CAAC,IAAI,2BAA2B,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC/C,CAAC;IACF,IAAI,EAAE,CAAC,CAAA;CACV,CAAC;AAEN,MAAM,MAAM,wBAAwB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI;IAClE,EAAE,EAAE,MAAM,CAAC,CAAC;IACZ,MAAM,EAAE,2BAA2B,CAAC,CAAC,CAAC,CAAA;CACzC,CAAC"}
|
package/dist/validation/type.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2022-2024.
|
|
4
|
-
* Author Peter Placzek (tada5hi)
|
|
5
|
-
* For the full copyright and license information,
|
|
6
|
-
* view the LICENSE file that was distributed with this source code.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
//# sourceMappingURL=type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/validation/type.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export function buildHTTPValidationErrorMessage<
|
|
9
|
-
T extends Record<string, any> = Record<string, any>,
|
|
10
|
-
>(name: keyof T | (keyof T)[]) {
|
|
11
|
-
const names = Array.isArray(name) ? name : [name];
|
|
12
|
-
|
|
13
|
-
if (names.length > 1) {
|
|
14
|
-
return `The parameters ${names.join(', ')} is invalid.`;
|
|
15
|
-
}
|
|
16
|
-
return `The parameter ${String(names[0])} is invalid.`;
|
|
17
|
-
}
|
package/src/validation/module.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022-2024.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { BadRequestError } from '@ebec/http';
|
|
9
|
-
import type { Result, ValidationError } from 'express-validator';
|
|
10
|
-
import { buildHTTPValidationErrorMessage } from './message';
|
|
11
|
-
|
|
12
|
-
export class HTTPValidationError extends BadRequestError {
|
|
13
|
-
constructor(validation: Result<ValidationError>) {
|
|
14
|
-
const errors : ValidationError[] = validation.array();
|
|
15
|
-
|
|
16
|
-
const parameterNames = [];
|
|
17
|
-
for (let i = 0; i < errors.length; i++) {
|
|
18
|
-
const item = errors[i];
|
|
19
|
-
|
|
20
|
-
switch (item.type) {
|
|
21
|
-
case 'field': {
|
|
22
|
-
parameterNames.push(item.path);
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
case 'alternative': {
|
|
26
|
-
parameterNames.push(item.nestedErrors.map(
|
|
27
|
-
((el) => el.path),
|
|
28
|
-
).join('|'));
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let message : string;
|
|
35
|
-
|
|
36
|
-
if (parameterNames.length > 0) {
|
|
37
|
-
message = buildHTTPValidationErrorMessage(Array.from(new Set(parameterNames)));
|
|
38
|
-
} else {
|
|
39
|
-
message = 'An unexpected validation error occurred.';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
super({
|
|
43
|
-
message,
|
|
44
|
-
data: {
|
|
45
|
-
errors,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
package/src/validation/result.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022-2024.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { BadRequestError } from '@ebec/http';
|
|
9
|
-
import { deleteUndefinedObjectProperties } from '@privateaim/kit';
|
|
10
|
-
import type { MatchedDataOptions } from 'express-validator';
|
|
11
|
-
import { matchedData, validationResult } from 'express-validator';
|
|
12
|
-
import type { Request } from 'routup';
|
|
13
|
-
import type { EntityTarget } from 'typeorm';
|
|
14
|
-
import { useDataSource } from 'typeorm-extension';
|
|
15
|
-
import { buildHTTPValidationErrorMessage } from './message';
|
|
16
|
-
import { HTTPValidationError } from './module';
|
|
17
|
-
import type { HTTPValidationExtendKeys, HTTPValidationResult } from './type';
|
|
18
|
-
|
|
19
|
-
export function createHTTPValidationResult<
|
|
20
|
-
R extends Record<string, any>,
|
|
21
|
-
M extends Record<string, any> = Record<string, any>,
|
|
22
|
-
>(req: Request, options: Partial<MatchedDataOptions> = {}) : HTTPValidationResult<R, M> {
|
|
23
|
-
const validation = validationResult(req);
|
|
24
|
-
if (!validation.isEmpty()) {
|
|
25
|
-
throw new HTTPValidationError(validation);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
data: deleteUndefinedObjectProperties(matchedData(req, {
|
|
30
|
-
includeOptionals: true,
|
|
31
|
-
...options,
|
|
32
|
-
})) as R,
|
|
33
|
-
meta: {} as M,
|
|
34
|
-
relation: {},
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export async function extendHTTPValidationResultWithRelation<
|
|
39
|
-
R extends Record<string, any>,
|
|
40
|
-
>(
|
|
41
|
-
result: HTTPValidationResult<R>,
|
|
42
|
-
target: EntityTarget<any>,
|
|
43
|
-
keys: HTTPValidationExtendKeys<R>,
|
|
44
|
-
) : Promise<HTTPValidationResult<R>> {
|
|
45
|
-
if (result.data[keys.id]) {
|
|
46
|
-
const dataSource = await useDataSource();
|
|
47
|
-
|
|
48
|
-
const repository = dataSource.getRepository(target);
|
|
49
|
-
const entity = await repository.findOneBy({ id: result.data[keys.id] });
|
|
50
|
-
if (!entity) {
|
|
51
|
-
throw new BadRequestError(buildHTTPValidationErrorMessage(keys.id));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
result.relation[keys.entity as keyof HTTPValidationResult<R>['relation']] = entity;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return result;
|
|
58
|
-
}
|
package/src/validation/type.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022-2024.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export type HTTPValidationResultMetaKey<T extends Record<string, any>> = ({
|
|
9
|
-
[K in keyof T]?: T[K] extends Record<string, any> ?
|
|
10
|
-
T[K] extends Date ? never : K :
|
|
11
|
-
never
|
|
12
|
-
})[keyof T];
|
|
13
|
-
|
|
14
|
-
export type HTTPValidationResult<
|
|
15
|
-
T extends Record<string, any>,
|
|
16
|
-
M extends Record<string, any> = Record<string, any>,
|
|
17
|
-
> = {
|
|
18
|
-
data: Partial<T>,
|
|
19
|
-
relation: {
|
|
20
|
-
[K in HTTPValidationResultMetaKey<T>]?: T[K]
|
|
21
|
-
},
|
|
22
|
-
meta: M
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type HTTPValidationExtendKeys<T extends Record<string, any>> = {
|
|
26
|
-
id: keyof T,
|
|
27
|
-
entity: HTTPValidationResultMetaKey<T>
|
|
28
|
-
};
|