@alanszp/express-common-fn 11.0.0 → 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.
Files changed (139) hide show
  1. package/dist/commonErrorsHandler.js +29 -14
  2. package/dist/commonErrorsHandler.js.map +1 -1
  3. package/node_modules/@alanszp/audit/dist/errors/AuditError.d.ts +2 -2
  4. package/node_modules/@alanszp/audit/dist/errors/AuditError.js +1 -1
  5. package/node_modules/@alanszp/audit/dist/errors/AuditError.js.map +1 -1
  6. package/node_modules/@alanszp/audit/dist/errors/MissingAuditFieldsError.d.ts +3 -3
  7. package/node_modules/@alanszp/audit/dist/errors/MissingAuditFieldsError.js +2 -2
  8. package/node_modules/@alanszp/audit/dist/errors/MissingAuditFieldsError.js.map +1 -1
  9. package/node_modules/@alanszp/audit/package.json +4 -4
  10. package/node_modules/@alanszp/audit/src/errors/AuditError.ts +2 -2
  11. package/node_modules/@alanszp/audit/src/errors/MissingAuditFieldsError.ts +4 -7
  12. package/node_modules/@alanszp/errors/dist/BaseError.js.map +1 -0
  13. package/node_modules/@alanszp/errors/dist/HttpRenderableError.d.ts +4 -0
  14. package/node_modules/@alanszp/errors/dist/HttpRenderableError.js +8 -0
  15. package/node_modules/@alanszp/errors/dist/HttpRenderableError.js.map +1 -0
  16. package/node_modules/@alanszp/errors/dist/InternalServerError.d.ts +8 -0
  17. package/node_modules/@alanszp/errors/dist/InternalServerError.js +24 -0
  18. package/node_modules/@alanszp/errors/dist/InternalServerError.js.map +1 -0
  19. package/node_modules/@alanszp/errors/dist/RenderableError.d.ts +15 -0
  20. package/node_modules/@alanszp/errors/dist/RenderableError.js +27 -0
  21. package/node_modules/@alanszp/errors/dist/RenderableError.js.map +1 -0
  22. package/node_modules/@alanszp/errors/dist/index.d.ts +4 -3
  23. package/node_modules/@alanszp/errors/dist/index.js +4 -3
  24. package/node_modules/@alanszp/errors/dist/index.js.map +1 -1
  25. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/.gitignore +3 -0
  26. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/.npmignore +3 -0
  27. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/LICENSE +21 -0
  28. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/app/appIdentifier.js.map +1 -0
  29. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/app/index.d.ts +1 -0
  30. package/node_modules/@alanszp/errors/{dist/errors/http → node_modules/@alanszp/core/dist/app}/index.js +6 -6
  31. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/app/index.js.map +1 -0
  32. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/assignKey.d.ts +2 -0
  33. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/assignKey.js +20 -0
  34. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/assignKey.js.map +1 -0
  35. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/index.d.ts +2 -0
  36. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/index.js +19 -0
  37. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/index.js.map +1 -0
  38. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/keepOrUpdate.d.ts +3 -0
  39. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js +26 -0
  40. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/keepOrUpdate.js.map +1 -0
  41. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/types.d.ts +6 -0
  42. package/node_modules/@alanszp/errors/{dist/errors/RenderableError.js → node_modules/@alanszp/core/dist/editable/types.js} +1 -1
  43. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/editable/types.js.map +1 -0
  44. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/index.d.ts +4 -0
  45. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/index.js +21 -0
  46. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/index.js.map +1 -0
  47. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/ListResult.d.ts +7 -0
  48. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/ListResult.js +8 -0
  49. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/ListResult.js.map +1 -0
  50. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Orderable.d.ts +11 -0
  51. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Orderable.js +13 -0
  52. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Orderable.js.map +1 -0
  53. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Paginable.d.ts +14 -0
  54. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Paginable.js +22 -0
  55. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/Paginable.js.map +1 -0
  56. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/index.d.ts +3 -0
  57. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/index.js +20 -0
  58. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/dist/lists/index.js.map +1 -0
  59. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/package.json +25 -0
  60. package/node_modules/@alanszp/errors/node_modules/@alanszp/core/tsconfig.json +15 -0
  61. package/node_modules/@alanszp/errors/package.json +6 -2
  62. package/node_modules/@alanszp/errors/src/HttpRenderableError.ts +5 -0
  63. package/node_modules/@alanszp/errors/src/{errors/http/InternalServerError.ts → InternalServerError.ts} +8 -10
  64. package/node_modules/@alanszp/errors/src/RenderableError.ts +37 -0
  65. package/node_modules/@alanszp/errors/src/index.ts +4 -3
  66. package/node_modules/@alanszp/express/dist/helpers/renderErrorJson.d.ts +4 -0
  67. package/node_modules/@alanszp/express/dist/helpers/renderErrorJson.js +32 -0
  68. package/node_modules/@alanszp/express/dist/helpers/renderErrorJson.js.map +1 -0
  69. package/node_modules/@alanszp/express/dist/index.d.ts +0 -1
  70. package/node_modules/@alanszp/express/dist/index.js +0 -1
  71. package/node_modules/@alanszp/express/dist/index.js.map +1 -1
  72. package/node_modules/@alanszp/express/dist/middlewares/authedForOrg.js +3 -4
  73. package/node_modules/@alanszp/express/dist/middlewares/authedForOrg.js.map +1 -1
  74. package/node_modules/@alanszp/express/dist/middlewares/authenticateUser.js +4 -5
  75. package/node_modules/@alanszp/express/dist/middlewares/authenticateUser.js.map +1 -1
  76. package/node_modules/@alanszp/express/dist/middlewares/createContext.js +2 -2
  77. package/node_modules/@alanszp/express/dist/middlewares/createContext.js.map +1 -1
  78. package/node_modules/@alanszp/express/dist/middlewares/createContext.test.js +3 -3
  79. package/node_modules/@alanszp/express/dist/middlewares/createContext.test.js.map +1 -1
  80. package/node_modules/@alanszp/express/dist/middlewares/hasRoles.js +2 -3
  81. package/node_modules/@alanszp/express/dist/middlewares/hasRoles.js.map +1 -1
  82. package/node_modules/@alanszp/express/dist/middlewares/jsonBodyParser.js +3 -4
  83. package/node_modules/@alanszp/express/dist/middlewares/jsonBodyParser.js.map +1 -1
  84. package/node_modules/@alanszp/express/dist/middlewares/returnInternalServerError.js +1 -2
  85. package/node_modules/@alanszp/express/dist/middlewares/returnInternalServerError.js.map +1 -1
  86. package/node_modules/@alanszp/express/dist/middlewares/returnNotFound.js +2 -3
  87. package/node_modules/@alanszp/express/dist/middlewares/returnNotFound.js.map +1 -1
  88. package/node_modules/@alanszp/express/package.json +7 -7
  89. package/node_modules/@alanszp/express/src/helpers/renderErrorJson.ts +29 -0
  90. package/node_modules/@alanszp/express/src/index.ts +0 -1
  91. package/node_modules/@alanszp/express/src/middlewares/authedForOrg.ts +3 -4
  92. package/node_modules/@alanszp/express/src/middlewares/authenticateUser.ts +7 -10
  93. package/node_modules/@alanszp/express/src/middlewares/createContext.test.ts +1 -1
  94. package/node_modules/@alanszp/express/src/middlewares/createContext.ts +1 -1
  95. package/node_modules/@alanszp/express/src/middlewares/hasRoles.ts +2 -3
  96. package/node_modules/@alanszp/express/src/middlewares/jsonBodyParser.ts +3 -4
  97. package/node_modules/@alanszp/express/src/middlewares/returnInternalServerError.ts +1 -2
  98. package/node_modules/@alanszp/express/src/middlewares/returnNotFound.ts +2 -3
  99. package/node_modules/@alanszp/jwt/package.json +2 -2
  100. package/node_modules/@alanszp/logger/package.json +2 -2
  101. package/package.json +7 -6
  102. package/src/commonErrorsHandler.ts +35 -16
  103. package/node_modules/@alanszp/errors/dist/errors/BaseError.js.map +0 -1
  104. package/node_modules/@alanszp/errors/dist/errors/RenderableError.d.ts +0 -6
  105. package/node_modules/@alanszp/errors/dist/errors/RenderableError.js.map +0 -1
  106. package/node_modules/@alanszp/errors/dist/errors/http/BadRequestError.d.ts +0 -8
  107. package/node_modules/@alanszp/errors/dist/errors/http/BadRequestError.js +0 -20
  108. package/node_modules/@alanszp/errors/dist/errors/http/BadRequestError.js.map +0 -1
  109. package/node_modules/@alanszp/errors/dist/errors/http/HttpError.d.ts +0 -8
  110. package/node_modules/@alanszp/errors/dist/errors/http/HttpError.js +0 -18
  111. package/node_modules/@alanszp/errors/dist/errors/http/HttpError.js.map +0 -1
  112. package/node_modules/@alanszp/errors/dist/errors/http/InternalServerError.d.ts +0 -8
  113. package/node_modules/@alanszp/errors/dist/errors/http/InternalServerError.js +0 -32
  114. package/node_modules/@alanszp/errors/dist/errors/http/InternalServerError.js.map +0 -1
  115. package/node_modules/@alanszp/errors/dist/errors/http/NotFoundError.d.ts +0 -4
  116. package/node_modules/@alanszp/errors/dist/errors/http/NotFoundError.js +0 -11
  117. package/node_modules/@alanszp/errors/dist/errors/http/NotFoundError.js.map +0 -1
  118. package/node_modules/@alanszp/errors/dist/errors/http/UnauthorizedError.d.ts +0 -8
  119. package/node_modules/@alanszp/errors/dist/errors/http/UnauthorizedError.js +0 -20
  120. package/node_modules/@alanszp/errors/dist/errors/http/UnauthorizedError.js.map +0 -1
  121. package/node_modules/@alanszp/errors/dist/errors/http/index.d.ts +0 -5
  122. package/node_modules/@alanszp/errors/dist/errors/http/index.js.map +0 -1
  123. package/node_modules/@alanszp/errors/src/errors/RenderableError.ts +0 -7
  124. package/node_modules/@alanszp/errors/src/errors/http/BadRequestError.ts +0 -21
  125. package/node_modules/@alanszp/errors/src/errors/http/HttpError.ts +0 -19
  126. package/node_modules/@alanszp/errors/src/errors/http/NotFoundError.ts +0 -7
  127. package/node_modules/@alanszp/errors/src/errors/http/UnauthorizedError.ts +0 -21
  128. package/node_modules/@alanszp/errors/src/errors/http/index.ts +0 -5
  129. package/node_modules/@alanszp/express/dist/helpers/appIdentifier.js.map +0 -1
  130. package/node_modules/@alanszp/express/dist/views/errorView.d.ts +0 -2
  131. package/node_modules/@alanszp/express/dist/views/errorView.js +0 -14
  132. package/node_modules/@alanszp/express/dist/views/errorView.js.map +0 -1
  133. package/node_modules/@alanszp/express/src/helpers/appIdentifier.ts +0 -5
  134. package/node_modules/@alanszp/express/src/views/errorView.ts +0 -11
  135. /package/node_modules/@alanszp/errors/dist/{errors/BaseError.d.ts → BaseError.d.ts} +0 -0
  136. /package/node_modules/@alanszp/errors/dist/{errors/BaseError.js → BaseError.js} +0 -0
  137. /package/node_modules/@alanszp/{express/dist/helpers → errors/node_modules/@alanszp/core/dist/app}/appIdentifier.d.ts +0 -0
  138. /package/node_modules/@alanszp/{express/dist/helpers → errors/node_modules/@alanszp/core/dist/app}/appIdentifier.js +0 -0
  139. /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,3 @@
