@alanszp/express 11.0.0 → 12.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/helpers/renderErrorJson.d.ts +4 -0
  2. package/dist/helpers/renderErrorJson.js +32 -0
  3. package/dist/helpers/renderErrorJson.js.map +1 -0
  4. package/dist/index.d.ts +0 -1
  5. package/dist/index.js +0 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/middlewares/authedForOrg.js +3 -4
  8. package/dist/middlewares/authedForOrg.js.map +1 -1
  9. package/dist/middlewares/authenticateUser.js +4 -5
  10. package/dist/middlewares/authenticateUser.js.map +1 -1
  11. package/dist/middlewares/createContext.js +2 -2
  12. package/dist/middlewares/createContext.js.map +1 -1
  13. package/dist/middlewares/createContext.test.js +3 -3
  14. package/dist/middlewares/createContext.test.js.map +1 -1
  15. package/dist/middlewares/hasRoles.js +2 -3
  16. package/dist/middlewares/hasRoles.js.map +1 -1
  17. package/dist/middlewares/jsonBodyParser.js +3 -4
  18. package/dist/middlewares/jsonBodyParser.js.map +1 -1
  19. package/dist/middlewares/returnInternalServerError.js +1 -2
  20. package/dist/middlewares/returnInternalServerError.js.map +1 -1
  21. package/dist/middlewares/returnNotFound.js +2 -3
  22. package/dist/middlewares/returnNotFound.js.map +1 -1
  23. package/package.json +8 -7
  24. package/src/helpers/renderErrorJson.ts +29 -0
  25. package/src/index.ts +0 -1
  26. package/src/middlewares/authedForOrg.ts +3 -4
  27. package/src/middlewares/authenticateUser.ts +7 -10
  28. package/src/middlewares/createContext.test.ts +1 -1
  29. package/src/middlewares/createContext.ts +1 -1
  30. package/src/middlewares/hasRoles.ts +2 -3
  31. package/src/middlewares/jsonBodyParser.ts +3 -4
  32. package/src/middlewares/returnInternalServerError.ts +1 -2
  33. package/src/middlewares/returnNotFound.ts +2 -3
  34. package/dist/helpers/appIdentifier.d.ts +0 -1
  35. package/dist/helpers/appIdentifier.js +0 -10
  36. package/dist/helpers/appIdentifier.js.map +0 -1
  37. package/dist/views/errorView.d.ts +0 -2
  38. package/dist/views/errorView.js +0 -14
  39. package/dist/views/errorView.js.map +0 -1
  40. package/src/helpers/appIdentifier.ts +0 -5
  41. package/src/views/errorView.ts +0 -11
@@ -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"}
package/dist/index.d.ts CHANGED
@@ -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";
package/dist/index.js CHANGED
@@ -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);
package/dist/index.js.map CHANGED
@@ -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,IA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N,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,wBAAw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C;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,0CA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C,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,mDA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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,6BAAa,GAAE,EAAE;aACvD,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
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,wCAA8C;AAC9C,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,CA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C;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alanszp/express",
3
- "version": "11.0.0",
3
+ "version": "12.0.1",
4
4
  "description": "Alan's express utils and middlewares.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -20,9 +20,11 @@
20
20
  "yalc-publish": "yarn run yalc publish"
21
21
  },
22
22
  "peerDependencies": {
23
+ "@alanszp/errors": ">=12.0.0",
23
24
  "express": "^4.17.1"
24
25
  },
25
26
  "devDependencies": {
27
+ "@alanszp/errors": "^12.0.1",
26
28
  "@types/body-parser": "^1.19.1",
27
29
  "@types/express": "^4.17.12",
28
30
  "@types/jest": "^28.1.8",
@@ -35,15 +37,14 @@
35
37
  "typescript": "^4.3.4"
36
38
  },
37
39
  "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",
40
+ "@alanszp/audit": "^12.0.1",
41
+ "@alanszp/jwt": "^12.0.0",
42
+ "@alanszp/logger": "^12.0.0",
43
+ "@alanszp/shared-context": "^12.0.1",
43
44
  "@babel/core": "^7.23.9",
44
45
  "@paralleldrive/cuid2": "^2.2.2",
45
46
  "body-parser": "^1.20.2",
46
47
  "lodash": "^4.17.21"
47
48
  },
48
- "gitHead": "60b62fa2fff34ef094ea9af69c2bed2373c70f64"
49
+ "gitHead": "2320e554850aec120e0e8bc71c00a2197187af40"
49
50
  }
@@ -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
+ }
package/src/index.ts CHANGED
@@ -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";
@@ -1,11 +1,10 @@
1
- import { NotFoundError, UnauthorizedError } from "@alanszp/errors";
2
- import { errorView } from "../views/errorView";
3
1
  import { NextFunction, Response } from "express";
