arkos 1.2.12-beta → 1.2.13-beta

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 (87) hide show
  1. package/dist/cjs/modules/auth/auth.router.js +9 -83
  2. package/dist/cjs/modules/auth/auth.router.js.map +1 -1
  3. package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +10 -94
  4. package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
  5. package/dist/cjs/modules/error-handler/error-handler.controller.js +2 -0
  6. package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
  7. package/dist/cjs/modules/error-handler/utils/catch-async.js.map +1 -1
  8. package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js +6 -0
  9. package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
  10. package/dist/cjs/modules/file-upload/file-upload.router.js +9 -21
  11. package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
  12. package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js +7 -0
  13. package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js.map +1 -1
  14. package/dist/cjs/modules/swagger/swagger.router.js +4 -3
  15. package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
  16. package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js +3 -2
  17. package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
  18. package/dist/cjs/server.js +4 -2
  19. package/dist/cjs/server.js.map +1 -1
  20. package/dist/cjs/utils/cli/dev.js +18 -16
  21. package/dist/cjs/utils/cli/dev.js.map +1 -1
  22. package/dist/cjs/utils/cli/generate.js +1 -1
  23. package/dist/cjs/utils/cli/generate.js.map +1 -1
  24. package/dist/cjs/utils/cli/start.js +1 -1
  25. package/dist/cjs/utils/cli/start.js.map +1 -1
  26. package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
  27. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js +1 -1
  28. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js.map +1 -1
  29. package/dist/cjs/utils/features/api.features.js +9 -3
  30. package/dist/cjs/utils/features/api.features.js.map +1 -1
  31. package/dist/cjs/utils/helpers/global.helpers.js +4 -22
  32. package/dist/cjs/utils/helpers/global.helpers.js.map +1 -1
  33. package/dist/cjs/utils/helpers/models.helpers.js +25 -9
  34. package/dist/cjs/utils/helpers/models.helpers.js.map +1 -1
  35. package/dist/cjs/utils/helpers/routers.helpers.js +21 -0
  36. package/dist/cjs/utils/helpers/routers.helpers.js.map +1 -0
  37. package/dist/cjs/utils/sheu.js +101 -125
  38. package/dist/cjs/utils/sheu.js.map +1 -1
  39. package/dist/esm/modules/auth/auth.router.js +9 -83
  40. package/dist/esm/modules/auth/auth.router.js.map +1 -1
  41. package/dist/esm/modules/base/utils/helpers/base.router.helpers.js +10 -94
  42. package/dist/esm/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
  43. package/dist/esm/modules/error-handler/error-handler.controller.js +2 -0
  44. package/dist/esm/modules/error-handler/error-handler.controller.js.map +1 -1
  45. package/dist/esm/modules/error-handler/utils/catch-async.js.map +1 -1
  46. package/dist/esm/modules/error-handler/utils/error-handler.helpers.js +5 -0
  47. package/dist/esm/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
  48. package/dist/esm/modules/file-upload/file-upload.router.js +9 -21
  49. package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
  50. package/dist/esm/modules/file-upload/utils/helpers/file-upload.helpers.js +6 -0
  51. package/dist/esm/modules/file-upload/utils/helpers/file-upload.helpers.js.map +1 -1
  52. package/dist/esm/modules/swagger/swagger.router.js +4 -3
  53. package/dist/esm/modules/swagger/swagger.router.js.map +1 -1
  54. package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js +3 -2
  55. package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
  56. package/dist/esm/server.js +4 -2
  57. package/dist/esm/server.js.map +1 -1
  58. package/dist/esm/utils/cli/dev.js +18 -16
  59. package/dist/esm/utils/cli/dev.js.map +1 -1
  60. package/dist/esm/utils/cli/generate.js +1 -1
  61. package/dist/esm/utils/cli/generate.js.map +1 -1
  62. package/dist/esm/utils/cli/start.js +1 -1
  63. package/dist/esm/utils/cli/start.js.map +1 -1
  64. package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
  65. package/dist/esm/utils/cli/utils/template-generator/templates/generate-service-template.js +1 -1
  66. package/dist/esm/utils/cli/utils/template-generator/templates/generate-service-template.js.map +1 -1
  67. package/dist/esm/utils/features/api.features.js +9 -3
  68. package/dist/esm/utils/features/api.features.js.map +1 -1
  69. package/dist/esm/utils/helpers/global.helpers.js +4 -22
  70. package/dist/esm/utils/helpers/global.helpers.js.map +1 -1
  71. package/dist/esm/utils/helpers/models.helpers.js +24 -9
  72. package/dist/esm/utils/helpers/models.helpers.js.map +1 -1
  73. package/dist/esm/utils/helpers/routers.helpers.js +16 -0
  74. package/dist/esm/utils/helpers/routers.helpers.js.map +1 -0
  75. package/dist/esm/utils/sheu.js +101 -125
  76. package/dist/esm/utils/sheu.js.map +1 -1
  77. package/dist/types/modules/error-handler/utils/catch-async.d.ts +1 -0
  78. package/dist/types/modules/error-handler/utils/error-handler.helpers.d.ts +4 -0
  79. package/dist/types/modules/file-upload/file-upload.router.d.ts +1 -1
  80. package/dist/types/modules/file-upload/utils/helpers/file-upload.helpers.d.ts +2 -1
  81. package/dist/types/modules/swagger/utils/helpers/swagger.router.helpers.d.ts +1 -1
  82. package/dist/types/server.d.ts +3 -0
  83. package/dist/types/utils/features/api.features.d.ts +1 -0
  84. package/dist/types/utils/helpers/models.helpers.d.ts +7 -4
  85. package/dist/types/utils/helpers/routers.helpers.d.ts +2 -0
  86. package/dist/types/utils/sheu.d.ts +66 -21
  87. package/package.json +2 -3
@@ -11,10 +11,10 @@ const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
11
11
  const models_helpers_1 = require("../../utils/helpers/models.helpers");
12
12
  const base_middlewares_1 = require("../base/base.middlewares");
13
13
  const deepmerge_helper_1 = __importDefault(require("../../utils/helpers/deepmerge.helper"));
14
- const catch_async_1 = __importDefault(require("../error-handler/utils/catch-async"));
14
+ const routers_helpers_1 = require("../../utils/helpers/routers.helpers");
15
15
  const router = (0, express_1.Router)();