1
+ export * from "./ListResult";
2
+ export * from "./Orderable";
3
+ export * from "./Paginable";
@@ -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": "11.0.0",
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",
@@ -23,5 +23,9 @@
23
23
  "ts-node": "^10.0.0",
24
24
  "typescript": "^4.3.4"
25
25
  },
26
- "gitHead": "60b62fa2fff34ef094ea9af69c2bed2373c70f64"
26
+ "dependencies": {
27
+ "@alanszp/core": "^12.0.0",
28
+ "lodash": "^4.17.21"
29
+ },
30
+ "gitHead": "085a76a387bc0e272e09e9cb1b6f48f814512940"
27
31
  }
@@ -0,0 +1,5 @@
1
+ import { RenderableError } from "./RenderableError";
2
+
3
+ export abstract class HttpRenderableError extends RenderableError {
4
+ abstract httpCode(): number;
5
+ }
@@ -1,16 +1,16 @@
1
- import { RenderableContext } from "../RenderableError";
2
- import { HttpError } from "./HttpError";
1
+ import { HttpRenderableError } from "./HttpRenderableError";
2
+ import { RenderableContext, RenderableError } from "./RenderableError";
3
3
 
4
- export class InternalServerError extends HttpError {
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
- public renderMessage(): string {
13
- return "Internal Server Error";
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
- code: this.error.code,
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 "./errors/BaseError";
2
- export * from "./errors/RenderableError";
3
- export * from "./errors/http";
1
+ export * from "./BaseError";
2
+ export * from "./RenderableError";
3
+ export * from "./HttpRenderableError";
4
+ export * from "./InternalServerError";
@@ -0,0 +1,4 @@
1
+ import { RenderableView } from "@alanszp/errors";
2
+ export declare function render401Error(requiredChecks: string[]): RenderableView;
3
+ export declare function render404Error(): RenderableView;
4
+ export declare function render400Error(message: string): RenderableView;
@@ -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"}
@@ -1,4 +1,3 @@
1
- export * from "./views/errorView";
2
1
  export * from "./types/AuthMethod";
3
2
  export * from "./middlewares/auditLog";
4
3
  export * from "./middlewares/accessLogger";
@@ -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,oDAAkC;AAClC,qDAAmC;AACnC,yDAAuC;AACvC,6DAA2C;AAC3C,6DAA2C;AAC3C,8DAA4C;AAC5C,iEAA+C;AAC/C,0EAAwD;AACxD,+DAA6C;AAC7C,+DAA6C;AAC7C,yDAAuC"}
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, errorView_1.errorView)(new errors_1.UnauthorizedError(["jwt"])));
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, errorView_1.errorView)(new errors_1.NotFoundError()));
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":";;;AAAA,4CAAmE;AACnE,kDAA+C;AAE/C,kEAA+D;AAG/D,SAAS,WAAW,CAAC,GAAa;IAChC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,qBAAS,EAAC,IAAI,0BAAiB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,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,CAA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C,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;
@@ -87,11 +86,11 @@ function createAuthContext(options) {
87
86
  if ((0, lodash_1.isEmpty)(successfulAuthAttempts)) {
88
87
  res
89
88
  .status(401)
90
- .json((0, errorView_1.errorView)(new errors_1.UnauthorizedError([
89
+ .json((0, renderErrorJson_1.render401Error)([
91
90
  authAttempts.includes(null)
92
91
  ? `Token invalid for methods ${authMethods}`
93
92
  : `Token not set for methods ${authMethods}`,
94
- ])));
93
+ ]));
95
94
  return;
96
95
  }
97
96
  const jwtUser = successfulAuthAttempts[0];
@@ -106,7 +105,7 @@ function createAuthContext(options) {
106
105
  methods: AuthMethods,
107
106
  error,
108
107
  });