4
2
  import { getRequestLogger } from "../helpers/getRequestLogger";
5
3
  import { GenericRequest } from "../types/GenericRequest";
4
+ import { render401Error, render404Error } from "../helpers/renderErrorJson";
6
5
 
7
6
  function response401(res: Response): void {
8
- res.status(401).json(errorView(new UnauthorizedError(["jwt"])));
7
+ res.status(401).json(render401Error(["jwt"]));
9
8
  }
10
9
 
11
10
  export function authForOrg(
@@ -46,6 +45,6 @@ export function authForOrg(
46
45
  logger.info("middleware.authForOrg.error.noOrganization", {
47
46
  error,
48
47
  });
49
- res.status(404).json(errorView(new NotFoundError()));
48
+ res.status(404).json(render404Error());
50
49
  }
51
50
  }
@@ -1,11 +1,10 @@
1
1
  import { JWTUser, verifyJWT, VerifyOptions } from "@alanszp/jwt";
2
- import { UnauthorizedError } from "@alanszp/errors";
3
- import { errorView } from "../views/errorView";
4
2
  import { NextFunction, Response } from "express";
5
3
  import { getRequestLogger } from "../helpers/getRequestLogger";
6
4
  import { GenericRequest } from "../types/GenericRequest";
7
5
  import { ILogger } from "@alanszp/logger";
8
6
  import { compact, isEmpty, omit } from "lodash";
7
+ import { render401Error } from "../helpers/renderErrorJson";
9
8
 
10
9
  function parseAuthorizationHeader(
11
10
  authorization: string | undefined
@@ -143,13 +142,11 @@ export function createAuthContext<Options extends AuthOptions>(
143
142
  res
144
143
  .status(401)
145
144
  .json(
146
- errorView(
147
- new UnauthorizedError([
148
- authAttempts.includes(null)
149
- ? `Token invalid for methods ${authMethods}`
150
- : `Token not set for methods ${authMethods}`,
151
- ])
152
- )
145
+ render401Error([
146
+ authAttempts.includes(null)
147
+ ? `Token invalid for methods ${authMethods}`
148
+ : `Token not set for methods ${authMethods}`,
149
+ ])
153
150
  );
154
151
  return;
155
152
  }
@@ -167,7 +164,7 @@ export function createAuthContext<Options extends AuthOptions>(
167
164
  methods: AuthMethods,
168
165
  error,
169
166
  });
170
- res.status(401).json(errorView(new UnauthorizedError(authMethods)));
167
+ res.status(401).json(render401Error(authMethods));
171
168
  }
172
169
  };
173
170
  };
@@ -8,7 +8,7 @@ import {
8
8
  mockRequestWithBody,
9
9
  mockResponse,
10
10
  } from "../test/mocks/expressMocks";
11
- import { appIdentifier } from "../helpers/appIdentifier";
11
+ import { appIdentifier } from "@alanszp/core";
12
12
  jest.mock("@alanszp/shared-context");
13
13
 
14
14
  const logger = createMockLogger({});
@@ -2,7 +2,7 @@ import { createId } from "@paralleldrive/cuid2";
2
2
  import { NextFunction, Response } from "express";
3
3
  import { ILogger } from "@alanszp/logger";
4
4
  import { Audit } from "@alanszp/audit";
5
- import { appIdentifier } from "../helpers/appIdentifier";
5
+ import { appIdentifier } from "@alanszp/core";
6
6
  import { GenericRequest } from "../types/GenericRequest";
7
7
  import { SharedContext } from "@alanszp/shared-context";
8
8
  import { compact } from "lodash";
@@ -1,10 +1,9 @@
1
- import { UnauthorizedError } from "@alanszp/errors";
2
- import { errorView } from "../views/errorView";
3
1
  import { NextFunction, Response } from "express";
4
2
  import { GenericRequest } from "../types/GenericRequest";
3
+ import { render401Error } from "../helpers/renderErrorJson";
5
4
 
6
5
  function response401(res: Response): void {
7
- res.status(401).json(errorView(new UnauthorizedError(["permissions"])));
6
+ res.status(401).json(render401Error(["permissions"]));
8
7
  }
9
8
 