16
16
  async function getAuthRouter(arkosConfigs) {
17
- const { middlewares, dtos, schemas, prismaQueryOptions } = await (0, models_helpers_1.importPrismaModelModules)("auth");
17
+ const { middlewares, dtos, schemas, prismaQueryOptions } = await (0, models_helpers_1.importPrismaModelModules)("auth", arkosConfigs);
18
18
  const authController = await (0, auth_controller_1.authControllerFactory)(middlewares);
19
19
  const getValidationSchemaOrDto = (key) => {
20
20
  const validationConfigs = arkosConfigs?.validation;
@@ -26,43 +26,10 @@ async function getAuthRouter(arkosConfigs) {
26
26
  }
27
27
  return undefined;
28
28
  };
29
- const safeCatchAsync = (middleware) => {
30
- return middleware ? (0, catch_async_1.default)(middleware) : undefined;
31
- };
32
29
  router
33
- .get("/users/me", auth_service_1.default.authenticate, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "getMe"), ...[
34
- safeCatchAsync(middlewares?.beforeGetMe) || authController.getMe,
35
- safeCatchAsync(middlewares?.beforeGetMe)
36
- ? authController.getMe
37
- : safeCatchAsync(middlewares?.afterGetMe) || base_middlewares_1.sendResponse,
38
- safeCatchAsync(middlewares?.beforeGetMe) &&
39
- safeCatchAsync(middlewares?.afterGetMe)
40
- ? safeCatchAsync(middlewares?.afterGetMe)
41
- : base_middlewares_1.sendResponse,
42
- base_middlewares_1.sendResponse,
43
- ].filter((middleware) => !!middleware))
44
- .patch("/users/me", auth_service_1.default.authenticate, (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("updateMe")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateMe"), ...[
45
- safeCatchAsync(middlewares?.beforeUpdateMe) || authController.updateMe,
46
- safeCatchAsync(middlewares?.beforeUpdateMe)
47
- ? authController.updateMe
48
- : safeCatchAsync(middlewares?.afterUpdateMe) || base_middlewares_1.sendResponse,
49
- safeCatchAsync(middlewares?.beforeUpdateMe) &&
50
- safeCatchAsync(middlewares?.afterUpdateMe)
51
- ? safeCatchAsync(middlewares?.afterUpdateMe)
52
- : base_middlewares_1.sendResponse,
53
- base_middlewares_1.sendResponse,
54
- ].filter((middleware) => !!middleware))
55
- .delete("/users/me", auth_service_1.default.authenticate, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteMe"), ...[
56
- safeCatchAsync(middlewares?.beforeDeleteMe) || authController.deleteMe,
57
- safeCatchAsync(middlewares?.beforeDeleteMe)
58
- ? authController.deleteMe
59
- : safeCatchAsync(middlewares?.afterDeleteMe) || base_middlewares_1.sendResponse,
60
- safeCatchAsync(middlewares?.beforeDeleteMe) &&
61
- safeCatchAsync(middlewares?.afterDeleteMe)
62
- ? safeCatchAsync(middlewares?.afterDeleteMe)
63
- : base_middlewares_1.sendResponse,
64
- base_middlewares_1.sendResponse,
65
- ].filter((middleware) => !!middleware));
30
+ .get("/users/me", auth_service_1.default.authenticate, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "getMe"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeGetMe), authController.getMe, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterGetMe), base_middlewares_1.sendResponse)
31
+ .patch("/users/me", auth_service_1.default.authenticate, (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("updateMe")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateMe"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeUpdateMe), authController.updateMe, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterUpdateMe), base_middlewares_1.sendResponse)
32
+ .delete("/users/me", auth_service_1.default.authenticate, (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteMe"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeDeleteMe), authController.deleteMe, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterDeleteMe), base_middlewares_1.sendResponse);
66
33
  router.use("/auth", (0, express_rate_limit_1.default)((0, deepmerge_helper_1.default)({
67
34
  windowMs: 5000,
68
35
  limit: 10,
@@ -74,51 +41,10 @@ async function getAuthRouter(arkosConfigs) {
74
41
  });
75
42
  },
76
43
  }, arkosConfigs?.authentication?.requestRateLimitOptions || {})));
77
- router.post("/auth/login", (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("login")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "login"), ...[
78
- safeCatchAsync(middlewares?.beforeLogin) || authController.login,
79
- safeCatchAsync(middlewares?.beforeLogin)
80
- ? authController.login
81
- : safeCatchAsync(middlewares?.afterLogin) || base_middlewares_1.sendResponse,
82
- safeCatchAsync(middlewares?.beforeLogin) &&
83
- safeCatchAsync(middlewares?.afterLogin)
84
- ? safeCatchAsync(middlewares?.afterLogin)
85
- : base_middlewares_1.sendResponse,
86
- base_middlewares_1.sendResponse,
87
- ].filter((middleware) => !!middleware));
88
- router.delete("/auth/logout", auth_service_1.default.authenticate, ...[
89
- safeCatchAsync(middlewares?.beforeLogout) || authController.logout,
90
- safeCatchAsync(middlewares?.beforeLogout)
91
- ? authController.logout
92
- : safeCatchAsync(middlewares?.afterLogout) || base_middlewares_1.sendResponse,
93
- safeCatchAsync(middlewares?.beforeLogout) &&
94
- safeCatchAsync(middlewares?.afterLogout)
95
- ? safeCatchAsync(middlewares?.afterLogout)
96
- : base_middlewares_1.sendResponse,
97
- base_middlewares_1.sendResponse,
98
- ].filter((middleware) => !!middleware));
99
- router.post("/auth/signup", (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("signup")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "signup"), ...[
100
- safeCatchAsync(middlewares?.beforeSignup) || authController.signup,
101
- safeCatchAsync(middlewares?.beforeSignup)
102
- ? authController.signup
103
- : safeCatchAsync(middlewares?.afterSignup) || base_middlewares_1.sendResponse,
104
- safeCatchAsync(middlewares?.beforeSignup) &&
105
- safeCatchAsync(middlewares?.afterSignup)
106
- ? safeCatchAsync(middlewares?.afterSignup)
107
- : base_middlewares_1.sendResponse,
108
- base_middlewares_1.sendResponse,
109
- ].filter((middleware) => !!middleware));
110
- router.post("/auth/update-password", auth_service_1.default.authenticate, (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("updatePassword")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updatePassword"), ...[
111
- safeCatchAsync(middlewares?.beforeUpdatePassword) ||
112
- authController.updatePassword,
113
- safeCatchAsync(middlewares?.beforeUpdatePassword)
114
- ? authController.updatePassword
115
- : safeCatchAsync(middlewares?.afterUpdatePassword) || base_middlewares_1.sendResponse,
116
- safeCatchAsync(middlewares?.beforeUpdatePassword) &&
117
- safeCatchAsync(middlewares?.afterUpdatePassword)
118
- ? safeCatchAsync(middlewares?.afterUpdatePassword)
119
- : base_middlewares_1.sendResponse,
120
- base_middlewares_1.sendResponse,
121
- ].filter((middleware) => !!middleware));
44
+ router.post("/auth/login", (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("login")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "login"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeLogin), authController.login, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterLogin), base_middlewares_1.sendResponse);
45
+ router.delete("/auth/logout", auth_service_1.default.authenticate, ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeLogout), authController.logout, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterLogout), base_middlewares_1.sendResponse);
46
+ router.post("/auth/signup", (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("signup")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "signup"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeSignup), authController.signup, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterSignup), base_middlewares_1.sendResponse);
47
+ router.post("/auth/update-password", auth_service_1.default.authenticate, (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("updatePassword")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updatePassword"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeUpdatePassword), authController.updatePassword, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterUpdatePassword), base_middlewares_1.sendResponse);
122
48
  return router;
123
49
  }
124
50
  //# sourceMappingURL=auth.router.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":";;;;;AAiBA,sCA4LC;AA7MD,qCAAiC;AACjC,uDAA0D;AAC1D,kEAAyC;AACzC,4EAA2C;AAC3C,uEAA8E;AAC9E,+DAIkC;AAElC,4FAA6D;AAE7D,qFAA4D;AAE5D,MAAM,MAAM,GAAW,IAAA,gBAAM,GAAE,CAAC;AAEzB,KAAK,UAAU,aAAa,CAAC,YAAyB;IAC3D,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,kBAAkB,EAAE,GACtD,MAAM,IAAA,yCAAwB,EAAC,MAAM,CAAC,CAAC;IACzC,MAAM,cAAc,GAAG,MAAM,IAAA,uCAAqB,EAAC,WAAW,CAAC,CAAC;IAGhE,MAAM,wBAAwB,GAAG,CAAC,GAAW,EAAE,EAAE;QAC/C,MAAM,iBAAiB,GAAG,YAAY,EAAE,UAAU,CAAC;QACnD,IAAI,iBAAiB,EAAE,QAAQ,KAAK,iBAAiB,EAAE,CAA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,CAAC,WAAW,EAAE,mBAAmB,CAAC;YAC9C,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB,CAAC;YAClD,CAAC,CAAC,+BAAY;QAChB,+BAAY;KACb,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CACvC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { authControllerFactory } from \"./auth.controller\";\nimport authService from \"./auth.service\";\nimport rateLimit from \"express-rate-limit\";\nimport { importPrismaModelModules } from \"../../utils/helpers/models.helpers\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport catchAsync from \"../error-handler/utils/catch-async\";\n\nconst router: Router = Router();\n\nexport async function getAuthRouter(arkosConfigs: ArkosConfig) {\n const { middlewares, dtos, schemas, prismaQueryOptions } =\n await importPrismaModelModules(\"auth\");\n const authController = await authControllerFactory(middlewares);\n\n // Helper to get the correct schema or DTO based on Arkos Config\n const getValidationSchemaOrDto = (key: string) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n // Helper to conditionally wrap middleware with catchAsync\n const safeCatchAsync = (middleware: any) => {\n return middleware ? catchAsync(middleware) : undefined;\n };\n\n router\n .get(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeGetMe) || authController.getMe,\n safeCatchAsync(middlewares?.beforeGetMe)\n ? authController.getMe\n : safeCatchAsync(middlewares?.afterGetMe) || sendResponse,\n safeCatchAsync(middlewares?.beforeGetMe) &&\n safeCatchAsync(middlewares?.afterGetMe)\n ? safeCatchAsync(middlewares?.afterGetMe)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n )\n .patch(\n \"/users/me\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMe\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdateMe) || authController.updateMe,\n safeCatchAsync(middlewares?.beforeUpdateMe)\n ? authController.updateMe\n : safeCatchAsync(middlewares?.afterUpdateMe) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdateMe) &&\n safeCatchAsync(middlewares?.afterUpdateMe)\n ? safeCatchAsync(middlewares?.afterUpdateMe)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n )\n .delete(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeDeleteMe) || authController.deleteMe,\n safeCatchAsync(middlewares?.beforeDeleteMe)\n ? authController.deleteMe\n : safeCatchAsync(middlewares?.afterDeleteMe) || sendResponse,\n safeCatchAsync(middlewares?.beforeDeleteMe) &&\n safeCatchAsync(middlewares?.afterDeleteMe)\n ? safeCatchAsync(middlewares?.afterDeleteMe)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n\n router.use(\n \"/auth\",\n rateLimit(\n deepmerge(\n {\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n handler: (req, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n arkosConfigs?.authentication?.requestRateLimitOptions || {}\n )\n )\n );\n\n router.post(\n \"/auth/login\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"login\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeLogin) || authController.login,\n safeCatchAsync(middlewares?.beforeLogin)\n ? authController.login\n : safeCatchAsync(middlewares?.afterLogin) || sendResponse,\n safeCatchAsync(middlewares?.beforeLogin) &&\n safeCatchAsync(middlewares?.afterLogin)\n ? safeCatchAsync(middlewares?.afterLogin)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n\n router.delete(\n \"/auth/logout\",\n authService.authenticate,\n ...[\n safeCatchAsync(middlewares?.beforeLogout) || authController.logout,\n safeCatchAsync(middlewares?.beforeLogout)\n ? authController.logout\n : safeCatchAsync(middlewares?.afterLogout) || sendResponse,\n safeCatchAsync(middlewares?.beforeLogout) &&\n safeCatchAsync(middlewares?.afterLogout)\n ? safeCatchAsync(middlewares?.afterLogout)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n\n router.post(\n \"/auth/signup\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"signup\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeSignup) || authController.signup,\n safeCatchAsync(middlewares?.beforeSignup)\n ? authController.signup\n : safeCatchAsync(middlewares?.afterSignup) || sendResponse,\n safeCatchAsync(middlewares?.beforeSignup) &&\n safeCatchAsync(middlewares?.afterSignup)\n ? safeCatchAsync(middlewares?.afterSignup)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n\n router.post(\n \"/auth/update-password\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updatePassword\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdatePassword) ||\n authController.updatePassword,\n safeCatchAsync(middlewares?.beforeUpdatePassword)\n ? authController.updatePassword\n : safeCatchAsync(middlewares?.afterUpdatePassword) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdatePassword) &&\n safeCatchAsync(middlewares?.afterUpdatePassword)\n ? safeCatchAsync(middlewares?.afterUpdatePassword)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n\n return router;\n}\n"]}
1
+ {"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":";;;;;AAiBA,sCAqIC;AAtJD,qCAAiC;AACjC,uDAA0D;AAC1D,kEAAyC;AACzC,4EAA2C;AAC3C,uEAA8E;AAC9E,+DAIkC;AAElC,4FAA6D;AAE7D,yEAAwE;AAExE,MAAM,MAAM,GAAW,IAAA,gBAAM,GAAE,CAAC;AAEzB,KAAK,UAAU,aAAa,CAAC,YAAyB;IAC3D,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,kBAAkB,EAAE,GACtD,MAAM,IAAA,yCAAwB,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACvD,MAAM,cAAc,GAAG,MAAM,IAAA,uCAAqB,EAAC,WAAW,CAAC,CAAC;IAGhE,MAAM,wBAAwB,GAAG,CAAC,GAAW,EAAE,EAAE;QAC/C,MAAM,iBAAiB,GAAG,YAAY,EAAE,UAAU,CAAC;QACnD,IAAI,iBAAiB,EAAE,QAAQ,KAAK,iBAAiB,EAAE,CAAC;YACtD,OAAO,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;aAAM,IAAI,iBAAiB,EAAE,QAAQ,KAAK,KAAK,EAAE,CAAC;YACjD,OAAO,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,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AO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { authControllerFactory } from \"./auth.controller\";\nimport authService from \"./auth.service\";\nimport rateLimit from \"express-rate-limit\";\nimport { importPrismaModelModules } from \"../../utils/helpers/models.helpers\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\n\nconst router: Router = Router();\n\nexport async function getAuthRouter(arkosConfigs: ArkosConfig) {\n const { middlewares, dtos, schemas, prismaQueryOptions } =\n await importPrismaModelModules(\"auth\", arkosConfigs);\n const authController = await authControllerFactory(middlewares);\n\n // Helper to get the correct schema or DTO based on Arkos Config\n const getValidationSchemaOrDto = (key: string) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n router\n .get(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...processMiddleware(middlewares?.beforeGetMe),\n authController.getMe,\n ...processMiddleware(middlewares?.afterGetMe),\n sendResponse\n )\n .patch(\n \"/users/me\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMe\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...processMiddleware(middlewares?.beforeUpdateMe),\n authController.updateMe,\n ...processMiddleware(middlewares?.afterUpdateMe),\n sendResponse\n )\n .delete(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...processMiddleware(middlewares?.beforeDeleteMe),\n authController.deleteMe,\n ...processMiddleware(middlewares?.afterDeleteMe),\n sendResponse\n );\n\n router.use(\n \"/auth\",\n rateLimit(\n deepmerge(\n {\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n handler: (req, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n arkosConfigs?.authentication?.requestRateLimitOptions || {}\n )\n )\n );\n\n router.post(\n \"/auth/login\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"login\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...processMiddleware(middlewares?.beforeLogin),\n authController.login,\n ...processMiddleware(middlewares?.afterLogin),\n sendResponse\n );\n\n router.delete(\n \"/auth/logout\",\n authService.authenticate,\n ...processMiddleware(middlewares?.beforeLogout),\n authController.logout,\n ...processMiddleware(middlewares?.afterLogout),\n sendResponse\n );\n\n router.post(\n \"/auth/signup\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"signup\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...processMiddleware(middlewares?.beforeSignup),\n authController.signup,\n ...processMiddleware(middlewares?.afterSignup),\n sendResponse\n );\n\n router.post(\n \"/auth/update-password\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updatePassword\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...processMiddleware(middlewares?.beforeUpdatePassword),\n authController.updatePassword,\n ...processMiddleware(middlewares?.afterUpdatePassword),\n sendResponse\n );\n\n return router;\n}\n"]}
@@ -12,11 +12,11 @@ const models_helpers_1 = require("../../../../utils/helpers/models.helpers");
12
12
  const auth_service_1 = __importDefault(require("../../../auth/auth.service"));