109
- res.status(401).json((0, errorView_1.errorView)(new errors_1.UnauthorizedError(authMethods)));
108
+ res.status(401).json((0, renderErrorJson_1.render401Error)(authMethods));
110
109
  }
111
110
  });
112
111
  };
@@ -1 +1 @@
1
- {"version":3,"file":"authenticateUser.js","sourceRoot":"","sources":["../../src/middlewares/authenticateUser.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAiE;AACjE,4CAAoD;AACpD,kDAA+C;AAE/C,kEAA+D;AAG/D,mCAAgD;AAEhD,SAAS,wBAAwB,CAC/B,aAAiC;IAEjC,IAAI,CAAC,aAAa;QAAE,OAAO,SAAS,CAAC;IACrC,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEzD,IAAI,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC;IAE9D,OAAO,GAAG,CAAC;AACb,CAAC;AAED,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,0BAAW,CAAA;IACX,kCAAmB,CAAA;AACrB,CAAC,EAHW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAGtB;AA0BD,MAAM,0BAA0B,GAO5B;IACF,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CACjB,GAA8B,EAC9B,OAA4C,EAC5C,MAAe,EACf,EAAE;QACF,IAAI;YACF,IA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AAC,CAAC,6BAA6B,WAAW,EAAE;yBAC/C,CAAC,CACH,CAAC;wBACJ,OAAO;qBACR;oBAED,MAAM,OAAO,GAAY,sBAAsB,CAAC,CAAC,CAAC,CAAC;oBACnD,GAAG,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;oBAC9B,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAC5B,OAAO,CAAC,iBAAiB,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CACtD,CAAC;oBACF,IAAI,EAAE,CAAC;iBACR;gBAAC,OAAO,KAAc,EAAE;oBACvB,MAAM,CAAC,IAAI,CAAC,6BAA6B,EAAE;wBACzC,GAAG;wBACH,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,aAAa;wBAChC,OAAO,EAAE,WAAW;wBACpB,KAAK;qBACN,CAAC,CAAC;oBACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gCAAc,EAAC,WAAW,CAAC,CAAC,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 appIdentifier_1 = require("../helpers/appIdentifier");
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, appIdentifier_1.appIdentifier)()]).join(",");
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,4DAAyD;AAGzD,mCAAiC;AAEjC,SAAgB,aAAa,CAC3B,aAA4B,EAC5B,UAAmB,EACnB,KAAY;IAEZ,OAAO,CAAC,GAAmB,EAAE,GAAa,EAAE,IAAkB,EAAQ,EAAE;;QACtE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;QAEhC,MAAM,aAAa,GACjB,GAAG,CAAC,MAAM,CAAC,mBAAmB,CAAC,KAAI,MAAA,MAAA,GAAG,CAAC,IAAI,0CAAE,MAAM,0CAAE,GAAG,CAAA,CAAC;QAC3D,MAAM,cAAc,GAAG,IAAA,gBAAO,EAAC,CAAC,aAAa,EAAE,IAAA,6BAAa,GAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE3E,MAAM,WAAW,GACf,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,KAAI,MAAA,MAAA,GAAG,CAAC,IAAI,0CAAE,MAAM,0CAAE,GAAG,CAAA,IAAI,IAAA,gBAAQ,GAAE,CAAC;QAEtE,MAAM,SAAS,GAAG,IAAA,gBAAQ,GAAE,CAAC;QAE7B,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC;QAC7C,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;QAEzC,aAAa,CAAC,GAAG,CACf,CAAC,OAAO,EAAE,EAAE;YACV,GAAG,CAA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,MAAA,GAAG,CAAC,IAAI,0CAAE,MAAM,0CAAE,GAAG,CAAA,IAAI,IAAA,gBAAQ,GAAE,CAAC;QAEtE,MAAM,SAAS,GAAG,IAAA,gBAAQ,GAAE,CAAC;QAE7B,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC;QAC7C,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;QAEzC,aAAa,CAAC,GAAG,CACf,CAAC,OAAO,EAAE,EAAE;YACV,GAAG,CAAC,OAAO,CAAC,aAAa,GAAG,EAAE,CAAC;YAC/B,GAAG,CAAC,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;YAC9C,GAAG,CAAC,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;YACpD,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;YAC1C,GAAG,CAAC,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;YACjC,GAAG,CAAC,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAClC,IAAI,EAAE,CAAC;QACT,CAAC,EACD;YACE,MAAM,EAAE,UAAU;YAClB,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE;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 appIdentifier_1 = require("../helpers/appIdentifier");
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, appIdentifier_1.appIdentifier)()}`,
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, appIdentifier_1.appIdentifier)()}`,
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,0CAAmD;AACnD,6DAKoC;AACpC,4DAAyD;AACzD,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;AAErC,MAAM,MAAM,GAAG,IAAA,yBAAgB,EAAC,EAAE,CAAC,CAAC;AACpC,MAAM,aAAa,GAAG,IAAI,8BAAa,EAAE,CAAC;AAC1C,MAAM,WAAW,GAAG,KAAK,CAAC;AAC1B,MAAM,cAAc,GAAG,WAAW,CAAC;AAEnC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;QAC1C,SAAS,CAAC,GAAG,EAAE;YACZ,8BAA2B,CAAC,SAAS,EAAE,CAAC;QAC3C,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;YACrD,MAAM,UAAU,GAAG,IAAA,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AAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,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,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasRoles = void 0;
4
- const errors_1 = require("@alanszp/errors");
5
- const errorView_1 = require("../views/errorView");
4
+ const renderErrorJson_1 = require("../helpers/renderErrorJson");
6
5
  function response401(res) {
7
- res.status(401).json((0, errorView_1.errorView)(new errors_1.UnauthorizedError(["permissions"])));
6
+ res.status(401).json((0, renderErrorJson_1.render401Error)(["permissions"]));
8
7
  }