10
9
  export function hasRoles(
@@ -1,8 +1,7 @@
1
1
  import { json, OptionsJson } from "body-parser";
2
2
  import { NextFunction, Response } from "express";
3
- import { BadRequestError } from "@alanszp/errors";
4
- import { errorView } from "../views/errorView";
5
3
  import { GenericRequest } from "../types/GenericRequest";
4
+ import { render400Error } from "../helpers/renderErrorJson";
6
5
 
7
6
  export function jsonBodyParser(options?: OptionsJson) {
8
7
  const bodyParser = json({ limit: "1mb", ...options });
@@ -14,10 +13,10 @@ export function jsonBodyParser(options?: OptionsJson) {
14
13
  try {
15
14
  bodyParser(req, res, (error?: unknown) => {
16
15
  if (!error) return next();
17
- res.status(400).json(errorView(new BadRequestError("Malformed JSON")));
16
+ res.status(400).json(render400Error("Malformed JSON"));
18
17
  });
19
18
  } catch (error: unknown) {
20
- res.status(400).json(errorView(new BadRequestError("Malformed JSON")));
19
+ res.status(400).json(render400Error("Malformed JSON"));
21
20
  }
22
21
  };
23
22
  }
@@ -1,6 +1,5 @@
1
1
  import { ErrorRequestHandler, NextFunction, Response } from "express";
2
2
  import { InternalServerError } from "@alanszp/errors";
3
- import { errorView } from "../views/errorView";
4
3
  import { GenericRequest } from "../types/GenericRequest";
5
4
  import { ILogger } from "@alanszp/logger";
6
5
 
@@ -11,6 +10,6 @@ export type GetInternalServerErrorMiddleware = (
11
10
  export const returnInternalServerError: GetInternalServerErrorMiddleware =
12
11
  (getLogger: () => ILogger) =>
13
12
  (error: unknown, req: GenericRequest, res: Response, _next: NextFunction) => {
14
- res.status(500).json(errorView(new InternalServerError(error)));
13
+ res.status(500).json(new InternalServerError(error).toView());
15
14
  getLogger().error("error_to_client", { error });
16
15
  };
@@ -1,12 +1,11 @@
1
1
  import { NextFunction, Response } from "express";
2
- import { NotFoundError } from "@alanszp/errors";
3
- import { errorView } from "../views/errorView";
4
2
  import { GenericRequest } from "../types/GenericRequest";
3
+ import { render404Error } from "../helpers/renderErrorJson";
5
4
 
6
5
  export function returnNotFound(
7
6
  _req: GenericRequest,
8
7
  res: Response,
9
8
  _next: NextFunction
10
9
  ): void {
11
- res.status(404).json(errorView(new NotFoundError()));
10
+ res.status(404).json(render404Error());
12
11
  }
@@ -1 +0,0 @@
1
- export declare function appIdentifier(): string;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.appIdentifier = void 0;
4
- function appIdentifier() {
5
- const appName = process.env.API_ORIGIN_NAME || "undefined";
6
- const env = process.env.NODE_ENV || "development";
7
- return `${appName}:${env}`;
8
- }
9
- exports.appIdentifier = appIdentifier;
10
- //# sourceMappingURL=appIdentifier.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"appIdentifier.js","sourceRoot":"","sources":["../../src/helpers/appIdentifier.ts"],"names":[],"mappings":";;;AAAA,SAAgB,aAAa;IAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,WAAW,CAAC;IAC3D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;IAClD,OAAO,GAAG,OAAO,IAAI,GAAG,EAAE,CAAC;AAC7B,CAAC;AAJD,sCAIC"}
@@ -1,2 +0,0 @@
1
- import { RenderableError } from "@alanszp/errors";
2
- export declare function errorView(err: RenderableError): unknown;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.errorView = void 0;
4
- const appIdentifier_1 = require("../helpers/appIdentifier");
5
- function errorView(err) {
6
- return {
7
- code: err.code(),
8
- message: err.renderMessage(),
9
- context: err.context(),
10
- origin: (0, appIdentifier_1.appIdentifier)(),
11
- };
12
- }
13
- exports.errorView = errorView;
14
- //# sourceMappingURL=errorView.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errorView.js","sourceRoot":"","sources":["../../src/views/errorView.ts"],"names":[],"mappings":";;;AACA,4DAAyD;AAEzD,SAAgB,SAAS,CAAC,GAAoB;IAC5C,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE;QAChB,OAAO,EAAE,GAAG,CAAC,aAAa,EAAE;QAC5B,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE;QACtB,MAAM,EAAE,IAAA,6BAAa,GAAE;KACxB,CAAC;AACJ,CAAC;AAPD,8BAOC"}
@@ -1,5 +0,0 @@
1
- export function appIdentifier() {
2
- const appName = process.env.API_ORIGIN_NAME || "undefined";
3
- const env = process.env.NODE_ENV || "development";
4
- return `${appName}:${env}`;
5
- }
@@ -1,11 +0,0 @@
1
- import { RenderableError } from "@alanszp/errors";
2
- import { appIdentifier } from "../helpers/appIdentifier";
3
-
4
- export function errorView(err: RenderableError): unknown {
5
- return {
6
- code: err.code(),
7
- message: err.renderMessage(),
8
- context: err.context(),
9
- origin: appIdentifier(),
10
- };
11
- }