@alanszp/express-common-fn 10.0.3 → 12.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/dist/commonErrorsHandler.js +29 -14
- package/dist/commonErrorsHandler.js.map +1 -1
- package/node_modules/@alanszp/audit/dist/errors/AuditError.d.ts +2 -2
- package/node_modules/@alanszp/audit/dist/errors/AuditError.js +1 -1
- package/node_modules/@alanszp/audit/dist/errors/AuditError.js.map +1 -1
- package/node_modules/@alanszp/audit/dist/errors/MissingAuditFieldsError.d.ts +3 -3
- package/node_modules/@alanszp/audit/dist/errors/MissingAuditFieldsError.js +2 -2
- package/node_modules/@alanszp/audit/dist/errors/MissingAuditFieldsError.js.map +1 -1
- package/node_modules/@alanszp/audit/package.json +5 -4
- package/node_modules/@alanszp/audit/src/errors/AuditError.ts +2 -2
- package/node_modules/@alanszp/audit/src/errors/MissingAuditFieldsError.ts +4 -7
- package/node_modules/@alanszp/errors/dist/BaseError.js.map +1 -0
- package/node_modules/@alanszp/errors/dist/HttpRenderableError.d.ts +4 -0
- package/node_modules/@alanszp/errors/dist/HttpRenderableError.js +8 -0
- package/node_modules/@alanszp/errors/dist/HttpRenderableError.js.map +1 -0
- package/node_modules/@alanszp/errors/dist/InternalServerError.d.ts +8 -0
- package/node_modules/@alanszp/errors/dist/InternalServerError.js +24 -0
- package/node_modules/@alanszp/errors/dist/InternalServerError.js.map +1 -0
- package/node_modules/@alanszp/errors/dist/RenderableError.d.ts +15 -0
- package/node_modules/@alanszp/errors/dist/RenderableError.js +27 -0
- package/node_modules/@alanszp/errors/dist/RenderableError.js.map +1 -0
- package/node_modules/@alanszp/errors/dist/index.d.ts +4 -3
- package/node_modules/@alanszp/errors/dist/index.js +4 -3
- package/node_modules/@alanszp/errors/dist/index.js.map +1 -1
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/.gitignore +3 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/.npmignore +3 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/LICENSE +21 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/app/appIdentifier.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/app/index.d.ts +1 -0
- package/node_modules/@alanszp/errors/{dist/errors/http → node_modules/@alanszp/core/dist/app}/index.js +6 -6
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/app/index.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/assignKey.d.ts +2 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/assignKey.js +20 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/assignKey.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/index.d.ts +2 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/index.js +19 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/index.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/keepOrUpdate.d.ts +3 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js +26 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/types.d.ts +6 -0
- package/node_modules/@alanszp/errors/{dist/errors/RenderableError.js → node_modules/@alanszp/core/dist/editable/types.js} +1 -1
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/types.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/index.d.ts +4 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/index.js +21 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/index.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/ListResult.d.ts +7 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/ListResult.js +8 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/ListResult.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Orderable.d.ts +11 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Orderable.js +13 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Orderable.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Paginable.d.ts +14 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Paginable.js +22 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Paginable.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/index.d.ts +3 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/index.js +20 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/index.js.map +1 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/package.json +25 -0
- package/node_modules/@alanszp/errors/node_modules/@alanszp/core/tsconfig.json +15 -0
- package/node_modules/@alanszp/errors/package.json +7 -2
- package/node_modules/@alanszp/errors/src/HttpRenderableError.ts +5 -0
- package/node_modules/@alanszp/errors/src/{errors/http/InternalServerError.ts → InternalServerError.ts} +8 -10
- package/node_modules/@alanszp/errors/src/RenderableError.ts +37 -0
- package/node_modules/@alanszp/errors/src/index.ts +4 -3
- package/node_modules/@alanszp/express/dist/helpers/renderErrorJson.d.ts +4 -0
- package/node_modules/@alanszp/express/dist/helpers/renderErrorJson.js +32 -0
- package/node_modules/@alanszp/express/dist/helpers/renderErrorJson.js.map +1 -0
- package/node_modules/@alanszp/express/dist/index.d.ts +0 -1
- package/node_modules/@alanszp/express/dist/index.js +0 -1
- package/node_modules/@alanszp/express/dist/index.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/authedForOrg.js +3 -4
- package/node_modules/@alanszp/express/dist/middlewares/authedForOrg.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/authenticateUser.js +8 -8
- package/node_modules/@alanszp/express/dist/middlewares/authenticateUser.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/createContext.js +2 -2
- package/node_modules/@alanszp/express/dist/middlewares/createContext.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/createContext.test.js +3 -3
- package/node_modules/@alanszp/express/dist/middlewares/createContext.test.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/hasRoles.js +3 -5
- package/node_modules/@alanszp/express/dist/middlewares/hasRoles.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/jsonBodyParser.js +3 -4
- package/node_modules/@alanszp/express/dist/middlewares/jsonBodyParser.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/returnInternalServerError.js +1 -2
- package/node_modules/@alanszp/express/dist/middlewares/returnInternalServerError.js.map +1 -1
- package/node_modules/@alanszp/express/dist/middlewares/returnNotFound.js +2 -3
- package/node_modules/@alanszp/express/dist/middlewares/returnNotFound.js.map +1 -1
- package/node_modules/@alanszp/express/dist/test/mocks/jwtUserMocks.js +7 -6
- package/node_modules/@alanszp/express/dist/test/mocks/jwtUserMocks.js.map +1 -1
- package/node_modules/@alanszp/express/package.json +7 -7
- package/node_modules/@alanszp/express/src/helpers/renderErrorJson.ts +29 -0
- package/node_modules/@alanszp/express/src/index.ts +0 -1
- package/node_modules/@alanszp/express/src/middlewares/authedForOrg.ts +3 -4
- package/node_modules/@alanszp/express/src/middlewares/authenticateUser.ts +18 -18
- package/node_modules/@alanszp/express/src/middlewares/createContext.test.ts +1 -1
- package/node_modules/@alanszp/express/src/middlewares/createContext.ts +1 -1
- package/node_modules/@alanszp/express/src/middlewares/hasRoles.ts +3 -5
- package/node_modules/@alanszp/express/src/middlewares/jsonBodyParser.ts +3 -4
- package/node_modules/@alanszp/express/src/middlewares/returnInternalServerError.ts +1 -2
- package/node_modules/@alanszp/express/src/middlewares/returnNotFound.ts +2 -3
- package/node_modules/@alanszp/express/src/test/mocks/jwtUserMocks.ts +6 -6
- package/node_modules/@alanszp/jwt/dist/JWTUser.d.ts +31 -0
- package/node_modules/@alanszp/jwt/dist/JWTUser.js +62 -0
- package/node_modules/@alanszp/jwt/dist/JWTUser.js.map +1 -0
- package/node_modules/@alanszp/jwt/dist/index.d.ts +1 -0
- package/node_modules/@alanszp/jwt/dist/index.js +1 -0
- package/node_modules/@alanszp/jwt/dist/index.js.map +1 -1
- package/node_modules/@alanszp/jwt/dist/jwt.d.ts +2 -3
- package/node_modules/@alanszp/jwt/dist/jwt.js +4 -26
- package/node_modules/@alanszp/jwt/dist/jwt.js.map +1 -1
- package/node_modules/@alanszp/jwt/dist/types.d.ts +3 -3
- package/node_modules/@alanszp/jwt/package.json +3 -2
- package/node_modules/@alanszp/jwt/src/JWTUser.ts +85 -0
- package/node_modules/@alanszp/jwt/src/index.ts +1 -0
- package/node_modules/@alanszp/jwt/src/jwt.ts +4 -29
- package/node_modules/@alanszp/jwt/src/types.ts +3 -3
- package/node_modules/@alanszp/logger/package.json +3 -2
- package/package.json +7 -6
- package/src/commonErrorsHandler.ts +35 -16
- package/node_modules/@alanszp/errors/dist/errors/BaseError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/RenderableError.d.ts +0 -6
- package/node_modules/@alanszp/errors/dist/errors/RenderableError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/BadRequestError.d.ts +0 -8
- package/node_modules/@alanszp/errors/dist/errors/http/BadRequestError.js +0 -20
- package/node_modules/@alanszp/errors/dist/errors/http/BadRequestError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/HttpError.d.ts +0 -8
- package/node_modules/@alanszp/errors/dist/errors/http/HttpError.js +0 -18
- package/node_modules/@alanszp/errors/dist/errors/http/HttpError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/InternalServerError.d.ts +0 -8
- package/node_modules/@alanszp/errors/dist/errors/http/InternalServerError.js +0 -32
- package/node_modules/@alanszp/errors/dist/errors/http/InternalServerError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/NotFoundError.d.ts +0 -4
- package/node_modules/@alanszp/errors/dist/errors/http/NotFoundError.js +0 -11
- package/node_modules/@alanszp/errors/dist/errors/http/NotFoundError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/UnauthorizedError.d.ts +0 -8
- package/node_modules/@alanszp/errors/dist/errors/http/UnauthorizedError.js +0 -20
- package/node_modules/@alanszp/errors/dist/errors/http/UnauthorizedError.js.map +0 -1
- package/node_modules/@alanszp/errors/dist/errors/http/index.d.ts +0 -5
- package/node_modules/@alanszp/errors/dist/errors/http/index.js.map +0 -1
- package/node_modules/@alanszp/errors/src/errors/RenderableError.ts +0 -7
- package/node_modules/@alanszp/errors/src/errors/http/BadRequestError.ts +0 -21
- package/node_modules/@alanszp/errors/src/errors/http/HttpError.ts +0 -19
- package/node_modules/@alanszp/errors/src/errors/http/NotFoundError.ts +0 -7
- package/node_modules/@alanszp/errors/src/errors/http/UnauthorizedError.ts +0 -21
- package/node_modules/@alanszp/errors/src/errors/http/index.ts +0 -5
- package/node_modules/@alanszp/express/dist/helpers/appIdentifier.js.map +0 -1
- package/node_modules/@alanszp/express/dist/views/errorView.d.ts +0 -2
- package/node_modules/@alanszp/express/dist/views/errorView.js +0 -14
- package/node_modules/@alanszp/express/dist/views/errorView.js.map +0 -1
- package/node_modules/@alanszp/express/src/helpers/appIdentifier.ts +0 -5
- package/node_modules/@alanszp/express/src/views/errorView.ts +0 -11
- /package/node_modules/@alanszp/errors/dist/{errors/BaseError.d.ts → BaseError.d.ts} +0 -0
- /package/node_modules/@alanszp/errors/dist/{errors/BaseError.js → BaseError.js} +0 -0
- /package/node_modules/@alanszp/{express/dist/helpers → errors/node_modules/@alanszp/core/dist/app}/appIdentifier.d.ts +0 -0
- /package/node_modules/@alanszp/{express/dist/helpers → errors/node_modules/@alanszp/core/dist/app}/appIdentifier.js +0 -0
- /package/node_modules/@alanszp/errors/src/{errors/BaseError.ts → BaseError.ts} +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Paginable<Validated extends boolean = false> {
|
|
2
|
+
pageSize: Validated extends true ? number : number | string;
|
|
3
|
+
page: Validated extends true ? number : number | string;
|
|
4
|
+
}
|
|
5
|
+
export declare function getPageObject<T extends Paginable<true>>(object: T): {
|
|
6
|
+
skip: number;
|
|
7
|
+
take: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Assigns the page and pageSize keys to the target object
|
|
11
|
+
* @param target Paginable Input
|
|
12
|
+
* @param source Paginable Source
|
|
13
|
+
*/
|
|
14
|
+
export declare function assignPaginableKeys<T extends Paginable<false>, K extends Partial<Paginable<false>>>(target: T, source: K): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assignPaginableKeys = exports.getPageObject = void 0;
|
|
4
|
+
function getPageObject(object) {
|
|
5
|
+
return {
|
|
6
|
+
skip: (object.page - 1) * object.pageSize,
|
|
7
|
+
take: object.pageSize,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
exports.getPageObject = getPageObject;
|
|
11
|
+
/**
|
|
12
|
+
* Assigns the page and pageSize keys to the target object
|
|
13
|
+
* @param target Paginable Input
|
|
14
|
+
* @param source Paginable Source
|
|
15
|
+
*/
|
|
16
|
+
function assignPaginableKeys(target, source) {
|
|
17
|
+
// Mind the || operator, it's on purpose to avoid the 0 value (cause falsy value)
|
|
18
|
+
target.page = Number.parseInt(source.page, 10) || 1;
|
|
19
|
+
target.pageSize = Number.parseInt(source.pageSize, 10) || 100;
|
|
20
|
+
}
|
|
21
|
+
exports.assignPaginableKeys = assignPaginableKeys;
|
|
22
|
+
//# sourceMappingURL=Paginable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Paginable.js","sourceRoot":"","sources":["../../src/lists/Paginable.ts"],"names":[],"mappings":";;;AAKA,SAAgB,aAAa,CAA4B,MAAS;IAChE,OAAO;QACL,IAAI,EAAE,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ;QACzC,IAAI,EAAE,MAAM,CAAC,QAAQ;KACtB,CAAC;AACJ,CAAC;AALD,sCAKC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAGjC,MAAS,EAAE,MAAS;IACpB,iFAAiF;IACjF,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAc,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAC9D,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAkB,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;AAC1E,CAAC;AAPD,kDAOC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ListResult"), exports);
|
|
18
|
+
__exportStar(require("./Orderable"), exports);
|
|
19
|
+
__exportStar(require("./Paginable"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lists/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,8CAA4B;AAC5B,8CAA4B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alanszp/core",
|
|
3
|
+
"version": "11.0.0",
|
|
4
|
+
"description": "Alan's core TS/JS lib.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"files": [
|
|
9
|
+
"**/*"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"compile": "rm -rf ./dist && tsc --declaration",
|
|
16
|
+
"compile-watch": "tsc -w",
|
|
17
|
+
"build": "yarn run compile",
|
|
18
|
+
"prepack": "yarn run build",
|
|
19
|
+
"yalc-publish": "yarn run yalc publish"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^20.11.17"
|
|
23
|
+
},
|
|
24
|
+
"gitHead": "60b62fa2fff34ef094ea9af69c2bed2373c70f64"
|
|
25
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": "src",
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"target": "es6",
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
|
|
11
|
+
"alwaysStrict": true,
|
|
12
|
+
"strictNullChecks": true
|
|
13
|
+
},
|
|
14
|
+
"exclude": ["node_modules"]
|
|
15
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanszp/errors",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Alan's basic errors classes.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -22,5 +22,10 @@
|
|
|
22
22
|
"@types/node": "^20.11.17",
|
|
23
23
|
"ts-node": "^10.0.0",
|
|
24
24
|
"typescript": "^4.3.4"
|
|
25
|
-
}
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@alanszp/core": "^12.0.0",
|
|
28
|
+
"lodash": "^4.17.21"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "085a76a387bc0e272e09e9cb1b6f48f814512940"
|
|
26
31
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { HttpRenderableError } from "./HttpRenderableError";
|
|
2
|
+
import { RenderableContext, RenderableError } from "./RenderableError";
|
|
3
3
|
|
|
4
|
-
export class InternalServerError extends
|
|
4
|
+
export class InternalServerError extends HttpRenderableError {
|
|
5
5
|
public error;
|
|
6
6
|
|
|
7
7
|
constructor(error?: unknown) {
|
|
8
|
-
super();
|
|
8
|
+
super("Internal Server Error");
|
|
9
9
|
this.error = error;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
return
|
|
12
|
+
httpCode(): number {
|
|
13
|
+
return 500;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
public context(): RenderableContext {
|
|
@@ -22,12 +22,10 @@ export class InternalServerError extends HttpError {
|
|
|
22
22
|
error: {
|
|
23
23
|
name: this.error.name,
|
|
24
24
|
message: this.error.message,
|
|
25
|
-
|
|
26
|
-
context: this.error.context,
|
|
27
|
-
renderMessage: this.error.renderMessage,
|
|
28
|
-
stack: this.error.stack,
|
|
25
|
+
...(this.error instanceof RenderableError ? this.error.toView() : {}),
|
|
29
26
|
status: this.error.status,
|
|
30
27
|
signal: this.error.signal,
|
|
28
|
+
stack: this.error.stack,
|
|
31
29
|
},
|
|
32
30
|
};
|
|
33
31
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { snakeCase } from "lodash";
|
|
2
|
+
import { appIdentifier } from "@alanszp/core";
|
|
3
|
+
import { BaseError } from "./BaseError";
|
|
4
|
+
|
|
5
|
+
export type RenderableContext = Record<string, unknown>;
|
|
6
|
+
|
|
7
|
+
export interface RenderableView {
|
|
8
|
+
code: string;
|
|
9
|
+
message: string;
|
|
10
|
+
context: RenderableContext;
|
|
11
|
+
origin: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export abstract class RenderableError extends BaseError {
|
|
15
|
+
constructor(renderMessage: string) {
|
|
16
|
+
super(renderMessage);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
code(): string {
|
|
20
|
+
return snakeCase(this.message);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
renderMessage(): string {
|
|
24
|
+
return this.message;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
toView(): Record<string, unknown> {
|
|
28
|
+
return {
|
|
29
|
+
code: this.code(),
|
|
30
|
+
message: this.renderMessage(),
|
|
31
|
+
context: this.context(),
|
|
32
|
+
origin: appIdentifier(),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
abstract context(): RenderableContext;
|
|
37
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
1
|
+
export * from "./BaseError";
|
|
2
|
+
export * from "./RenderableError";
|
|
3
|
+
export * from "./HttpRenderableError";
|
|
4
|
+
export * from "./InternalServerError";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.render400Error = exports.render404Error = exports.render401Error = void 0;
|
|
4
|
+
const core_1 = require("@alanszp/core");
|
|
5
|
+
function render401Error(requiredChecks) {
|
|
6
|
+
return {
|
|
7
|
+
code: "unauthorized_error",
|
|
8
|
+
message: "Unauthorized Error",
|
|
9
|
+
context: { requiredChecks },
|
|
10
|
+
origin: (0, core_1.appIdentifier)(),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.render401Error = render401Error;
|
|
14
|
+
function render404Error() {
|
|
15
|
+
return {
|
|
16
|
+
code: "not_found",
|
|
17
|
+
message: "Not Found",
|
|
18
|
+
context: {},
|
|
19
|
+
origin: (0, core_1.appIdentifier)(),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.render404Error = render404Error;
|
|
23
|
+
function render400Error(message) {
|
|
24
|
+
return {
|
|
25
|
+
code: "bad_request",
|
|
26
|
+
message,
|
|
27
|
+
context: {},
|
|
28
|
+
origin: (0, core_1.appIdentifier)(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.render400Error = render400Error;
|
|
32
|
+
//# sourceMappingURL=renderErrorJson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderErrorJson.js","sourceRoot":"","sources":["../../src/helpers/renderErrorJson.ts"],"names":[],"mappings":";;;AAAA,wCAA8C;AAG9C,SAAgB,cAAc,CAAC,cAAwB;IACrD,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,oBAAoB;QAC7B,OAAO,EAAE,EAAE,cAAc,EAAE;QAC3B,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAPD,wCAOC;AAED,SAAgB,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,WAAW;QACpB,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAPD,wCAOC;AAED,SAAgB,cAAc,CAAC,OAAe;IAC5C,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,OAAO;QACP,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,IAAA,oBAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAPD,wCAOC"}
|
|
@@ -10,7 +10,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./views/errorView"), exports);
|
|
14
13
|
__exportStar(require("./types/AuthMethod"), exports);
|
|
15
14
|
__exportStar(require("./middlewares/auditLog"), exports);
|
|
16
15
|
__exportStar(require("./middlewares/accessLogger"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAmC;AACnC,yDAAuC;AACvC,6DAA2C;AAC3C,6DAA2C;AAC3C,8DAA4C;AAC5C,iEAA+C;AAC/C,0EAAwD;AACxD,+DAA6C;AAC7C,+DAA6C;AAC7C,yDAAuC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.authForOrg = void 0;
|
|
4
|
-
const errors_1 = require("@alanszp/errors");
|
|
5
|
-
const errorView_1 = require("../views/errorView");
|
|
6
4
|
const getRequestLogger_1 = require("../helpers/getRequestLogger");
|
|
5
|
+
const renderErrorJson_1 = require("../helpers/renderErrorJson");
|
|
7
6
|
function response401(res) {
|
|
8
|
-
res.status(401).json((0,
|
|
7
|
+
res.status(401).json((0, renderErrorJson_1.render401Error)(["jwt"]));
|
|
9
8
|
}
|
|
10
9
|
function authForOrg(req, res, next) {
|
|
11
10
|
var _a, _b, _c;
|
|
@@ -39,7 +38,7 @@ function authForOrg(req, res, next) {
|
|
|
39
38
|
logger.info("middleware.authForOrg.error.noOrganization", {
|
|
40
39
|
error,
|
|
41
40
|
});
|
|
42
|
-
res.status(404).json((0,
|
|
41
|
+
res.status(404).json((0, renderErrorJson_1.render404Error)());
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
exports.authForOrg = authForOrg;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authedForOrg.js","sourceRoot":"","sources":["../../src/middlewares/authedForOrg.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"authedForOrg.js","sourceRoot":"","sources":["../../src/middlewares/authedForOrg.ts"],"names":[],"mappings":";;;AACA,kEAA+D;AAE/D,gEAA4E;AAE5E,SAAS,WAAW,CAAC,GAAa;IAChC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,EAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,SAAgB,UAAU,CACxB,GAAmB,EACnB,GAAa,EACb,IAAkB;;IAElB,MAAM,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;IACpC,MAAM,MAAM,GAAG,IAAA,mCAAgB,EAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC;IAClE,IAAI;QACF,IAAI,CAAC,YAAY,EAAE;YACjB,MAAM,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;YACjE,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;SACzB;QAED,IAAI,CAAC,CAAA,MAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,OAAO,0CAAE,qBAAqB,CAAA,EAAE;YAChD,MAAM,CAAC,IAAI,CAAC,wCAAwC,EAAE;gBACpD,OAAO,EAAE,CAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,OAAO,KAAI,IAAI;aACtC,CAAC,CAAC;YACH,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;SACzB;QAED,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC;QACzD,IAAI,MAAM,KAAK,YAAY,EAAE;YAC3B,IAAI,MAAM,KAAK,MAAM,EAAE;gBACrB,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,qBAAqB,GAAG,YAAY,CAAC;gBACzD,OAAO,IAAI,EAAE,CAAC;aACf;YAED,MAAM,CAAC,IAAI,CAAC,sCAAsC,EAAE;gBAClD,MAAM;aACP,CAAC,CAAC;YACH,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;SACzB;QAED,OAAO,IAAI,EAAE,CAAC;KACf;IAAC,OAAO,KAAc,EAAE;QACvB,MAAM,CAAC,IAAI,CAAC,4CAA4C,EAAE;YACxD,KAAK;SACN,CAAC,CAAC;QACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,GAAE,CAAC,CAAC;KACxC;AACH,CAAC;AAxCD,gCAwCC"}
|
|
@@ -11,10 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createAuthContext = exports.AuthMethods = void 0;
|
|
13
13
|
const jwt_1 = require("@alanszp/jwt");
|
|
14
|
-
const errors_1 = require("@alanszp/errors");
|
|
15
|
-
const errorView_1 = require("../views/errorView");
|
|
16
14
|
const getRequestLogger_1 = require("../helpers/getRequestLogger");
|
|
17
15
|
const lodash_1 = require("lodash");
|
|
16
|
+
const renderErrorJson_1 = require("../helpers/renderErrorJson");
|
|
18
17
|
function parseAuthorizationHeader(authorization) {
|
|
19
18
|
if (!authorization)
|
|
20
19
|
return undefined;
|
|
@@ -54,14 +53,15 @@ const middlewareGetterByAuthType = {
|
|
|
54
53
|
user: "0",
|
|
55
54
|
org: "lara",
|
|
56
55
|
});
|
|
57
|
-
return Promise.resolve({
|
|
56
|
+
return Promise.resolve(new jwt_1.JWTUser({
|
|
58
57
|
id: "0",
|
|
59
58
|
employeeReference: "0",
|
|
60
59
|
organizationReference: "lara",
|
|
61
60
|
roles: [],
|
|
62
61
|
segmentReference: null,
|
|
63
|
-
permissions
|
|
64
|
-
|
|
62
|
+
// This will be changed in the near future to grab all permissions.
|
|
63
|
+
permissions: "MA==", // 0 in base64
|
|
64
|
+
}));
|
|
65
65
|
}
|
|
66
66
|
else {
|
|
67
67
|
return null;
|
|
@@ -86,11 +86,11 @@ function createAuthContext(options) {
|
|
|
86
86
|
if ((0, lodash_1.isEmpty)(successfulAuthAttempts)) {
|
|
87
87
|
res
|
|
88
88
|
.status(401)
|
|
89
|
-
.json((0,
|
|
89
|
+
.json((0, renderErrorJson_1.render401Error)([
|
|
90
90
|
authAttempts.includes(null)
|
|
91
91
|
? `Token invalid for methods ${authMethods}`
|
|
92
92
|
: `Token not set for methods ${authMethods}`,
|
|
93
|
-
]))
|
|
93
|
+
]));
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
96
|
const jwtUser = successfulAuthAttempts[0];
|
|
@@ -105,7 +105,7 @@ function createAuthContext(options) {
|
|
|
105
105
|
methods: AuthMethods,
|
|
106
106
|
error,
|
|
107
107
|
});
|
|
108
|
-
res.status(401).json((0,
|
|
108
|
+
res.status(401).json((0, renderErrorJson_1.render401Error)(authMethods));
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
111
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticateUser.js","sourceRoot":"","sources":["../../src/middlewares/authenticateUser.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAiE;
|
|
1
|
+
{"version":3,"file":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,CAAC;iBACnD;YACH,CAAC;SAAA,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA3DD,8CA2DC"}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createContext = void 0;
|
|
4
4
|
const cuid2_1 = require("@paralleldrive/cuid2");
|
|
5
|
-
const
|
|
5
|
+
const core_1 = require("@alanszp/core");
|
|
6
6
|
const lodash_1 = require("lodash");
|
|
7
7
|
function createContext(sharedContext, baseLogger, audit) {
|
|
8
8
|
return (req, res, next) => {
|
|
9
9
|
var _a, _b, _c, _d;
|
|
10
10
|
req.context = req.context || {};
|
|
11
11
|
const receivedChain = req.header("x-lifecycle-chain") || ((_b = (_a = req.body) === null || _a === void 0 ? void 0 : _a.detail) === null || _b === void 0 ? void 0 : _b.lch);
|
|
12
|
-
const lifecycleChain = (0, lodash_1.compact)([receivedChain, (0,
|
|
12
|
+
const lifecycleChain = (0, lodash_1.compact)([receivedChain, (0, core_1.appIdentifier)()]).join(",");
|
|
13
13
|
const lifecycleId = req.header("x-lifecycle-id") || ((_d = (_c = req.body) === null || _c === void 0 ? void 0 : _c.detail) === null || _d === void 0 ? void 0 : _d.lid) || (0, cuid2_1.createId)();
|
|
14
14
|
const contextId = (0, cuid2_1.createId)();
|
|
15
15
|
res.setHeader("x-lifecycle-id", lifecycleId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../src/middlewares/createContext.ts"],"names":[],"mappings":";;;AAAA,gDAAgD;AAIhD,
|
|
1
|
+
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../src/middlewares/createContext.ts"],"names":[],"mappings":";;;AAAA,gDAAgD;AAIhD,wCAA8C;AAG9C,mCAAiC;AAEjC,SAAgB,aAAa,CAC3B,aAA4B,EAC5B,UAAmB,EACnB,KAAY;IAEZ,OAAO,CAAC,GAAmB,EAAE,GAAa,EAAE,IAAkB,EAA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YACxB,WAAW;YACX,cAAc;YACd,SAAS;SACV,CACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAvCD,sCAuCC"}
|
|
@@ -5,7 +5,7 @@ const shared_context_1 = require("@alanszp/shared-context");
|
|
|
5
5
|
const logger_1 = require("@alanszp/logger");
|
|
6
6
|
const audit_1 = require("@alanszp/audit");
|
|
7
7
|
const expressMocks_1 = require("../test/mocks/expressMocks");
|
|
8
|
-
const
|
|
8
|
+
const core_1 = require("@alanszp/core");
|
|
9
9
|
jest.mock("@alanszp/shared-context");
|
|
10
10
|
const logger = (0, logger_1.createMockLogger)({});
|
|
11
11
|
const sharedContext = new shared_context_1.SharedContext();
|
|
@@ -24,7 +24,7 @@ describe("CreateContext", () => {
|
|
|
24
24
|
}), (0, expressMocks_1.mockResponse)(), (0, expressMocks_1.mockNext)());
|
|
25
25
|
expect(sharedContext.run).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
|
26
26
|
lifecycleId,
|
|
27
|
-
lifecycleChain: `${lifecycleChain},${(0,
|
|
27
|
+
lifecycleChain: `${lifecycleChain},${(0, core_1.appIdentifier)()}`,
|
|
28
28
|
}));
|
|
29
29
|
});
|
|
30
30
|
});
|
|
@@ -42,7 +42,7 @@ describe("CreateContext", () => {
|
|
|
42
42
|
}), (0, expressMocks_1.mockResponse)(), (0, expressMocks_1.mockNext)());
|
|
43
43
|
expect(sharedContext.run).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
|
|
44
44
|
lifecycleId,
|
|
45
|
-
lifecycleChain: `${lifecycleChain},${(0,
|
|
45
|
+
lifecycleChain: `${lifecycleChain},${(0, core_1.appIdentifier)()}`,
|
|
46
46
|
}));
|
|
47
47
|
});
|
|
48
48
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContext.test.js","sourceRoot":"","sources":["../../src/middlewares/createContext.test.ts"],"names":[],"mappings":";;AAAA,mDAAgD;AAChD,4DAAwD;AACxD,4CAAmD;AACnD,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QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;QACnD,SAAS,CAAC,GAAG,EAAE;YACZ,8BAA2B,CAAC,SAAS,EAAE,CAAC;QAC3C,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;YAC3D,MAAM,UAAU,GAAG,IAAA,6BAAa,EAC9B,aAAa,EACb,MAAM,EACN,IAAA,yBAAiB,EAAC,MAAM,CAAC,CAC1B,CAAC;YAEF,UAAU,CACR,IAAA,kCAAmB,EACjB,WAAW,EACX,EAAE,EACF;gBACE,MAAM,EAAE;oBACN,GAAG,EAAE,cAAc;oBACnB,GAAG,EAAE,WAAW;iBACjB;aACF,CACF,EACD,IAAA,2BAAY,GAAE,EACd,IAAA,uBAAQ,GAAE,CACX,CAAC;YAEF,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAC5C,MAAM,CAAC,QAAQ,EAAE,EACjB,MAAM,CAAC,gBAAgB,CAAC;gBACtB,WAAW;gBACX,cAAc,EAAE,GAAG,cAAc,IAAI,IAAA,oBAAa,GAAE,EAAE;aACvD,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hasRoles = void 0;
|
|
4
|
-
const
|
|
5
|
-
const errorView_1 = require("../views/errorView");
|
|
6
|
-
const jwt_1 = require("@alanszp/jwt");
|
|
4
|
+
const renderErrorJson_1 = require("../helpers/renderErrorJson");
|
|
7
5
|
function response401(res) {
|
|
8
|
-
res.status(401).json((0,
|
|
6
|
+
res.status(401).json((0, renderErrorJson_1.render401Error)(["permissions"]));
|
|
9
7
|
}
|
|
10
8
|
function hasRoles(roles) {
|
|
11
9
|
return (req, res, next) => {
|
|
@@ -13,7 +11,7 @@ function hasRoles(roles) {
|
|
|
13
11
|
if (!jwtUser) {
|
|
14
12
|
return response401(res);
|
|
15
13
|
}
|
|
16
|
-
if (
|
|
14
|
+
if (jwtUser.hasRoles(roles)) {
|
|
17
15
|
return next();
|
|
18
16
|
}
|
|
19
17
|
response401(res);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hasRoles.js","sourceRoot":"","sources":["../../src/middlewares/hasRoles.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"hasRoles.js","sourceRoot":"","sources":["../../src/middlewares/hasRoles.ts"],"names":[],"mappings":";;;AAEA,gEAA4D;AAE5D,SAAS,WAAW,CAAC,GAAa;IAChC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,EAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,SAAgB,QAAQ,CACtB,KAAwB;IAExB,OAAO,CAAC,GAAmB,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QAChE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;SACzB;QAED,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YAC3B,OAAO,IAAI,EAAE,CAAC;SACf;QAED,WAAW,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC;AAfD,4BAeC"}
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jsonBodyParser = void 0;
|
|
4
4
|
const body_parser_1 = require("body-parser");
|
|
5
|
-
const
|
|
6
|
-
const errorView_1 = require("../views/errorView");
|
|
5
|
+
const renderErrorJson_1 = require("../helpers/renderErrorJson");
|
|
7
6
|
function jsonBodyParser(options) {
|
|
8
7
|
const bodyParser = (0, body_parser_1.json)(Object.assign({ limit: "1mb" }, options));
|
|
9
8
|
return function jsonBodyParserMiddleware(req, res, next) {
|
|
@@ -11,11 +10,11 @@ function jsonBodyParser(options) {
|
|
|
11
10
|
bodyParser(req, res, (error) => {
|
|
12
11
|
if (!error)
|
|
13
12
|
return next();
|
|
14
|
-
res.status(400).json((0,
|
|
13
|
+
res.status(400).json((0, renderErrorJson_1.render400Error)("Malformed JSON"));
|
|
15
14
|
});
|
|
16
15
|
}
|
|
17
16
|
catch (error) {
|
|
18
|
-
res.status(400).json((0,
|
|
17
|
+
res.status(400).json((0, renderErrorJson_1.render400Error)("Malformed JSON"));
|
|
19
18
|
}
|
|
20
19
|
};
|
|
21
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonBodyParser.js","sourceRoot":"","sources":["../../src/middlewares/jsonBodyParser.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;
|
|
1
|
+
{"version":3,"file":"jsonBodyParser.js","sourceRoot":"","sources":["../../src/middlewares/jsonBodyParser.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAGhD,gEAA4D;AAE5D,SAAgB,cAAc,CAAC,OAAqB;IAClD,MAAM,UAAU,GAAG,IAAA,kBAAI,kBAAG,KAAK,EAAE,KAAK,IAAK,OAAO,EAAG,CAAC;IACtD,OAAO,SAAS,wBAAwB,CACtC,GAAmB,EACnB,GAAa,EACb,IAAkB;QAElB,IAAI;YACF,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,KAAe,EAAE,EAAE;gBACvC,IAAI,CAAC,KAAK;oBAAE,OAAO,IAAI,EAAE,CAAC;gBAC1B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,EAAC,gBAAgB,CAAC,CAAC,CAAC;YACzD,CAAC,CAAC,CAAC;SACJ;QAAC,OAAO,KAAc,EAAE;YACvB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,EAAC,gBAAgB,CAAC,CAAC,CAAC;SACxD;IACH,CAAC,CAAC;AACJ,CAAC;AAhBD,wCAgBC"}
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.returnInternalServerError = void 0;
|
|
4
4
|
const errors_1 = require("@alanszp/errors");
|
|
5
|
-
const errorView_1 = require("../views/errorView");
|
|
6
5
|
const returnInternalServerError = (getLogger) => (error, req, res, _next) => {
|
|
7
|
-
res.status(500).json(
|
|
6
|
+
res.status(500).json(new errors_1.InternalServerError(error).toView());
|
|
8
7
|
getLogger().error("error_to_client", { error });
|
|
9
8
|
};
|
|
10
9
|
exports.returnInternalServerError = returnInternalServerError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"returnInternalServerError.js","sourceRoot":"","sources":["../../src/middlewares/returnInternalServerError.ts"],"names":[],"mappings":";;;AACA,4CAAsD;
|
|
1
|
+
{"version":3,"file":"returnInternalServerError.js","sourceRoot":"","sources":["../../src/middlewares/returnInternalServerError.ts"],"names":[],"mappings":";;;AACA,4CAAsD;AAQ/C,MAAM,yBAAyB,GACpC,CAAC,SAAwB,EAAE,EAAE,CAC7B,CAAC,KAAc,EAAE,GAAmB,EAAE,GAAa,EAAE,KAAmB,EAAE,EAAE;IAC1E,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,4BAAmB,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9D,SAAS,EAAE,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAClD,CAAC,CAAC;AALS,QAAA,yBAAyB,6BAKlC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.returnNotFound = void 0;
|
|
4
|
-
const
|
|
5
|
-
const errorView_1 = require("../views/errorView");
|
|
4
|
+
const renderErrorJson_1 = require("../helpers/renderErrorJson");
|
|
6
5
|
function returnNotFound(_req, res, _next) {
|
|
7
|
-
res.status(404).json((0,
|
|
6
|
+
res.status(404).json((0, renderErrorJson_1.render404Error)());
|
|
8
7
|
}
|
|
9
8
|
exports.returnNotFound = returnNotFound;
|
|
10
9
|
//# sourceMappingURL=returnNotFound.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"returnNotFound.js","sourceRoot":"","sources":["../../src/middlewares/returnNotFound.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"returnNotFound.js","sourceRoot":"","sources":["../../src/middlewares/returnNotFound.ts"],"names":[],"mappings":";;;AAEA,gEAA4D;AAE5D,SAAgB,cAAc,CAC5B,IAAoB,EACpB,GAAa,EACb,KAAmB;IAEnB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,GAAE,CAAC,CAAC;AACzC,CAAC;AAND,wCAMC"}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.laraJwtUserMock = exports.userJwtUserMock = void 0;
|
|
4
|
-
|
|
4
|
+
const jwt_1 = require("@alanszp/jwt");
|
|
5
|
+
exports.userJwtUserMock = new jwt_1.JWTUser({
|
|
5
6
|
id: "1",
|
|
6
7
|
employeeReference: "1",
|
|
7
8
|
organizationReference: "test",
|
|
8
9
|
roles: [],
|
|
9
|
-
permissions:
|
|
10
|
+
permissions: "MA==",
|
|
10
11
|
segmentReference: null,
|
|
11
|
-
};
|
|
12
|
-
exports.laraJwtUserMock = {
|
|
12
|
+
});
|
|
13
|
+
exports.laraJwtUserMock = new jwt_1.JWTUser({
|
|
13
14
|
id: "0",
|
|
14
15
|
employeeReference: "0",
|
|
15
16
|
organizationReference: "lara",
|
|
16
17
|
roles: [],
|
|
17
|
-
permissions:
|
|
18
|
+
permissions: "MA==",
|
|
18
19
|
segmentReference: null,
|
|
19
|
-
};
|
|
20
|
+
});
|
|
20
21
|
//# sourceMappingURL=jwtUserMocks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwtUserMocks.js","sourceRoot":"","sources":["../../../src/test/mocks/jwtUserMocks.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"jwtUserMocks.js","sourceRoot":"","sources":["../../../src/test/mocks/jwtUserMocks.ts"],"names":[],"mappings":";;;AAAA,sCAAuC;AAE1B,QAAA,eAAe,GAAY,IAAI,aAAO,CAAC;IAClD,EAAE,EAAE,GAAG;IACP,iBAAiB,EAAE,GAAG;IACtB,qBAAqB,EAAE,MAAM;IAC7B,KAAK,EAAE,EAAE;IACT,WAAW,EAAE,MAAM;IACnB,gBAAgB,EAAE,IAAI;CACvB,CAAC,CAAC;AAEU,QAAA,eAAe,GAAY,IAAI,aAAO,CAAC;IAClD,EAAE,EAAE,GAAG;IACP,iBAAiB,EAAE,GAAG;IACtB,qBAAqB,EAAE,MAAM;IAC7B,KAAK,EAAE,EAAE;IACT,WAAW,EAAE,MAAM;IACnB,gBAAgB,EAAE,IAAI;CACvB,CAAC,CAAC"}
|