@thisisagile/easy-express 9.5.10 → 10.2.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorHandler.js","sourceRoot":"","sources":["../../src/express/ErrorHandler.ts"],"names":[],"mappings":";;;AACA,2CAA0C;AAC1C,4CAmB2B;AAE3B,MAAM,UAAU,GAAG,CAAC,MAAkB,EAAE,SAAmB,EAAE,EAAY,EAAE,CAAC,CAAC;IAC3E,MAAM;IACN,IAAI,EAAE,WAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;CACnC,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,OAAO,EAAmB,EAAY,EAAE;IAChE,OAAO,CACL,IAAA,aAAM,
|
|
1
|
+
{"version":3,"file":"ErrorHandler.js","sourceRoot":"","sources":["../../src/express/ErrorHandler.ts"],"names":[],"mappings":";;;AACA,2CAA0C;AAC1C,4CAmB2B;AAE3B,MAAM,UAAU,GAAG,CAAC,MAAkB,EAAE,SAAmB,EAAE,EAAY,EAAE,CAAC,CAAC;IAC3E,MAAM;IACN,IAAI,EAAE,WAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;CACnC,CAAC,CAAC;AAEH,MAAM,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,OAAO,EAAmB,EAAY,EAAE;IAChE,OAAO,CACL,IAAA,aAAM,EAAC,MAAM,CAAC;SACX,IAAI,CAAC,uBAAW,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,IAAA,mBAAY,EAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,IAAA,eAAQ,EAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;SACpF,IAAI,CAAC,qBAAc,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,IAAI,iBAAU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H,IAAI,QAAkB,CAAC;IACvB,IAAA,YAAK,EAAC,GAAG,EAAE,CAAC,IAAA,wBAAiB,EAAC,CAAC,CAAC,CAAC;SAC9B,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACrB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;SAC3B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,UAAG,CAAC,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;SAC5G,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC;SACvB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3D,CAAC,CAAC;AARW,QAAA,KAAK,SAQhB"}
|
|
@@ -8,19 +8,13 @@ const passport_1 = __importDefault(require("passport"));
|
|
|
8
8
|
const passport_jwt_1 = require("passport-jwt");
|
|
9
9
|
const AuthError_1 = require("./AuthError");
|
|
10
10
|
const easy_1 = require("@thisisagile/easy");
|
|
11
|
-
const checkLabCoat = () => (req, res, next) => next(
|
|
12
|
-
.case(e => easy_1.Environment.Dev.equals(e), undefined)
|
|
13
|
-
.else((0, AuthError_1.authError)(easy_1.HttpStatus.Forbidden)));
|
|
11
|
+
const checkLabCoat = () => (req, res, next) => next(easy_1.Environment.Dev.equals(easy_1.ctx.env.name) ? undefined : (0, AuthError_1.authError)(easy_1.HttpStatus.Forbidden));
|
|
14
12
|
exports.checkLabCoat = checkLabCoat;
|
|
15
13
|
const checkToken = () => passport_1.default.authenticate('jwt', { session: false, failWithError: true });
|
|
16
14
|
exports.checkToken = checkToken;
|
|
17
|
-
const checkScope = (scope) => (req, res, next) => next((0,
|
|
18
|
-
.case(s => req.user?.scopes.includes(s), undefined)
|
|
19
|
-
.else((0, AuthError_1.authError)(easy_1.HttpStatus.Forbidden)));
|
|
15
|
+
const checkScope = (scope) => (req, res, next) => next(req.user?.scopes?.includes(scope.id) ? undefined : (0, AuthError_1.authError)(easy_1.HttpStatus.Forbidden));
|
|
20
16
|
exports.checkScope = checkScope;
|
|
21
|
-
const checkUseCase = (uc) => (req, res, next) => next((0,
|
|
22
|
-
.case(u => req.user?.usecases.includes(u), undefined)
|
|
23
|
-
.else((0, AuthError_1.authError)(easy_1.HttpStatus.Forbidden)));
|
|
17
|
+
const checkUseCase = (uc) => (req, res, next) => next(req.user?.usecases?.includes(uc.id) ? undefined : (0, AuthError_1.authError)(easy_1.HttpStatus.Forbidden));
|
|
24
18
|
exports.checkUseCase = checkUseCase;
|
|
25
19
|
const wrapSecretOrKeyProvider = (p) => p
|
|
26
20
|
? (request, rawJwtToken, done) => p(request, rawJwtToken)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SecurityHandler.js","sourceRoot":"","sources":["../../src/express/SecurityHandler.ts"],"names":[],"mappings":";;;;;;AACA,wDAAgC;AAChC,+CAAiG;AACjG,2CAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"SecurityHandler.js","sourceRoot":"","sources":["../../src/express/SecurityHandler.ts"],"names":[],"mappings":";;;;;;AACA,wDAAgC;AAChC,+CAAiG;AACjG,2CAAwC;AACxC,4CAAiF;AA0B1E,MAAM,YAAY,GAAG,GAAmB,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CACnE,IAAI,CAAC,kBAAW,CAAC,GAAG,CAAC,MAAM,CAAC,UAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC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CAAC;IACxB,CAAC,CAAC,SAAS,CAAC;AAET,MAAM,QAAQ,GAAG,CAAC,EAAE,kBAAkB,KAAsB,EAAE,EAAuF,EAAE;IAC5J,MAAM,SAAS,GAAoB;QACjC,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;QACxD,WAAW,EAAE,kBAAkB,EAAE,WAAW,IAAI,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAG,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QACrI,mBAAmB,EAAE,uBAAuB,CAAC,kBAAkB,EAAE,mBAAmB,CAAC;QACrF,MAAM,EAAE,kBAAkB,EAAE,MAAM;QAClC,QAAQ,EAAE,kBAAkB,EAAE,QAAQ;QACtC,UAAU,EAAE,kBAAkB,EAAE,UAAU;QAC1C,iBAAiB,EAAE,IAAI;KACxB,CAAC;IAEF,MAAM,QAAQ,GAAG,IAAI,uBAAW,CAAC,SAAS,EAAE,CAAC,GAAoB,EAAE,OAAY,EAAE,IAAmC,EAAE,EAAE;QACtH,UAAG,CAAC,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC;QAC5B,UAAG,CAAC,OAAO,CAAC,GAAG,GAAG,yBAAU,CAAC,2BAA2B,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACtE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,kBAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACvB,OAAO,kBAAQ,CAAC,UAAU,EAAE,CAAC;AAC/B,CAAC,CAAC;AAnBW,QAAA,QAAQ,YAmBnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy-express",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.2.1",
|
|
4
4
|
"description": "Straightforward library for building domain-driven microservice architectures",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@thisisagile/easy-test": "
|
|
34
|
+
"@thisisagile/easy-test": "10.2.1",
|
|
35
35
|
"@types/cls-hooked": "^4.3.3",
|
|
36
36
|
"@types/form-urlencoded": "^4.4.0",
|
|
37
37
|
"@types/jsonwebtoken": "^8.5.8",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@types/validator": "^13.7.2"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@thisisagile/easy": "
|
|
44
|
+
"@thisisagile/easy": "10.2.1",
|
|
45
45
|
"@types/express": "^4.17.13",
|
|
46
46
|
"cls-hooked": "^4.2.2",
|
|
47
47
|
"express": "^4.17.3",
|
|
@@ -28,7 +28,7 @@ const toResponse = (status: HttpStatus, errors: Result[] = []): Response => ({
|
|
|
28
28
|
|
|
29
29
|
const toBody = ({ origin, options }: OriginatedError): Response => {
|
|
30
30
|
return (
|
|
31
|
-
choose
|
|
31
|
+
choose(origin)
|
|
32
32
|
.type(isAuthError, ae => toResponse(toHttpStatus(ae.status), [toResult(ae.message)]))
|
|
33
33
|
.type(isDoesNotExist, e => toResponse(options?.onNotFound ?? HttpStatus.NotFound, [toResult(e.reason ?? e.message)]))
|
|
34
34
|
// This service breaks with an error
|
|
@@ -2,7 +2,7 @@ import express, { Request, RequestHandler } from 'express';
|
|
|
2
2
|
import passport from 'passport';
|
|
3
3
|
import passportJwt, { ExtractJwt, Strategy as JwtStrategy, StrategyOptions } from 'passport-jwt';
|
|
4
4
|
import { authError } from './AuthError';
|
|
5
|
-
import {
|
|
5
|
+
import { ctx, Environment, HttpStatus, Scope, UseCase } from '@thisisagile/easy';
|
|
6
6
|
|
|
7
7
|
type SecretOrKeyProvider = (request: Request, rawJwtToken: any) => Promise<string | Buffer>;
|
|
8
8
|
|
|
@@ -29,38 +29,26 @@ export interface SecurityOptions {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export const checkLabCoat = (): RequestHandler => (req, res, next) =>
|
|
32
|
-
next(
|
|
33
|
-
choose(ctx.env.name)
|
|
34
|
-
.case(e => Environment.Dev.equals(e), undefined)
|
|
35
|
-
.else(authError(HttpStatus.Forbidden))
|
|
36
|
-
);
|
|
32
|
+
next(Environment.Dev.equals(ctx.env.name) ? undefined : authError(HttpStatus.Forbidden));
|
|
37
33
|
|
|
38
34
|
export const checkToken = (): RequestHandler => passport.authenticate('jwt', { session: false, failWithError: true });
|
|
39
35
|
|
|
40
36
|
export const checkScope =
|
|
41
37
|
(scope: Scope): RequestHandler =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
choose(scope.id)
|
|
45
|
-
.case(s => (req.user as any)?.scopes.includes(s), undefined)
|
|
46
|
-
.else(authError(HttpStatus.Forbidden))
|
|
47
|
-
);
|
|
38
|
+
(req, res, next) =>
|
|
39
|
+
next((req.user as any)?.scopes?.includes(scope.id) ? undefined : authError(HttpStatus.Forbidden));
|
|
48
40
|
|
|
49
41
|
export const checkUseCase =
|
|
50
42
|
(uc: UseCase): RequestHandler =>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
choose(uc.id)
|
|
54
|
-
.case(u => (req.user as any)?.usecases.includes(u), undefined)
|
|
55
|
-
.else(authError(HttpStatus.Forbidden))
|
|
56
|
-
);
|
|
43
|
+
(req, res, next) =>
|
|
44
|
+
next((req.user as any)?.usecases?.includes(uc.id) ? undefined : authError(HttpStatus.Forbidden));
|
|
57
45
|
|
|
58
46
|
const wrapSecretOrKeyProvider = (p?: SecretOrKeyProvider): passportJwt.SecretOrKeyProvider | undefined =>
|
|
59
47
|
p
|
|
60
48
|
? (request, rawJwtToken, done) =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
p(request, rawJwtToken)
|
|
50
|
+
.then(t => done(null, t))
|
|
51
|
+
.catch(e => done(e))
|
|
64
52
|
: undefined;
|
|
65
53
|
|
|
66
54
|
export const security = ({ jwtStrategyOptions }: SecurityOptions = {}): ((req: express.Request, res: express.Response, next: express.NextFunction) => void) => {
|