9
8
  function hasRoles(roles) {
10
9
  return (req, res, next) => {
@@ -1 +1 @@
1
- {"version":3,"file":"hasRoles.js","sourceRoot":"","sources":["../../src/middlewares/hasRoles.ts"],"names":[],"mappings":";;;AAAA,4CAAoD;AACpD,kDAA+C;AAI/C,SAAS,WAAW,CAAC,GAAa;IAChC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,qBAAS,EAAC,IAAI,0BAAiB,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1E,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"}
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 errors_1 = require("@alanszp/errors");
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, errorView_1.errorView)(new errors_1.BadRequestError("Malformed JSON")));
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, errorView_1.errorView)(new errors_1.BadRequestError("Malformed JSON")));
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;AAEhD,4CAAkD;AAClD,kDAA+C;AAG/C,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,qBAAS,EAAC,IAAI,wBAAe,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;YACzE,CAAC,CAAC,CAAC;SACJ;QAAC,OAAO,KAAc,EAAE;YACvB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,qBAAS,EAAC,IAAI,wBAAe,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;SACxE;IACH,CAAC,CAAC;AACJ,CAAC;AAhBD,wCAgBC"}
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((0, errorView_1.errorView)(new errors_1.InternalServerError(error)));
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;AACtD,kDAA+C;AAQxC,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,IAAA,qBAAS,EAAC,IAAI,4BAAmB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChE,SAAS,EAAE,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAClD,CAAC,CAAC;AALS,QAAA,yBAAyB,6BAKlC"}
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 errors_1 = require("@alanszp/errors");
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, errorView_1.errorView)(new errors_1.NotFoundError()));
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":";;;AACA,4CAAgD;AAChD,kDAA+C;AAG/C,SAAgB,cAAc,CAC5B,IAAoB,EACpB,GAAa,EACb,KAAmB;IAEnB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,qBAAS,EAAC,IAAI,sBAAa,EAAE,CAAC,CAAC,CAAC;AACvD,CAAC;AAND,wCAMC"}
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@alanszp/express",
3
- "version": "11.0.0",
3
+ "version": "12.0.0",
4
4
  "description": "Alan's express utils and middlewares.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -35,15 +35,15 @@
