@thisisagile/easy-express 8.41.19 → 8.42.2
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.
|
@@ -8,7 +8,7 @@ const toResponse = (status, errors = []) => ({
|
|
|
8
8
|
body: easy_1.rest.toError(status, errors),
|
|
9
9
|
});
|
|
10
10
|
const toBody = ({ origin, options }) => {
|
|
11
|
-
return (0, easy_1.choose)(origin)
|
|
11
|
+
return ((0, easy_1.choose)(origin)
|
|
12
12
|
.type(AuthError_1.isAuthError, ae => toResponse((0, easy_1.toHttpStatus)(ae.status), [(0, easy_1.toResult)(ae.message)]))
|
|
13
13
|
.case(o => easy_1.Exception.DoesNotExist.equals(o), (o) => toResponse(options?.onNotFound ?? easy_1.HttpStatus.NotFound, [(0, easy_1.toResult)(o.reason ?? o.message)]))
|
|
14
14
|
.type(easy_1.isError, e => toResponse(easy_1.HttpStatus.InternalServerError, [(0, easy_1.toResult)(e.message)]))
|
|
@@ -16,17 +16,16 @@ const toBody = ({ origin, options }) => {
|
|
|
16
16
|
.type(easy_1.isResponse, r => toResponse(easy_1.HttpStatus.InternalServerError, r.body.error?.errors))
|
|
17
17
|
.type(easy_1.isException, e => toResponse(options?.onError ?? easy_1.HttpStatus.BadRequest, [(0, easy_1.toResult)(e.reason ?? e.message)]))
|
|
18
18
|
.type(easy_1.isText, t => toResponse(options?.onError ?? easy_1.HttpStatus.BadRequest, [(0, easy_1.toResult)((0, easy_1.asString)(t))]))
|
|
19
|
-
.else(() => toResponse(easy_1.HttpStatus.InternalServerError, [(0, easy_1.toResult)('Unknown error')]));
|
|
19
|
+
.else(() => toResponse(easy_1.HttpStatus.InternalServerError, [(0, easy_1.toResult)('Unknown error')])));
|
|
20
20
|
};
|
|
21
21
|
const error = (e, req, res, _next) => {
|
|
22
|
+
let response;
|
|
22
23
|
(0, easy_1.tryTo)(() => (0, easy_1.toOriginatedError)(e))
|
|
23
24
|
.map(oe => toBody(oe))
|
|
25
|
+
.accept(r => (response = r))
|
|
24
26
|
.accept(r => (easy_1.ctx.request.lastError = r.status.isServerError ? r.body.error?.errors[0]?.message : undefined))
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
console.error('ErrorHandler:', o);
|
|
28
|
-
return res.status(easy_1.HttpStatus.InternalServerError.status).json(toResponse(easy_1.HttpStatus.InternalServerError, [(0, easy_1.toResult)(easy_1.HttpStatus.InternalServerError.name)]).body);
|
|
29
|
-
});
|
|
27
|
+
.recover(() => response)
|
|
28
|
+
.accept(r => res.status(r.status.status).json(r.body));
|
|
30
29
|
};
|
|
31
30
|
exports.error = error;
|
|
32
31
|
//# sourceMappingURL=ErrorHandler.js.map
|
|
@@ -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,IAAA,aAAM,EAAgB,MAAM,CAAC;
|
|
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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/SecurityHandler.ts"],"names":[],"mappings":";;;;;;AACA,wDAAgC;AAChC,+CAAiG;AACjG,2CAAwC;AACxC,4CAAyF;AA0BlF,MAAM,YAAY,GAAG,GAAmB,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CACnE,IAAI,CACF,IAAA,aAAM,EAAC,UAAG,CAAC,GAAG,CAAC,IAAI,CAAC;KACjB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,kBAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC;KAC/C,IAAI,CAAC,IAAA,qBAAS,EAAC,iBAAU,CAAC,SAAS,CAAC,CAAC,CACzC,CAAC;AALS,QAAA,YAAY,gBAKrB;AAEG,MAAM,UAAU,GAAG,GAAmB,EAAE,CAAC,kBAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;AAAzG,QAAA,UAAU,cAA+F;AAE/G,MAAM,UAAU,GACrB,CAAC,KAAY,EAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"SecurityHandler.js","sourceRoot":"","sources":["../../src/express/SecurityHandler.ts"],"names":[],"mappings":";;;;;;AACA,wDAAgC;AAChC,+CAAiG;AACjG,2CAAwC;AACxC,4CAAyF;AA0BlF,MAAM,YAAY,GAAG,GAAmB,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CACnE,IAAI,CACF,IAAA,aAAM,EAAC,UAAG,CAAC,GAAG,CAAC,IAAI,CAAC;KACjB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,kBAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC;KAC/C,IAAI,CAAC,IAAA,qBAAS,EAAC,iBAAU,CAAC,SAAS,CAAC,CAAC,CACzC,CAAC;AALS,QAAA,YAAY,gBAKrB;AA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"8.42.2",
|
|
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": "8.
|
|
34
|
+
"@thisisagile/easy-test": "8.42.2",
|
|
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.1"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@thisisagile/easy": "8.
|
|
44
|
+
"@thisisagile/easy": "8.42.2",
|
|
45
45
|
"@types/express": "^4.17.13",
|
|
46
46
|
"cls-hooked": "^4.2.2",
|
|
47
47
|
"express": "^4.17.1",
|
|
@@ -27,31 +27,32 @@ const toResponse = (status: HttpStatus, errors: Result[] = []): Response => ({
|
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
const toBody = ({ origin, options }: OriginatedError): Response => {
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
return (
|
|
31
|
+
choose<Response, any>(origin)
|
|
32
|
+
.type(isAuthError, ae => toResponse(toHttpStatus(ae.status), [toResult(ae.message)]))
|
|
33
|
+
.case(
|
|
34
|
+
o => Exception.DoesNotExist.equals(o),
|
|
35
|
+
(o: Exception) => toResponse(options?.onNotFound ?? HttpStatus.NotFound, [toResult(o.reason ?? o.message)])
|
|
36
|
+
)
|
|
37
|
+
// This service breaks with an error
|
|
38
|
+
.type(isError, e => toResponse(HttpStatus.InternalServerError, [toResult(e.message)]))
|
|
39
|
+
// This service fails
|
|
40
|
+
.type(isResults, r => toResponse(options?.onError ?? HttpStatus.BadRequest, r.results))
|
|
41
|
+
// Underlying service fails
|
|
42
|
+
.type(isResponse, r => toResponse(HttpStatus.InternalServerError, r.body.error?.errors))
|
|
43
|
+
.type(isException, e => toResponse(options?.onError ?? HttpStatus.BadRequest, [toResult(e.reason ?? e.message)]))
|
|
44
|
+
// This service fails with a string
|
|
45
|
+
.type(isText, t => toResponse(options?.onError ?? HttpStatus.BadRequest, [toResult(asString(t))]))
|
|
46
|
+
.else(() => toResponse(HttpStatus.InternalServerError, [toResult('Unknown error')]))
|
|
47
|
+
);
|
|
46
48
|
};
|
|
47
49
|
|
|
48
50
|
export const error = (e: Error, req: express.Request, res: express.Response, _next: express.NextFunction): void => {
|
|
51
|
+
let response: Response;
|
|
49
52
|
tryTo(() => toOriginatedError(e))
|
|
50
53
|
.map(oe => toBody(oe))
|
|
54
|
+
.accept(r => (response = r))
|
|
51
55
|
.accept(r => (ctx.request.lastError = r.status.isServerError ? r.body.error?.errors[0]?.message : undefined))
|
|
52
|
-
.
|
|
53
|
-
.
|
|
54
|
-
console.error('ErrorHandler:', o);
|
|
55
|
-
return res.status(HttpStatus.InternalServerError.status).json(toResponse(HttpStatus.InternalServerError, [toResult(HttpStatus.InternalServerError.name)]).body) as any;
|
|
56
|
-
});
|
|
56
|
+
.recover(() => response)
|
|
57
|
+
.accept(r => res.status(r.status.status).json(r.body));
|
|
57
58
|
};
|
|
@@ -32,35 +32,35 @@ export const checkLabCoat = (): RequestHandler => (req, res, next) =>
|
|
|
32
32
|
next(
|
|
33
33
|
choose(ctx.env.name)
|
|
34
34
|
.case(e => Environment.Dev.equals(e), undefined)
|
|
35
|
-
.else(authError(HttpStatus.Forbidden))
|
|
35
|
+
.else(authError(HttpStatus.Forbidden))
|
|
36
36
|
);
|
|
37
37
|
|
|
38
38
|
export const checkToken = (): RequestHandler => passport.authenticate('jwt', { session: false, failWithError: true });
|
|
39
39
|
|
|
40
40
|
export const checkScope =
|
|
41
41
|
(scope: Scope): RequestHandler =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
(req, res, next) =>
|
|
43
|
+
next(
|
|
44
|
+
choose(scope.id)
|
|
45
|
+
.case(s => (req.user as any)?.scopes.includes(s), undefined)
|
|
46
|
+
.else(authError(HttpStatus.Forbidden))
|
|
47
|
+
);
|
|
48
48
|
|
|
49
49
|
export const checkUseCase =
|
|
50
50
|
(uc: UseCase): RequestHandler =>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
(req, res, next) =>
|
|
52
|
+
next(
|
|
53
|
+
choose(uc.id)
|
|
54
|
+
.case(u => (req.user as any)?.usecases.includes(u), undefined)
|
|
55
|
+
.else(authError(HttpStatus.Forbidden))
|
|
56
|
+
);
|
|
57
57
|
|
|
58
58
|
const wrapSecretOrKeyProvider = (p?: SecretOrKeyProvider): passportJwt.SecretOrKeyProvider | undefined =>
|
|
59
59
|
p
|
|
60
60
|
? (request, rawJwtToken, done) =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
p(request, rawJwtToken)
|
|
62
|
+
.then(t => done(null, t))
|
|
63
|
+
.catch(e => done(e))
|
|
64
64
|
: undefined;
|
|
65
65
|
|
|
66
66
|
export const security = ({ jwtStrategyOptions }: SecurityOptions = {}): ((req: express.Request, res: express.Response, next: express.NextFunction) => void) => {
|