13
13
  const base_controller_1 = require("../../base.controller");
14
14
  const base_middlewares_1 = require("../../base.middlewares");
15
- const catch_async_1 = __importDefault(require("../../../error-handler/utils/catch-async"));
15
+ const routers_helpers_1 = require("../../../../utils/helpers/routers.helpers");
16
16
  function setupRouters(models, router, arkosConfigs) {
17
17
  return models.map(async (model) => {
18
18
  const modelNameInKebab = (0, utils_1.kebabCase)(model);
19
- const modelModules = await (0, models_helpers_1.importPrismaModelModules)(modelNameInKebab);
19
+ const modelModules = await (0, models_helpers_1.importPrismaModelModules)(modelNameInKebab, arkosConfigs);
20
20
  const { middlewares, authConfigs, prismaQueryOptions, router: customRouterModule, dtos, schemas, } = modelModules;
21
21
  const routeName = pluralize_1.default.plural(modelNameInKebab);
22
22
  const controller = new base_controller_1.BaseController(model);
@@ -41,121 +41,37 @@ function setupRouters(models, router, arkosConfigs) {
41
41
  };
42
42
  if (customRouterModule?.default && !routerConfig?.disable)
43
43
  router.use(`/${routeName}`, customRouterModule.default);
44
- function safeCatchAsync(middleware) {
45
- return middleware ? (0, catch_async_1.default)(middleware) : undefined;
46
- }
47
44
  if (!isEndpointDisabled(routerConfig, "createOne") &&
48
45
  !hasCustomImplementation(`/${routeName}`, "post")) {
49
- router.post(`/${routeName}`, auth_service_1.default.handleAuthenticationControl("Create", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Create", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("create")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createOne"), ...[
50
- safeCatchAsync(middlewares?.beforeCreateOne) || controller.createOne,
51
- safeCatchAsync(middlewares?.beforeCreateOne)
52
- ? controller.createOne
53
- : safeCatchAsync(middlewares?.afterCreateOne) || base_middlewares_1.sendResponse,
54
- safeCatchAsync(middlewares?.beforeCreateOne) &&
55
- safeCatchAsync(middlewares?.afterCreateOne)
56
- ? safeCatchAsync(middlewares?.afterCreateOne)
57
- : base_middlewares_1.sendResponse,
58
- ].filter((m) => !!m), base_middlewares_1.sendResponse);
46
+ router.post(`/${routeName}`, auth_service_1.default.handleAuthenticationControl("Create", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Create", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("create")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createOne"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeCreateOne), controller.createOne, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterCreateOne), base_middlewares_1.sendResponse);
59
47
  }
60
48
  if (!isEndpointDisabled(routerConfig, "findMany") &&
61
49
  !hasCustomImplementation(`/${routeName}`, "get")) {
62
- router.get(`/${routeName}`, auth_service_1.default.handleAuthenticationControl("View", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("View", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findMany"), ...[
63
- safeCatchAsync(middlewares?.beforeFindMany) || controller.findMany,
64
- safeCatchAsync(middlewares?.beforeFindMany)
65
- ? controller.findMany
66
- : safeCatchAsync(middlewares?.afterFindMany) || base_middlewares_1.sendResponse,
67
- safeCatchAsync(middlewares?.beforeFindMany) &&
68
- safeCatchAsync(middlewares?.afterFindMany)
69
- ? safeCatchAsync(middlewares?.afterFindMany)
70
- : base_middlewares_1.sendResponse,
71
- base_middlewares_1.sendResponse,
72
- ].filter((m) => !!m));
50
+ router.get(`/${routeName}`, auth_service_1.default.handleAuthenticationControl("View", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("View", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findMany"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeFindMany), controller.findMany, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterFindMany), base_middlewares_1.sendResponse);
73
51
  }
74
52
  if (!isEndpointDisabled(routerConfig, "createMany") &&
75
53
  !hasCustomImplementation(`/${routeName}/many`, "post")) {
76
- router.post(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Create", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Create", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("createMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createMany"), ...[
77
- safeCatchAsync(middlewares?.beforeCreateMany) ||
78
- controller.createMany,
79
- safeCatchAsync(middlewares?.beforeCreateMany)
80
- ? controller.createMany
81
- : safeCatchAsync(middlewares?.afterCreateMany) || base_middlewares_1.sendResponse,
82
- safeCatchAsync(middlewares?.beforeCreateMany) &&
83
- safeCatchAsync(middlewares?.afterCreateMany)
84
- ? safeCatchAsync(middlewares?.afterCreateMany)
85
- : base_middlewares_1.sendResponse,
86
- base_middlewares_1.sendResponse,
87
- ].filter((m) => !!m));
54
+ router.post(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Create", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Create", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("createMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createMany"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeCreateMany), controller.createMany, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterCreateMany), base_middlewares_1.sendResponse);
88
55
  }
89
56
  if (!isEndpointDisabled(routerConfig, "updateMany") &&
90
57
  !hasCustomImplementation(`/${routeName}/many`, "patch")) {
91
- router.patch(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Update", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Update", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("updateMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateMany"), ...[
92
- safeCatchAsync(middlewares?.beforeUpdateMany) ||
93
- controller.updateMany,
94
- safeCatchAsync(middlewares?.beforeUpdateMany)
95
- ? controller.updateMany
96
- : safeCatchAsync(middlewares?.afterUpdateMany) || base_middlewares_1.sendResponse,
97
- safeCatchAsync(middlewares?.beforeUpdateMany) &&
98
- safeCatchAsync(middlewares?.afterUpdateMany)
99
- ? safeCatchAsync(middlewares?.afterUpdateMany)
100
- : base_middlewares_1.sendResponse,
101
- base_middlewares_1.sendResponse,
102
- ].filter((m) => !!m));
58
+ router.patch(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Update", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Update", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("updateMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateMany"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeUpdateMany), controller.updateMany, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterUpdateMany), base_middlewares_1.sendResponse);
103
59
  }
104
60
  if (!isEndpointDisabled(routerConfig, "deleteMany") &&
105
61
  !hasCustomImplementation(`/${routeName}/many`, "delete")) {
106
- router.delete(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Delete", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("deleteMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteMany"), ...[
107
- safeCatchAsync(middlewares?.beforeDeleteMany) ||
108
- controller.deleteMany,
109
- safeCatchAsync(middlewares?.beforeDeleteMany)
110
- ? controller.deleteMany
111
- : safeCatchAsync(middlewares?.afterDeleteMany) || base_middlewares_1.sendResponse,
112
- safeCatchAsync(middlewares?.beforeDeleteMany) &&
113
- safeCatchAsync(middlewares?.afterDeleteMany)
114
- ? safeCatchAsync(middlewares?.afterDeleteMany)
115
- : base_middlewares_1.sendResponse,
116
- base_middlewares_1.sendResponse,
117
- ].filter((middleware) => !!middleware));
62
+ router.delete(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Delete", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("deleteMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteMany"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeDeleteMany), controller.deleteMany, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterDeleteMany), base_middlewares_1.sendResponse);
118
63
  }
119
64
  if (!isEndpointDisabled(routerConfig, "findOne") &&
120
65
  !hasCustomImplementation(`/${routeName}/:id`, "get")) {
121
- router.get(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("View", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("View", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("findOne")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findOne"), ...[
122
- safeCatchAsync(middlewares?.beforeFindOne) || controller.findOne,
123
- safeCatchAsync(middlewares?.beforeFindOne)
124
- ? controller.findOne
125
- : safeCatchAsync(middlewares?.afterFindOne) || base_middlewares_1.sendResponse,
126
- safeCatchAsync(middlewares?.beforeFindOne) &&
127
- safeCatchAsync(middlewares?.afterFindOne)
128
- ? safeCatchAsync(middlewares?.afterFindOne)
129
- : base_middlewares_1.sendResponse,
130
- base_middlewares_1.sendResponse,
131
- ].filter((m) => !!m));
66
+ router.get(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("View", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("View", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("findOne")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findOne"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeFindOne), controller.findOne, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterFindOne), base_middlewares_1.sendResponse);
132
67
  }
133
68
  if (!isEndpointDisabled(routerConfig, "updateOne") &&
134
69
  !hasCustomImplementation(`/${routeName}/:id`, "patch")) {
135
- router.patch(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("Update", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Update", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("update")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateOne"), ...[
136
- safeCatchAsync(middlewares?.beforeUpdateOne) || controller.updateOne,
137
- safeCatchAsync(middlewares?.beforeUpdateOne)
138
- ? controller.updateOne
139
- : safeCatchAsync(middlewares?.afterUpdateOne) || base_middlewares_1.sendResponse,
140
- safeCatchAsync(middlewares?.beforeUpdateOne) &&
141
- safeCatchAsync(middlewares?.afterUpdateOne)
142
- ? safeCatchAsync(middlewares?.afterUpdateOne)
143
- : base_middlewares_1.sendResponse,
144
- ].filter((m) => !!m), base_middlewares_1.sendResponse);
70
+ router.patch(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("Update", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Update", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("update")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateOne"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeUpdateOne), controller.updateOne, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterUpdateOne), base_middlewares_1.sendResponse);
145
71
  }
146
72
  if (!isEndpointDisabled(routerConfig, "deleteOne") &&
147
73
  !hasCustomImplementation(`/${routeName}/:id`, "delete")) {
148
- router.delete(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Delete", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("delete")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteOne"), ...[
149
- safeCatchAsync(middlewares?.beforeDeleteOne) || controller.deleteOne,
150
- safeCatchAsync(middlewares?.beforeDeleteOne)
151
- ? controller.deleteOne
152
- : safeCatchAsync(middlewares?.afterDeleteOne) || base_middlewares_1.sendResponse,
153
- safeCatchAsync(middlewares?.beforeDeleteOne) &&
154
- safeCatchAsync(middlewares?.afterDeleteOne)
155
- ? safeCatchAsync(middlewares?.afterDeleteOne)
156
- : base_middlewares_1.sendResponse,
157
- base_middlewares_1.sendResponse,
158
- ].filter((m) => !!m));
74
+ router.delete(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Delete", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("delete")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteOne"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeDeleteOne), controller.deleteOne, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterDeleteOne), base_middlewares_1.sendResponse);
159
75
  }
160
76
  });
161
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"base.router.helpers.js","sourceRoot":"","sources":["../../../../../../src/modules/base/utils/helpers/base.router.helpers.ts"],"names":[],"mappings":";;;;;AAgBA,oCAgWC;AAED,gDAYC;AAED,0DAWC;AA1YD,0DAAkC;AAElC,qDAAsD;AAGtD,6EAAoF;AACpF,8EAAqD;AACrD,2DAAuD;AACvD,6DAIgC;AAChC,2FAAkE;AAElE,SAAgB,YAAY,CAC1B,MAAgB,EAChB,MAAc,EACd,YAAyB;IAEzB,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAChC,MAAM,gBAAgB,GAAG,IAAA,iBAAS,EAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,MAAM,IAAA,yCAAwB,EAAC,gBAAgB,CAAC,CAAC;QACtE,MAAM,EACJ,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EACJ,OAAO,GACR,GAAG,YAAY,CAAC;QAEjB,MAAM,SAAS,GAAG,mBAAS,CA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AAC,QAAQ,CAAC,KAAK,IAAI,CAAC;IAEjD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAgB,uBAAuB,CACrC,YAAiB,EACjB,QAAgB;IAEhB,IAAI,CAAC,YAAY,EAAE,MAAM;QAAE,OAAO,KAAK,CAAC;IAExC,MAAM,eAAe,GAAG,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC;IACtD,IAAI,eAAe,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;QAAE,OAAO,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE9E,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { Router } from \"express\";\nimport pluralize from \"pluralize\";\nimport { ArkosConfig, RouterConfig } from \"../../../../exports\";\nimport { kebabCase } from \"../../../../exports/utils\";\nimport { PrismaQueryOptions } from \"../../../../types\";\nimport { RouterEndpoint } from \"../../../../types/router-config\";\nimport { importPrismaModelModules } from \"../../../../utils/helpers/models.helpers\";\nimport authService from \"../../../auth/auth.service\";\nimport { BaseController } from \"../../base.controller\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../../base.middlewares\";\nimport catchAsync from \"../../../error-handler/utils/catch-async\";\n\nexport function setupRouters(\n models: string[],\n router: Router,\n arkosConfigs: ArkosConfig\n) {\n return models.map(async (model) => {\n const modelNameInKebab = kebabCase(model);\n const modelModules = await importPrismaModelModules(modelNameInKebab);\n const {\n middlewares,\n authConfigs,\n prismaQueryOptions,\n router: customRouterModule,\n dtos,\n schemas,\n } = modelModules;\n\n const routeName = pluralize.plural(modelNameInKebab);\n const controller = new BaseController(model);\n\n const routerConfig: RouterConfig = customRouterModule?.config || {};\n\n // Check if custom implementation exists\n const customRouter = (customRouterModule as Router) || {};\n const hasCustomImplementation = (path: string, method: string) => {\n return customRouter.stack?.some(\n (layer) =>\n (layer.path === `/api/${path}` ||\n layer.path === `api/${path}` ||\n layer.path === `api/${path}/` ||\n layer.path === `/api/${path}/`) &&\n layer.method.toLowerCase() === method.toLowerCase()\n );\n };\n\n // Helper to get the correct schema or DTO based on Arkos Config\n const getValidationSchemaOrDto = (\n key: keyof typeof dtos | keyof typeof schemas\n ) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n // If the custom router has its own routes, add them\n if (customRouterModule?.default && !routerConfig?.disable)\n router.use(`/${routeName}`, customRouterModule.default);\n\n function safeCatchAsync(middleware: any) {\n return middleware ? catchAsync(middleware) : undefined;\n }\n\n // POST /{routeName} - Create One\n if (\n !isEndpointDisabled(routerConfig, \"createOne\") &&\n !hasCustomImplementation(`/${routeName}`, \"post\")\n ) {\n router.post(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"create\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeCreateOne) || controller.createOne,\n safeCatchAsync(middlewares?.beforeCreateOne)\n ? controller.createOne\n : safeCatchAsync(middlewares?.afterCreateOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeCreateOne) &&\n safeCatchAsync(middlewares?.afterCreateOne)\n ? safeCatchAsync(middlewares?.afterCreateOne)\n : sendResponse,\n ].filter((m) => !!m),\n sendResponse\n );\n }\n\n // GET /{routeName} - Find Many\n if (\n !isEndpointDisabled(routerConfig, \"findMany\") &&\n !hasCustomImplementation(`/${routeName}`, \"get\")\n ) {\n router.get(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeFindMany) || controller.findMany,\n safeCatchAsync(middlewares?.beforeFindMany)\n ? controller.findMany\n : safeCatchAsync(middlewares?.afterFindMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeFindMany) &&\n safeCatchAsync(middlewares?.afterFindMany)\n ? safeCatchAsync(middlewares?.afterFindMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // POST /{routeName}/many - Create Many\n if (\n !isEndpointDisabled(routerConfig, \"createMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"post\")\n ) {\n router.post(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"createMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeCreateMany) ||\n controller.createMany,\n safeCatchAsync(middlewares?.beforeCreateMany)\n ? controller.createMany\n : safeCatchAsync(middlewares?.afterCreateMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeCreateMany) &&\n safeCatchAsync(middlewares?.afterCreateMany)\n ? safeCatchAsync(middlewares?.afterCreateMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // PATCH /{routeName}/many - Update Many\n if (\n !isEndpointDisabled(routerConfig, \"updateMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdateMany) ||\n controller.updateMany,\n safeCatchAsync(middlewares?.beforeUpdateMany)\n ? controller.updateMany\n : safeCatchAsync(middlewares?.afterUpdateMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdateMany) &&\n safeCatchAsync(middlewares?.afterUpdateMany)\n ? safeCatchAsync(middlewares?.afterUpdateMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // DELETE /{routeName}/many - Delete Many\n if (\n !isEndpointDisabled(routerConfig, \"deleteMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"deleteMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeDeleteMany) ||\n controller.deleteMany,\n safeCatchAsync(middlewares?.beforeDeleteMany)\n ? controller.deleteMany\n : safeCatchAsync(middlewares?.afterDeleteMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeDeleteMany) &&\n safeCatchAsync(middlewares?.afterDeleteMany)\n ? safeCatchAsync(middlewares?.afterDeleteMany)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n }\n\n // GET /{routeName}/:id - Find One\n if (\n !isEndpointDisabled(routerConfig, \"findOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"get\")\n ) {\n router.get(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"findOne\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeFindOne) || controller.findOne,\n safeCatchAsync(middlewares?.beforeFindOne)\n ? controller.findOne\n : safeCatchAsync(middlewares?.afterFindOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeFindOne) &&\n safeCatchAsync(middlewares?.afterFindOne)\n ? safeCatchAsync(middlewares?.afterFindOne)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // PATCH /{routeName}/:id - Update One\n if (\n !isEndpointDisabled(routerConfig, \"updateOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"update\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdateOne) || controller.updateOne,\n safeCatchAsync(middlewares?.beforeUpdateOne)\n ? controller.updateOne\n : safeCatchAsync(middlewares?.afterUpdateOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdateOne) &&\n safeCatchAsync(middlewares?.afterUpdateOne)\n ? safeCatchAsync(middlewares?.afterUpdateOne)\n : sendResponse,\n ].filter((m) => !!m),\n sendResponse\n );\n }\n\n // DELETE /{routeName}/:id - Delete One\n if (\n !isEndpointDisabled(routerConfig, \"deleteOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"delete\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeDeleteOne) || controller.deleteOne,\n safeCatchAsync(middlewares?.beforeDeleteOne)\n ? controller.deleteOne\n : safeCatchAsync(middlewares?.afterDeleteOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeDeleteOne) &&\n safeCatchAsync(middlewares?.afterDeleteOne)\n ? safeCatchAsync(middlewares?.afterDeleteOne)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n });\n}\n\nexport function isEndpointDisabled(\n routerConfig: RouterConfig,\n endpoint: RouterEndpoint\n): boolean {\n if (!routerConfig?.disable) return false;\n\n if (routerConfig.disable === true) return true;\n\n if (typeof routerConfig.disable === \"object\")\n return routerConfig.disable[endpoint] === true;\n\n return false;\n}\n\nexport function isParentEndpointAllowed(\n routerConfig: any,\n endpoint: string\n): boolean {\n if (!routerConfig?.parent) return false;\n\n const parentEndpoints = routerConfig.parent.endpoints;\n if (parentEndpoints === \"*\") return true;\n if (Array.isArray(parentEndpoints)) return parentEndpoints.includes(endpoint);\n\n return true; // Default to allow if not specified\n}\n"]}
1
+ {"version":3,"file":"base.router.helpers.js","sourceRoot":"","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AAC,YAAY,EAAE,OAAO;QAAE,OAAO,KAAK,CAAC;IAEzC,IAAI,YAAY,CAAC,OAAO,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAE/C,IAAI,OAAO,YAAY,CAAC,OAAO,KAAK,QAAQ;QAC1C,OAAO,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;IAEjD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAgB,uBAAuB,CACrC,YAAiB,EACjB,QAAgB;IAEhB,IAAI,CAAC,YAAY,EAAE,MAAM;QAAE,OAAO,KAAK,CAAC;IAExC,MAAM,eAAe,GAAG,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC;IACtD,IAAI,eAAe,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;QAAE,OAAO,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE9E,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { Router } from \"express\";\nimport pluralize from \"pluralize\";\nimport { ArkosConfig, RouterConfig } from \"../../../../exports\";\nimport { kebabCase } from \"../../../../exports/utils\";\nimport { PrismaQueryOptions } from \"../../../../types\";\nimport { RouterEndpoint } from \"../../../../types/router-config\";\nimport { importPrismaModelModules } from \"../../../../utils/helpers/models.helpers\";\nimport authService from \"../../../auth/auth.service\";\nimport { BaseController } from \"../../base.controller\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../../base.middlewares\";\nimport { processMiddleware } from \"../../../../utils/helpers/routers.helpers\";\n\nexport function setupRouters(\n models: string[],\n router: Router,\n arkosConfigs: ArkosConfig\n) {\n return models.map(async (model) => {\n const modelNameInKebab = kebabCase(model);\n const modelModules = await importPrismaModelModules(\n modelNameInKebab,\n arkosConfigs\n );\n const {\n middlewares,\n authConfigs,\n prismaQueryOptions,\n router: customRouterModule,\n dtos,\n schemas,\n } = modelModules;\n\n const routeName = pluralize.plural(modelNameInKebab);\n const controller = new BaseController(model);\n\n const routerConfig: RouterConfig = customRouterModule?.config || {};\n\n // Check if custom implementation exists\n const customRouter = (customRouterModule as Router) || {};\n const hasCustomImplementation = (path: string, method: string) => {\n return customRouter.stack?.some(\n (layer) =>\n (layer.path === `/api/${path}` ||\n layer.path === `api/${path}` ||\n layer.path === `api/${path}/` ||\n layer.path === `/api/${path}/`) &&\n layer.method.toLowerCase() === method.toLowerCase()\n );\n };\n\n // Helper to get the correct schema or DTO based on Arkos Config\n const getValidationSchemaOrDto = (key: string) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n // If the custom router has its own routes, add them\n if (customRouterModule?.default && !routerConfig?.disable)\n router.use(`/${routeName}`, customRouterModule.default);\n\n // POST /{routeName} - Create One\n if (\n !isEndpointDisabled(routerConfig, \"createOne\") &&\n !hasCustomImplementation(`/${routeName}`, \"post\")\n ) {\n router.post(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"create\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createOne\"\n ),\n ...processMiddleware(middlewares?.beforeCreateOne),\n controller.createOne,\n ...processMiddleware(middlewares?.afterCreateOne),\n sendResponse\n );\n }\n\n // GET /{routeName} - Find Many\n if (\n !isEndpointDisabled(routerConfig, \"findMany\") &&\n !hasCustomImplementation(`/${routeName}`, \"get\")\n ) {\n router.get(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findMany\"\n ),\n ...processMiddleware(middlewares?.beforeFindMany),\n controller.findMany,\n ...processMiddleware(middlewares?.afterFindMany),\n sendResponse\n );\n }\n\n // POST /{routeName}/many - Create Many\n if (\n !isEndpointDisabled(routerConfig, \"createMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"post\")\n ) {\n router.post(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"createMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createMany\"\n ),\n ...processMiddleware(middlewares?.beforeCreateMany),\n controller.createMany,\n ...processMiddleware(middlewares?.afterCreateMany),\n sendResponse\n );\n }\n\n // PATCH /{routeName}/many - Update Many\n if (\n !isEndpointDisabled(routerConfig, \"updateMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateMany\"\n ),\n ...processMiddleware(middlewares?.beforeUpdateMany),\n controller.updateMany,\n ...processMiddleware(middlewares?.afterUpdateMany),\n sendResponse\n );\n }\n\n // DELETE /{routeName}/many - Delete Many\n if (\n !isEndpointDisabled(routerConfig, \"deleteMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"deleteMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteMany\"\n ),\n ...processMiddleware(middlewares?.beforeDeleteMany),\n controller.deleteMany,\n ...processMiddleware(middlewares?.afterDeleteMany),\n sendResponse\n );\n }\n\n // GET /{routeName}/:id - Find One\n if (\n !isEndpointDisabled(routerConfig, \"findOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"get\")\n ) {\n router.get(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"findOne\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findOne\"\n ),\n ...processMiddleware(middlewares?.beforeFindOne),\n controller.findOne,\n ...processMiddleware(middlewares?.afterFindOne),\n sendResponse\n );\n }\n\n // PATCH /{routeName}/:id - Update One\n if (\n !isEndpointDisabled(routerConfig, \"updateOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"update\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateOne\"\n ),\n ...processMiddleware(middlewares?.beforeUpdateOne),\n controller.updateOne,\n ...processMiddleware(middlewares?.afterUpdateOne),\n sendResponse\n );\n }\n\n // DELETE /{routeName}/:id - Delete One\n if (\n !isEndpointDisabled(routerConfig, \"deleteOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"delete\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteOne\"\n ),\n ...processMiddleware(middlewares?.beforeDeleteOne),\n controller.deleteOne,\n ...processMiddleware(middlewares?.afterDeleteOne),\n sendResponse\n );\n }\n });\n}\n\nexport function isEndpointDisabled(\n routerConfig: RouterConfig,\n endpoint: RouterEndpoint\n): boolean {\n if (!routerConfig?.disable) return false;\n\n if (routerConfig.disable === true) return true;\n\n if (typeof routerConfig.disable === \"object\")\n return routerConfig.disable[endpoint] === true;\n\n return false;\n}\n\nexport function isParentEndpointAllowed(\n routerConfig: any,\n endpoint: string\n): boolean {\n if (!routerConfig?.parent) return false;\n\n const parentEndpoints = routerConfig.parent.endpoints;\n if (parentEndpoints === \"*\") return true;\n if (Array.isArray(parentEndpoints)) return parentEndpoints.includes(endpoint);\n\n return true; // Default to allow if not specified\n}\n"]}
@@ -73,6 +73,8 @@ function errorHandler(err, req, res, next) {
73
73
  error = errorControllerHelper.handleForeignKeyConstraintError(err);
74
74
  if (err.code === "P2004")
75
75
  error = errorControllerHelper.handleConstraintFailedError(err);
76
+ if (err.code === "P2025")
77
+ error = errorControllerHelper.handleNonExistingRecord(err);
76
78
  if (err.code === "P3000")
77
79
  error = errorControllerHelper.handleSchemaCreationFailedError(err);
78
80
  if (err.code === "P3001")
@@ -1 +1 @@
1
- {"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,+BAgEC;AAnFD,kEAAyC;AACzC,qFAAuE;AACvE,yCAAsC;AAiBtC,SAAwB,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;IACvC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC;IAGnC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACpC,OAAO;IACT,CAAC;IAGD,IAAI,KAAK,GAAG,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IAG7C,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB;QAClC,KAAK,GAAG,qBAAqB,CAAC,cAAc,EAAE,CAAC;IACjD,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB;QAClC,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,EAAE,CAAC;IAGnD,IAAI,GAAG,CAAC,IAAI,KAAK,6BAA6B;QAC5C,KAAK,GAAG,qBAAqB,CAAC,iCAAiC,CAAC,GAAG,CAAC,CAAC;IAGvE,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;QACtB,KAAK,GAAG,qBAAqB,CAAC,yBAAyB,CAAC,GAAG,CAAC,C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gBAClB,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE;gBACpB,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,SAAS;aAC5B,CAAC,CAAC;;YAEH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,uBAAuB;aACjC,CAAC,CAAC;QAEL,OAAO;IACT,CAAC;IAED,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;QACtB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;YAC9B,KAAK,EAAE,uBAAuB;YAC9B,OAAO,EAAE,GAAG,CAAC,OAAO;SACrB,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QAC9B,KAAK,EAAE,uBAAuB;QAC9B,OAAO,EAAE,yBAAyB;KACnC,CAAC,CAAC;AACL,CAAC;AAWD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACzB,IACE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,EAClC,CAAC;QACD,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAE3E,eAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} next - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n next: NextFunction\n): void {\n console.error(\"[\\x1b[31mERROR\\x1b[0m]:\", err);\n // Default error status\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n // If the environment is not production, send detailed error information\n if (process.env.NODE_ENV !== \"production\") {\n sendDevelopmentError(err, req, res);\n return;\n }\n\n // Prepare error object for response, copying the original error's properties\n let error = { ...err, message: err.message };\n\n // Handle specific error cases (JWT errors, Prisma validation errors, etc.)\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n // Handle specific Prisma client validation errors\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n\n // Handle Prisma database-specific error codes (P1000 to P3005)\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n if (err.name === \"NetworkError\")\n error = errorControllerHelper.handleNetworkError(err);\n if (!error.isOperational) error = new AppError(\"Something went wrong!\", 500);\n\n // Send the error response for production environment\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(\n err: AppError,\n req: Request,\n res: Response\n): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n ...err,\n message: err.message.split(\"\\n\")[err.message.split(\"\\n\").length - 1],\n stack: err.stack?.split(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Something went wrong!\",\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: \"Please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (\n process.env.NODE_ENV !== \"production\" &&\n process.env.NODE_ENV !== \"staging\"\n ) {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n process.exit();\n });\n }\n});\n"]}
1
+ {"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,+BAkEC;AArFD,kEAAyC;AACzC,qFAAuE;AACvE,yCAAsC;AAiBtC,SAAwB,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;IACvC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC;IAGnC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACpC,OAAO;IACT,CAAC;IAGD,IAAI,KAAK,GAAG,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IAG7C,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB;QAClC,KAAK,GAAG,qBAAqB,CA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;QACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,EAClC,CAAC;QACD,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAE3E,eAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} next - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n next: NextFunction\n): void {\n console.error(\"[\\x1b[31mERROR\\x1b[0m]:\", err);\n // Default error status\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n // If the environment is not production, send detailed error information\n if (process.env.NODE_ENV !== \"production\") {\n sendDevelopmentError(err, req, res);\n return;\n }\n\n // Prepare error object for response, copying the original error's properties\n let error = { ...err, message: err.message };\n\n // Handle specific error cases (JWT errors, Prisma validation errors, etc.)\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n // Handle specific Prisma client validation errors\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n\n // Handle Prisma database-specific error codes (P1000 to P3005)\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P2025\")\n error = errorControllerHelper.handleNonExistingRecord(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n if (err.name === \"NetworkError\")\n error = errorControllerHelper.handleNetworkError(err);\n if (!error.isOperational) error = new AppError(\"Something went wrong!\", 500);\n\n // Send the error response for production environment\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(\n err: AppError,\n req: Request,\n res: Response\n): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n ...err,\n message: err.message.split(\"\\n\")[err.message.split(\"\\n\").length - 1],\n stack: err.stack?.split(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Something went wrong!\",\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: \"Please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (\n process.env.NODE_ENV !== \"production\" &&\n process.env.NODE_ENV !== \"staging\"\n ) {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n process.exit();\n });\n }\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"catch-async.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/catch-async.ts"],"names":[],"mappings":";;AAwBA,MAAM,UAAU,GACd,CAAC,EAAuB,EAAE,EAAE,CAC5B,KAAK,EACH,GAAiB,EACjB,GAAkB,EAClB,IAAuB,EACR,EAAE;IACjB,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAS,CAAC;IAC5C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAEJ,kBAAe,UAAU,CAAC","sourcesContent":["import {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n} from \"../../../types\";\n\n/**\n * Used to wrap request handlers and middleware for automatic catch async errors and throw to next to invoke the global error handler\n *\n * @param {ArkosRequestHandler} fn - an express request handler or middleware that will be called with req, res, next, with catch attached for error handling\n * @returns\n *\n * @example\n * ```typescript\n * import { ArkosRequest, ArkosResponse, ArkosNextFunction } from 'arkos'\n *\n * export const getManyPosts = catchAsync(async\n * (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n * const posts = await getSomePosts()\n * res.status(200).json({ data: posts })\n * })\n * ```\n */\nconst catchAsync =\n (fn: ArkosRequestHandler) =>\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ): Promise<void> => {\n try {\n return (await fn(req, res, next)) as void;\n } catch (err) {\n next(err);\n }\n };\n\nexport default catchAsync;\n"]}
1
+ {"version":3,"file":"catch-async.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/catch-async.ts"],"names":[],"mappings":";;AAwBA,MAAM,UAAU,GACd,CAAC,EAAuB,EAAE,EAAE,CAC5B,KAAK,EACH,GAAiB,EACjB,GAAkB,EAClB,IAAuB,EACR,EAAE;IACjB,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAS,CAAC;IAC5C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAIJ,kBAAe,UAAU,CAAC","sourcesContent":["import {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n} from \"../../../types\";\n\n/**\n * Used to wrap request handlers and middleware for automatic catch async errors and throw to next to invoke the global error handler\n *\n * @param {ArkosRequestHandler} fn - an express request handler or middleware that will be called with req, res, next, with catch attached for error handling\n * @returns\n *\n * @example\n * ```typescript\n * import { ArkosRequest, ArkosResponse, ArkosNextFunction } from 'arkos'\n *\n * export const getManyPosts = catchAsync(async\n * (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n * const posts = await getSomePosts()\n * res.status(200).json({ data: posts })\n * })\n * ```\n */\nconst catchAsync =\n (fn: ArkosRequestHandler) =>\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ): Promise<void> => {\n try {\n return (await fn(req, res, next)) as void;\n } catch (err) {\n next(err);\n }\n };\n\nexport type CatchAsyncReturnType = ReturnType<typeof catchAsync>;\n\nexport default catchAsync;\n"]}
@@ -38,6 +38,7 @@ exports.handleNetworkError = handleNetworkError;
38
38
  exports.handleUnhandledPromiseError = handleUnhandledPromiseError;
39
39
  exports.handleDataTypeError = handleDataTypeError;
40
40
  exports.handleEmptyResultError = handleEmptyResultError;
41
+ exports.handleNonExistingRecord = handleNonExistingRecord;
41
42
  const app_error_1 = __importDefault(require("./app-error"));
42
43
  function handleJWTError() {
43
44
  return new app_error_1.default("Invalid token. Please log in again!", 401);
@@ -192,4 +193,9 @@ function handleEmptyResultError(err) {
192
193
  const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;
193
194
  return new app_error_1.default(message, 404);
194
195
  }
196
+ function handleNonExistingRecord(err) {
197
+ const message = err?.meta?.cause ||
198
+ `Operation could not be completed as the required record was not found`;
199
+ return new app_error_1.default(message, 404, err.meta || {}, "PrismaRecordNotFound");
200
+ }
195
201
  //# sourceMappingURL=error-handler.helpers.js.map