35
35
  "typescript": "^4.3.4"
36
36
  },
37
37
  "dependencies": {
38
- "@alanszp/audit": "^11.0.0",
39
- "@alanszp/errors": "^11.0.0",
40
- "@alanszp/jwt": "^11.0.0",
41
- "@alanszp/logger": "^11.0.0",
42
- "@alanszp/shared-context": "^11.0.0",
38
+ "@alanszp/audit": "^12.0.0",
39
+ "@alanszp/errors": "^12.0.0",
40
+ "@alanszp/jwt": "^12.0.0",
41
+ "@alanszp/logger": "^12.0.0",
42
+ "@alanszp/shared-context": "^12.0.0",
43
43
  "@babel/core": "^7.23.9",
44
44
  "@paralleldrive/cuid2": "^2.2.2",
45
45
  "body-parser": "^1.20.2",
46
46
  "lodash": "^4.17.21"
47
47
  },
48
- "gitHead": "60b62fa2fff34ef094ea9af69c2bed2373c70f64"
48
+ "gitHead": "085a76a387bc0e272e09e9cb1b6f48f814512940"
49
49
  }
@@ -0,0 +1,29 @@
1
+ import { appIdentifier } from "@alanszp/core";
2
+ import { RenderableView } from "@alanszp/errors";
3
+
4
+ export function render401Error(requiredChecks: string[]): RenderableView {
5
+ return {
6
+ code: "unauthorized_error",
7
+ message: "Unauthorized Error",
8
+ context: { requiredChecks },
9
+ origin: appIdentifier(),
10
+ };
11
+ }
12
+
13
+ export function render404Error(): RenderableView {
14
+ return {
15
+ code: "not_found",
16
+ message: "Not Found",
17
+ context: {},
18
+ origin: appIdentifier(),
19
+ };
20
+ }
21
+
22
+ export function render400Error(message: string): RenderableView {
23
+ return {
24
+ code: "bad_request",
25
+ message,
26
+ context: {},
27
+ origin: appIdentifier(),
28
+ };
29
+ }
@@ -1,4 +1,3 @@
1
- export * from "./views/errorView";
2
1
  export * from "./types/AuthMethod";
3
2
  export * from "./middlewares/auditLog";
4
3
  export * from "./middlewares/accessLogger";