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
@@ -1 +1 @@
1
- {"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router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AAI,YAAY;QAC5D,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC;YACzC,cAAc,CAAC,WAAW,EAAE,WAAW,CAAC;YACtC,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,WAAW,CAAC;YAC1C,CAAC,CAAC,YAAY;QAChB,YAAY;KACb,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CACvC,CAAC;IAEF,MAAM,CAAC,IAAI,CACT,uBAAuB,EACvB,WAAW,CAAC,YAAY,EACxB,4CAA4C,CAC1C,wBAAwB,CAAC,gBAAgB,CAAC,CAC3C,EACD,8BAA8B,CAC5B,kBAAiD,EACjD,gBAAgB,CACjB,EACD,GAAG;QACD,cAAc,CAAC,WAAW,EAAE,oBAAoB,CAAC;YAC/C,cAAc,CAAC,cAAc;QAC/B,cAAc,CAAC,WAAW,EAAE,oBAAoB,CAAC;YAC/C,CAAC,CAAC,cAAc,CAAC,cAAc;YAC/B,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB,CAAC,IAAI,YAAY;QACpE,cAAc,CAAC,WAAW,EAAE,oBAAoB,CAAC;YACjD,cAAc,CAAC,WAAW,EAAE,mBAAmB,CAAC;YAC9C,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB,CAAC;YAClD,CAAC,CAAC,YAAY;QAChB,YAAY;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":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,qBAAqB,EA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AM,CAAC,MAAM,CACX,cAAc,EACd,WAAW,CAAC,YAAY,EACxB,GAAG,iBAAiB,CAAC,WAAW,EAAE,YAAY,CAAC,EAC/C,cAAc,CAAC,MAAM,EACrB,GAAG,iBAAiB,CAAC,WAAW,EAAE,WAAW,CAAC,EAC9C,YAAY,CACb,CAAC;IAEF,MAAM,CAAC,IAAI,CACT,cAAc,EACd,4CAA4C,CAC1C,wBAAwB,CAAC,QAAQ,CAAC,CACnC,EACD,8BAA8B,CAC5B,kBAAiD,EACjD,QAAQ,CACT,EACD,GAAG,iBAAiB,CAAC,WAAW,EAAE,YAAY,CAAC,EAC/C,cAAc,CAAC,MAAM,EACrB,GAAG,iBAAiB,CAAC,WAAW,EAAE,WAAW,CAAC,EAC9C,YAAY,CACb,CAAC;IAEF,MAAM,CAAC,IAAI,CACT,uBAAuB,EACvB,WAAW,CAAC,YAAY,EACxB,4CAA4C,CAC1C,wBAAwB,CAAC,gBAAgB,CAAC,CAC3C,EACD,8BAA8B,CAC5B,kBAAiD,EACjD,gBAAgB,CACjB,EACD,GAAG,iBAAiB,CAAC,WAAW,EAAE,oBAAoB,CAAC,EACvD,cAAc,CAAC,cAAc,EAC7B,GAAG,iBAAiB,CAAC,WAAW,EAAE,mBAAmB,CAAC,EACtD,YAAY,CACb,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 { 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"]}
@@ -4,11 +4,11 @@ import { importPrismaModelModules } from "../../../../utils/helpers/models.helpe
4
4
  import authService from "../../../auth/auth.service.js";
5
5
  import { BaseController } from "../../base.controller.js";
6
6
  import { addPrismaQueryOptionsToRequest, handleRequestBodyValidationAndTransformation, sendResponse, } from "../../base.middlewares.js";
7
- import catchAsync from "../../../error-handler/utils/catch-async.js";
7
+ import { processMiddleware } from "../../../../utils/helpers/routers.helpers.js";
8
8
  export function setupRouters(models, router, arkosConfigs) {
9
9
  return models.map(async (model) => {
10
10
  const modelNameInKebab = kebabCase(model);
11
- const modelModules = await importPrismaModelModules(modelNameInKebab);
11
+ const modelModules = await importPrismaModelModules(modelNameInKebab, arkosConfigs);
12
12
  const { middlewares, authConfigs, prismaQueryOptions, router: customRouterModule, dtos, schemas, } = modelModules;
13
13
  const routeName = pluralize.plural(modelNameInKebab);
14
14
  const controller = new BaseController(model);
@@ -33,121 +33,37 @@ export function setupRouters(models, router, arkosConfigs) {
33
33
  };
34
34
  if (customRouterModule?.default && !routerConfig?.disable)
35
35
  router.use(`/${routeName}`, customRouterModule.default);
36
- function safeCatchAsync(middleware) {
37
- return middleware ? catchAsync(middleware) : undefined;
38
- }
39
36
  if (!isEndpointDisabled(routerConfig, "createOne") &&
40
37
  !hasCustomImplementation(`/${routeName}`, "post")) {
41
- router.post(`/${routeName}`, authService.handleAuthenticationControl("Create", authConfigs?.authenticationControl), authService.handleAccessControl("Create", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("create")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "createOne"), ...[
42
- safeCatchAsync(middlewares?.beforeCreateOne) || controller.createOne,
43
- safeCatchAsync(middlewares?.beforeCreateOne)
44
- ? controller.createOne
45
- : safeCatchAsync(middlewares?.afterCreateOne) || sendResponse,
46
- safeCatchAsync(middlewares?.beforeCreateOne) &&
47
- safeCatchAsync(middlewares?.afterCreateOne)
48
- ? safeCatchAsync(middlewares?.afterCreateOne)
49
- : sendResponse,
50
- ].filter((m) => !!m), sendResponse);
38
+ router.post(`/${routeName}`, authService.handleAuthenticationControl("Create", authConfigs?.authenticationControl), authService.handleAccessControl("Create", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("create")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "createOne"), ...processMiddleware(middlewares?.beforeCreateOne), controller.createOne, ...processMiddleware(middlewares?.afterCreateOne), sendResponse);
51
39
  }
52
40
  if (!isEndpointDisabled(routerConfig, "findMany") &&
53
41
  !hasCustomImplementation(`/${routeName}`, "get")) {
54
- router.get(`/${routeName}`, authService.handleAuthenticationControl("View", authConfigs?.authenticationControl), authService.handleAccessControl("View", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), addPrismaQueryOptionsToRequest(prismaQueryOptions, "findMany"), ...[
55
- safeCatchAsync(middlewares?.beforeFindMany) || controller.findMany,
56
- safeCatchAsync(middlewares?.beforeFindMany)
57
- ? controller.findMany
58
- : safeCatchAsync(middlewares?.afterFindMany) || sendResponse,
59
- safeCatchAsync(middlewares?.beforeFindMany) &&
60
- safeCatchAsync(middlewares?.afterFindMany)
61
- ? safeCatchAsync(middlewares?.afterFindMany)
62
- : sendResponse,
63
- sendResponse,
64
- ].filter((m) => !!m));
42
+ router.get(`/${routeName}`, authService.handleAuthenticationControl("View", authConfigs?.authenticationControl), authService.handleAccessControl("View", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), addPrismaQueryOptionsToRequest(prismaQueryOptions, "findMany"), ...processMiddleware(middlewares?.beforeFindMany), controller.findMany, ...processMiddleware(middlewares?.afterFindMany), sendResponse);
65
43
  }
66
44
  if (!isEndpointDisabled(routerConfig, "createMany") &&
67
45
  !hasCustomImplementation(`/${routeName}/many`, "post")) {
68
- router.post(`/${routeName}/many`, authService.handleAuthenticationControl("Create", authConfigs?.authenticationControl), authService.handleAccessControl("Create", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("createMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "createMany"), ...[
69
- safeCatchAsync(middlewares?.beforeCreateMany) ||
70
- controller.createMany,
71
- safeCatchAsync(middlewares?.beforeCreateMany)
72
- ? controller.createMany
73
- : safeCatchAsync(middlewares?.afterCreateMany) || sendResponse,
74
- safeCatchAsync(middlewares?.beforeCreateMany) &&
75
- safeCatchAsync(middlewares?.afterCreateMany)
76
- ? safeCatchAsync(middlewares?.afterCreateMany)
77
- : sendResponse,
78
- sendResponse,
79
- ].filter((m) => !!m));
46
+ router.post(`/${routeName}/many`, authService.handleAuthenticationControl("Create", authConfigs?.authenticationControl), authService.handleAccessControl("Create", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("createMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "createMany"), ...processMiddleware(middlewares?.beforeCreateMany), controller.createMany, ...processMiddleware(middlewares?.afterCreateMany), sendResponse);
80
47
  }
81
48
  if (!isEndpointDisabled(routerConfig, "updateMany") &&
82
49
  !hasCustomImplementation(`/${routeName}/many`, "patch")) {
83
- router.patch(`/${routeName}/many`, authService.handleAuthenticationControl("Update", authConfigs?.authenticationControl), authService.handleAccessControl("Update", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("updateMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateMany"), ...[
84
- safeCatchAsync(middlewares?.beforeUpdateMany) ||
85
- controller.updateMany,
86
- safeCatchAsync(middlewares?.beforeUpdateMany)
87
- ? controller.updateMany
88
- : safeCatchAsync(middlewares?.afterUpdateMany) || sendResponse,
89
- safeCatchAsync(middlewares?.beforeUpdateMany) &&
90
- safeCatchAsync(middlewares?.afterUpdateMany)
91
- ? safeCatchAsync(middlewares?.afterUpdateMany)
92
- : sendResponse,
93
- sendResponse,
94
- ].filter((m) => !!m));
50
+ router.patch(`/${routeName}/many`, authService.handleAuthenticationControl("Update", authConfigs?.authenticationControl), authService.handleAccessControl("Update", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("updateMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateMany"), ...processMiddleware(middlewares?.beforeUpdateMany), controller.updateMany, ...processMiddleware(middlewares?.afterUpdateMany), sendResponse);
95
51
  }
96
52
  if (!isEndpointDisabled(routerConfig, "deleteMany") &&
97
53
  !hasCustomImplementation(`/${routeName}/many`, "delete")) {
98
- router.delete(`/${routeName}/many`, authService.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), authService.handleAccessControl("Delete", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("deleteMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteMany"), ...[
99
- safeCatchAsync(middlewares?.beforeDeleteMany) ||
100
- controller.deleteMany,
101
- safeCatchAsync(middlewares?.beforeDeleteMany)
102
- ? controller.deleteMany
103
- : safeCatchAsync(middlewares?.afterDeleteMany) || sendResponse,
104
- safeCatchAsync(middlewares?.beforeDeleteMany) &&
105
- safeCatchAsync(middlewares?.afterDeleteMany)
106
- ? safeCatchAsync(middlewares?.afterDeleteMany)
107
- : sendResponse,
108
- sendResponse,
109
- ].filter((middleware) => !!middleware));
54
+ router.delete(`/${routeName}/many`, authService.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), authService.handleAccessControl("Delete", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("deleteMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteMany"), ...processMiddleware(middlewares?.beforeDeleteMany), controller.deleteMany, ...processMiddleware(middlewares?.afterDeleteMany), sendResponse);
110
55
  }
111
56
  if (!isEndpointDisabled(routerConfig, "findOne") &&
112
57
  !hasCustomImplementation(`/${routeName}/:id`, "get")) {
113
- router.get(`/${routeName}/:id`, authService.handleAuthenticationControl("View", authConfigs?.authenticationControl), authService.handleAccessControl("View", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("findOne")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "findOne"), ...[
114
- safeCatchAsync(middlewares?.beforeFindOne) || controller.findOne,
115
- safeCatchAsync(middlewares?.beforeFindOne)
116
- ? controller.findOne
117
- : safeCatchAsync(middlewares?.afterFindOne) || sendResponse,
118
- safeCatchAsync(middlewares?.beforeFindOne) &&
119
- safeCatchAsync(middlewares?.afterFindOne)
120
- ? safeCatchAsync(middlewares?.afterFindOne)
121
- : sendResponse,
122
- sendResponse,
123
- ].filter((m) => !!m));
58
+ router.get(`/${routeName}/:id`, authService.handleAuthenticationControl("View", authConfigs?.authenticationControl), authService.handleAccessControl("View", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("findOne")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "findOne"), ...processMiddleware(middlewares?.beforeFindOne), controller.findOne, ...processMiddleware(middlewares?.afterFindOne), sendResponse);
124
59
  }
125
60
  if (!isEndpointDisabled(routerConfig, "updateOne") &&
126
61
  !hasCustomImplementation(`/${routeName}/:id`, "patch")) {
127
- router.patch(`/${routeName}/:id`, authService.handleAuthenticationControl("Update", authConfigs?.authenticationControl), authService.handleAccessControl("Update", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("update")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateOne"), ...[
128
- safeCatchAsync(middlewares?.beforeUpdateOne) || controller.updateOne,
129
- safeCatchAsync(middlewares?.beforeUpdateOne)
130
- ? controller.updateOne
131
- : safeCatchAsync(middlewares?.afterUpdateOne) || sendResponse,
132
- safeCatchAsync(middlewares?.beforeUpdateOne) &&
133
- safeCatchAsync(middlewares?.afterUpdateOne)
134
- ? safeCatchAsync(middlewares?.afterUpdateOne)
135
- : sendResponse,
136
- ].filter((m) => !!m), sendResponse);
62
+ router.patch(`/${routeName}/:id`, authService.handleAuthenticationControl("Update", authConfigs?.authenticationControl), authService.handleAccessControl("Update", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("update")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateOne"), ...processMiddleware(middlewares?.beforeUpdateOne), controller.updateOne, ...processMiddleware(middlewares?.afterUpdateOne), sendResponse);
137
63
  }
138
64
  if (!isEndpointDisabled(routerConfig, "deleteOne") &&
139
65
  !hasCustomImplementation(`/${routeName}/:id`, "delete")) {
140
- router.delete(`/${routeName}/:id`, authService.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), authService.handleAccessControl("Delete", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("delete")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteOne"), ...[
141
- safeCatchAsync(middlewares?.beforeDeleteOne) || controller.deleteOne,
142
- safeCatchAsync(middlewares?.beforeDeleteOne)
143
- ? controller.deleteOne
144
- : safeCatchAsync(middlewares?.afterDeleteOne) || sendResponse,
145
- safeCatchAsync(middlewares?.beforeDeleteOne) &&
146
- safeCatchAsync(middlewares?.afterDeleteOne)
147
- ? safeCatchAsync(middlewares?.afterDeleteOne)
148
- : sendResponse,
149
- sendResponse,
150
- ].filter((m) => !!m));
66
+ router.delete(`/${routeName}/:id`, authService.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), authService.handleAccessControl("Delete", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("delete")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteOne"), ...processMiddleware(middlewares?.beforeDeleteOne), controller.deleteOne, ...processMiddleware(middlewares?.afterDeleteOne), sendResponse);
151
67
  }
152
68
  });
153
69
  }
@@ -1 +1 @@
1
- {"version":3,"file":"base.router.helpers.js","sourceRoot":"","sources":["../../../../../../src/modules/base/utils/helpers/base.router.helpers.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGtD,OAAO,EAAE,w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C;oBAC7C,CAAC,CAAC,YAAY;gBAChB,YAAY;aACb,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CACrB,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,YAA0B,EAC1B,QAAwB;IAExB,IAAI,CAAC,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,MAAM,UAAU,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":"","sources":["../../../../../../src/modules/base/utils/helpers/base.router.helpers.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,WAAW,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,8BAA8B,EAC9B,4CAA4C,EAC5C,YAAY,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAE9E,MAAM,UAAU,YAAY,CAC1B,MAAgB,EAChB,MAAc,EACd,YAAyB;IAEzB,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAChC,MAAM,gBAAgB,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,MAAM,wBAAwB,CACjD,gBAAgB,EAChB,YAAY,CACb,CAAC;QACF,MAAM,EACJ,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EACJ,OAAO,GACR,G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E,CACjC,EACD,4CAA4C,CAC1C,wBAAwB,CAAC,QAAQ,CAAC,CACnC,EACD,8BAA8B,CAC5B,kBAA6C,EAC7C,WAAW,CACZ,EACD,GAAG,iBAAiB,CAAC,WAAW,EAAE,eAAe,CAAC,EAClD,UAAU,CAAC,SAAS,EACpB,GAAG,iBAAiB,CAAC,WAAW,EAAE,cAAc,CAAC,EACjD,YAAY,CACb,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,YAA0B,EAC1B,QAAwB;IAExB,IAAI,CAAC,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,MAAM,UAAU,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"]}
@@ -34,6 +34,8 @@ export default function errorHandler(err, req, res, next) {
34
34
  error = errorControllerHelper.handleForeignKeyConstraintError(err);
35
35
  if (err.code === "P2004")
36
36
  error = errorControllerHelper.handleConstraintFailedError(err);
37
+ if (err.code === "P2025")
38
+ error = errorControllerHelper.handleNonExistingRecord(err);
37
39
  if (err.code === "P3000")
38
40
  error = errorControllerHelper.handleSchemaCreationFailedError(err);
39
41
  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":"AACA,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,qBAAqB,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC,MAAM,CAAC,OAAO,UAAU,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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AG,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,MAAM,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":"AACA,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,qBAAqB,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAA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AG,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,MAAM,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,eAAe,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,eAAe,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"]}
@@ -152,4 +152,9 @@ export function handleEmptyResultError(err) {
152
152
  const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;
153
153
  return new AppError(message, 404);
154
154
  }
155
+ export function handleNonExistingRecord(err) {
156
+ const message = err?.meta?.cause ||
157
+ `Operation could not be completed as the required record was not found`;
158
+ return new AppError(message, 404, err.meta || {}, "PrismaRecordNotFound");
159
+ }
155
160
  //# sourceMappingURL=error-handler.helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-handler.helpers.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/error-handler.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,aAAa,CAAC;AASnC,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,QAAQ,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,QAAQ,CAAC,2CAA2C,EAAE,GAAG,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAAC,GAAa;IAC7D,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9E,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,GAAa;IACrD,MAAM,OAAO,GACX,mFAAmF,CAAC;IACtF,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,GAAa;IACzD,MAAM,OAAO,GACX,qGAAqG,CAAC;IACxG,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,GAAa;IACxD,MAAM,OAAO,GACX,gGAAgG,CAAC;IACnG,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,GAAa;IACvD,MAAM,OAAO,GAAG,sDAAsD,CAAC;IACvE,OAAO,IAAI,QAAQ,CAAC,OAA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,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,GAAa;IACvD,MAAM,OAAO,GAAG,iGAAiG,CAAC;IAClH,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,GAAa;IAC/C,MAAM,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,KAAK,IAAI,eAAe,CAAC;IAClD,MAAM,YAAY,GAAG,GAAG,EAAE,IAAI,EAAE,aAAa,IAAI,cAAc,CAAC;IAChE,MAAM,OAAO,GAAG,gCAAgC,KAAK,qBAAqB,YAAY,GAAG,CAAC;IAC1F,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAa;IAClD,MAAM,OAAO,GAAG,6FAA6F,CAAC;IAC9G,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import AppError from \"./app-error\";\n\nexport interface PrismaError {\n code?: string; // Prisma-specific error code\n message: string; // Error message\n meta?: Record<string, any>; // Metadata provided by Prisma\n name?: string; // Error name\n}\n\nexport function handleJWTError() {\n return new AppError(\"Invalid token. Please log in again!\", 401);\n}\n\nexport function handleJWTExpired() {\n return new AppError(\"Your token has expired, Please log again!\", 401);\n}\n\nexport function handlePrismaClientValidationError(err: AppError) {\n const message = err?.message.split(\"\\n\")[err?.message.split(\"\\n\").length - 1];\n return new AppError(message, 400);\n}\n\nexport function handleAuthenticationError(err: AppError) {\n const message =\n \"Authentication failed against the database server. Please check your credentials.\";\n return new AppError(message, 401);\n}\n\nexport function handleServerNotReachableError(err: AppError) {\n const message =\n \"The database server is not reachable. Verify your connection string or ensure the server is online.\";\n return new AppError(message, 503);\n}\n\nexport function handleConnectionTimeoutError(err: AppError) {\n const message =\n \"Connection to the database timed out. Please check server performance or network connectivity.\";\n return new AppError(message, 504);\n}\n\nexport function handleDatabaseNotFoundError(err: AppError) {\n const message = \"The specified database does not exist on the server.\";\n return new AppError(message, 404);\n}\n\nexport function handleEnvironmentVariableError(err: AppError) {\n const missingVars = err?.missing || \"unknown environment variables\";\n const message = `Missing or invalid environment variables: ${missingVars}. Please check your configuration.`;\n return new AppError(message, 500);\n}\n\nexport function handleFieldValueTooLargeError(err: AppError) {\n const message = `The value for the field \"${err?.meta?.field_name}\" is too large. Please provide a smaller value.`;\n return new AppError(message, 400);\n}\n\nexport function handleRecordNotFoundError(err: AppError) {\n const message =\n \"No record found for the given query. Ensure the query parameters are correct.\";\n return new AppError(message, 404);\n}\n\nexport function handleUniqueConstraintError(err: AppError) {\n const field = err?.meta?.target || \"unknown field\";\n const message = `Duplicate value detected for the unique field(s): ${field}. Please use a different value.`;\n return new AppError(message, 409);\n}\n\nexport function handleForeignKeyConstraintError(err: AppError) {\n const message =\n \"Foreign key constraint violation. Ensure that the referenced record exists.\";\n return new AppError(message, 400);\n}\n\nexport function handleConstraintFailedError(err: AppError) {\n const constraint = err?.meta?.constraint || \"unknown constraint\";\n const message = `A database constraint \"${constraint}\" failed. Please review your input data.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldValueError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `Invalid value provided for the field \"${fieldName}\". Please provide a valid value.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldProvidedError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" has been provided with an invalid value. Check the data and try again.`;\n return new AppError(message, 400);\n}\n\nexport function handleDataValidationError(err: AppError) {\n const message =\n \"Data validation error occurred. Please ensure all fields meet the required criteria.\";\n return new AppError(message, 400);\n}\n\nexport function handleQueryParsingError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `Failed to parse the query: \"${query}\". Check the syntax and structure.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidQueryFormatError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `The query format is invalid: \"${query}\". Ensure the query adheres to the expected format.`;\n return new AppError(message, 400);\n}\n\nexport function handleRawQueryExecutionError(err: AppError) {\n const message =\n \"An error occurred during the execution of a raw query. Verify the query and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleNullConstraintViolationError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" cannot be null. Please provide a value.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaCreationFailedError(err: AppError) {\n const message =\n \"Failed to create the database schema. Verify the schema definition and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleMigrationAlreadyAppliedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration \"${migrationName}\" has already been applied to the database.`;\n return new AppError(message, 409);\n}\n\nexport function handleMigrationScriptFailedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration script \"${migrationName}\" failed. Review the script and resolve any issues.`;\n return new AppError(message, 500);\n}\n\nexport function handleVersionMismatchError(err: AppError) {\n const message = `Version mismatch: The database schema and migration versions are inconsistent. Please check and resolve this issue.`;\n return new AppError(message, 400);\n}\n\nexport function handleMigrationFileReadError(err: AppError) {\n const migrationFile = err?.meta?.migration_file || \"unknown file\";\n const message = `Failed to read the migration file \"${migrationFile}\". Ensure the file exists and is accessible.`;\n return new AppError(message, 500);\n}\n\nexport function handleSchemaDriftError(err: AppError) {\n const message = `Schema drift detected: The database schema differs from the expected state. Run migrations or sync schema to resolve.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaSyntaxError(err: AppError) {\n const message = `Syntax error in the schema file. Please check for typos or invalid syntax in your schema definition.`;\n return new AppError(message, 500);\n}\n\nexport function handleClientTypeError(err: AppError) {\n const message = `Type error, Ensure proper usage of methods and correct data types.`;\n return new AppError(message, 400);\n}\n\nexport function handleDynamicQueryError(err: AppError) {\n const message = `Error constructing or executing a dynamic query. Verify query structure and parameters.`;\n return new AppError(message, 400);\n}\n\nexport function handleRelationLoadingError(err: AppError) {\n const relation = err?.meta?.relation || \"unknown relation\";\n const message = `Error loading relation \"${relation}\". Ensure it is correctly defined and included in the query.`;\n return new AppError(message, 400);\n}\n\nexport function handleBinaryError(err: AppError) {\n const binaryName = err?.meta?.binary || \"unknown binary\";\n const message = `Error with Prisma binary \"${binaryName}\". Ensure the binary is properly installed and compatible.`;\n return new AppError(message, 500);\n}\n\nexport function handleNetworkError(err: AppError) {\n const message = `Network error: Unable to connect to the database or internet. Please check your network connection.`;\n return new AppError(message, 500);\n}\n\nexport function handleUnhandledPromiseError(err: AppError) {\n const message = `Unhandled promise rejection detected. Please check asynchronous code for proper error handling.`;\n return new AppError(message, 500);\n}\n\nexport function handleDataTypeError(err: AppError) {\n const field = err?.meta?.field || \"unknown field\";\n const expectedType = err?.meta?.expected_type || \"unknown type\";\n const message = `Invalid data type for field \"${field}\". Expected type: ${expectedType}.`;\n return new AppError(message, 400);\n}\n\nexport function handleEmptyResultError(err: AppError) {\n const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;\n return new AppError(message, 404);\n}\n"]}
1
+ {"version":3,"file":"error-handler.helpers.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/error-handler.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,aAAa,CAAC;AASnC,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,QAAQ,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,QAAQ,CAAC,2CAA2C,EAAE,GAAG,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAAC,GAAa;IAC7D,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,IA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,6FAA6F,CAAC;IAC9G,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,GAGvC;IACC,MAAM,OAAO,GACX,GAAG,EAAE,IAAI,EAAE,KAAK;QAChB,uEAAuE,CAAC;IAC1E,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,sBAAsB,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import AppError from \"./app-error\";\n\nexport interface PrismaError {\n code?: string; // Prisma-specific error code\n message: string; // Error message\n meta?: Record<string, any>; // Metadata provided by Prisma\n name?: string; // Error name\n}\n\nexport function handleJWTError() {\n return new AppError(\"Invalid token. Please log in again!\", 401);\n}\n\nexport function handleJWTExpired() {\n return new AppError(\"Your token has expired, Please log again!\", 401);\n}\n\nexport function handlePrismaClientValidationError(err: AppError) {\n const message = err?.message.split(\"\\n\")[err?.message.split(\"\\n\").length - 1];\n return new AppError(message, 400);\n}\n\nexport function handleAuthenticationError(err: AppError) {\n const message =\n \"Authentication failed against the database server. Please check your credentials.\";\n return new AppError(message, 401);\n}\n\nexport function handleServerNotReachableError(err: AppError) {\n const message =\n \"The database server is not reachable. Verify your connection string or ensure the server is online.\";\n return new AppError(message, 503);\n}\n\nexport function handleConnectionTimeoutError(err: AppError) {\n const message =\n \"Connection to the database timed out. Please check server performance or network connectivity.\";\n return new AppError(message, 504);\n}\n\nexport function handleDatabaseNotFoundError(err: AppError) {\n const message = \"The specified database does not exist on the server.\";\n return new AppError(message, 404);\n}\n\nexport function handleEnvironmentVariableError(err: AppError) {\n const missingVars = err?.missing || \"unknown environment variables\";\n const message = `Missing or invalid environment variables: ${missingVars}. Please check your configuration.`;\n return new AppError(message, 500);\n}\n\nexport function handleFieldValueTooLargeError(err: AppError) {\n const message = `The value for the field \"${err?.meta?.field_name}\" is too large. Please provide a smaller value.`;\n return new AppError(message, 400);\n}\n\nexport function handleRecordNotFoundError(err: AppError) {\n const message =\n \"No record found for the given query. Ensure the query parameters are correct.\";\n return new AppError(message, 404);\n}\n\nexport function handleUniqueConstraintError(err: AppError) {\n const field = err?.meta?.target || \"unknown field\";\n const message = `Duplicate value detected for the unique field(s): ${field}. Please use a different value.`;\n return new AppError(message, 409);\n}\n\nexport function handleForeignKeyConstraintError(err: AppError) {\n const message =\n \"Foreign key constraint violation. Ensure that the referenced record exists.\";\n return new AppError(message, 400);\n}\n\nexport function handleConstraintFailedError(err: AppError) {\n const constraint = err?.meta?.constraint || \"unknown constraint\";\n const message = `A database constraint \"${constraint}\" failed. Please review your input data.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldValueError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `Invalid value provided for the field \"${fieldName}\". Please provide a valid value.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldProvidedError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" has been provided with an invalid value. Check the data and try again.`;\n return new AppError(message, 400);\n}\n\nexport function handleDataValidationError(err: AppError) {\n const message =\n \"Data validation error occurred. Please ensure all fields meet the required criteria.\";\n return new AppError(message, 400);\n}\n\nexport function handleQueryParsingError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `Failed to parse the query: \"${query}\". Check the syntax and structure.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidQueryFormatError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `The query format is invalid: \"${query}\". Ensure the query adheres to the expected format.`;\n return new AppError(message, 400);\n}\n\nexport function handleRawQueryExecutionError(err: AppError) {\n const message =\n \"An error occurred during the execution of a raw query. Verify the query and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleNullConstraintViolationError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" cannot be null. Please provide a value.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaCreationFailedError(err: AppError) {\n const message =\n \"Failed to create the database schema. Verify the schema definition and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleMigrationAlreadyAppliedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration \"${migrationName}\" has already been applied to the database.`;\n return new AppError(message, 409);\n}\n\nexport function handleMigrationScriptFailedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration script \"${migrationName}\" failed. Review the script and resolve any issues.`;\n return new AppError(message, 500);\n}\n\nexport function handleVersionMismatchError(err: AppError) {\n const message = `Version mismatch: The database schema and migration versions are inconsistent. Please check and resolve this issue.`;\n return new AppError(message, 400);\n}\n\nexport function handleMigrationFileReadError(err: AppError) {\n const migrationFile = err?.meta?.migration_file || \"unknown file\";\n const message = `Failed to read the migration file \"${migrationFile}\". Ensure the file exists and is accessible.`;\n return new AppError(message, 500);\n}\n\nexport function handleSchemaDriftError(err: AppError) {\n const message = `Schema drift detected: The database schema differs from the expected state. Run migrations or sync schema to resolve.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaSyntaxError(err: AppError) {\n const message = `Syntax error in the schema file. Please check for typos or invalid syntax in your schema definition.`;\n return new AppError(message, 500);\n}\n\nexport function handleClientTypeError(err: AppError) {\n const message = `Type error, Ensure proper usage of methods and correct data types.`;\n return new AppError(message, 400);\n}\n\nexport function handleDynamicQueryError(err: AppError) {\n const message = `Error constructing or executing a dynamic query. Verify query structure and parameters.`;\n return new AppError(message, 400);\n}\n\nexport function handleRelationLoadingError(err: AppError) {\n const relation = err?.meta?.relation || \"unknown relation\";\n const message = `Error loading relation \"${relation}\". Ensure it is correctly defined and included in the query.`;\n return new AppError(message, 400);\n}\n\nexport function handleBinaryError(err: AppError) {\n const binaryName = err?.meta?.binary || \"unknown binary\";\n const message = `Error with Prisma binary \"${binaryName}\". Ensure the binary is properly installed and compatible.`;\n return new AppError(message, 500);\n}\n\nexport function handleNetworkError(err: AppError) {\n const message = `Network error: Unable to connect to the database or internet. Please check your network connection.`;\n return new AppError(message, 500);\n}\n\nexport function handleUnhandledPromiseError(err: AppError) {\n const message = `Unhandled promise rejection detected. Please check asynchronous code for proper error handling.`;\n return new AppError(message, 500);\n}\n\nexport function handleDataTypeError(err: AppError) {\n const field = err?.meta?.field || \"unknown field\";\n const expectedType = err?.meta?.expected_type || \"unknown type\";\n const message = `Invalid data type for field \"${field}\". Expected type: ${expectedType}.`;\n return new AppError(message, 400);\n}\n\nexport function handleEmptyResultError(err: AppError) {\n const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;\n return new AppError(message, 404);\n}\n\nexport function handleNonExistingRecord(err: {\n meta?: Record<string, any>;\n [x: string]: any;\n}) {\n const message =\n err?.meta?.cause ||\n `Operation could not be completed as the required record was not found`;\n return new AppError(message, 404, err.meta || {}, \"PrismaRecordNotFound\");\n}\n"]}
@@ -6,9 +6,12 @@ import path from "path";
6
6
  import express from "express";
7
7
  import deepmerge from "../../utils/helpers/deepmerge.helper.js";
8
8
  import { sendResponse } from "../base/base.middlewares.js";
9
+ import { processMiddleware } from "../../utils/helpers/routers.helpers.js";
10
+ import { adjustRequestUrl } from "./utils/helpers/file-upload.helpers.js";
9
11
  const router = Router();
10
- export async function getFileUploadRouter({ fileUpload }) {
11
- const modelModules = await importPrismaModelModules("file-upload");
12
+ export async function getFileUploadRouter(arkosConfig) {
13
+ const { fileUpload } = arkosConfig;
14
+ const modelModules = await importPrismaModelModules("file-upload", arkosConfig);
12
15
  let { middlewares = {}, authConfigs = {} } = {};
13
16
  if (modelModules) {
14
17
  ({ middlewares = {}, authConfigs = {} } = modelModules);
@@ -18,10 +21,7 @@ export async function getFileUploadRouter({ fileUpload }) {
18
21
  basePathname = "/" + basePathname;
19
22
  if (!basePathname.endsWith("/"))
20
23
  basePathname = basePathname + "/";
21
- router.get(`${basePathname}*`, authService.handleAuthenticationControl("View", authConfigs.authenticationControl), authService.handleAccessControl("View", "file-upload", authConfigs.accessControl), ...(middlewares?.beforeFindFile ? [middlewares?.beforeFindFile] : []), (req, res, next) => {
22
- req.url = req.url.replace(basePathname, "/");
23
- next();
24
- }, express.static(path.resolve(process.cwd(), fileUpload?.baseUploadDir || "uploads"), deepmerge({
24
+ router.get(`${basePathname}*`, authService.handleAuthenticationControl("View", authConfigs.authenticationControl), authService.handleAccessControl("View", "file-upload", authConfigs.accessControl), ...processMiddleware(middlewares?.beforeFindFile), adjustRequestUrl, express.static(path.resolve(process.cwd(), fileUpload?.baseUploadDir || "uploads"), deepmerge({
25
25
  maxAge: "1y",
26
26
  etag: true,
27
27
  lastModified: true,
@@ -30,21 +30,9 @@ export async function getFileUploadRouter({ fileUpload }) {
30
30
  index: false,
31
31
  cacheControl: true,
32
32
  }, fileUpload?.expressStaticOptions || {})));
33
- router.post(`${basePathname}:fileType`, authService.handleAuthenticationControl("Create", authConfigs.authenticationControl), authService.handleAccessControl("Create", "file-upload", authConfigs.accessControl), middlewares?.beforeUploadFile || fileUploadController.uploadFile, middlewares?.beforeUploadFile
34
- ? fileUploadController.uploadFile
35
- : middlewares?.afterUploadFile || sendResponse, middlewares?.beforeUploadFile && middlewares?.afterUploadFile
36
- ? middlewares?.afterUploadFile
37
- : sendResponse, sendResponse);
38
- router.patch(`${basePathname}:fileType/:fileName`, authService.handleAuthenticationControl("Update", authConfigs.authenticationControl), authService.handleAccessControl("Update", "file-upload", authConfigs.accessControl), middlewares?.beforeUpdateFile || fileUploadController.updateFile, middlewares?.beforeUpdateFile
39
- ? fileUploadController.updateFile
40
- : middlewares?.afterUpdateFile || sendResponse, middlewares?.beforeUpdateFile && middlewares?.afterUpdateFile
41
- ? middlewares?.afterUpdateFile
42
- : sendResponse, sendResponse);
43
- router.delete(`${basePathname}:fileType/:fileName`, authService.handleAuthenticationControl("Delete", authConfigs.authenticationControl), authService.handleAccessControl("Delete", "file-upload", authConfigs.accessControl), middlewares?.beforeDeleteFile || fileUploadController.deleteFile, middlewares?.beforeDeleteFile
44
- ? fileUploadController.deleteFile
45
- : middlewares?.afterDeleteFile || sendResponse, middlewares?.beforeDeleteFile && middlewares?.afterDeleteFile
46
- ? middlewares?.afterDeleteFile
47
- : sendResponse, sendResponse);
33
+ router.post(`${basePathname}:fileType`, authService.handleAuthenticationControl("Create", authConfigs.authenticationControl), authService.handleAccessControl("Create", "file-upload", authConfigs.accessControl), ...processMiddleware(middlewares?.beforeUploadFile), fileUploadController.uploadFile, ...processMiddleware(middlewares?.afterUploadFile), sendResponse);
34
+ router.patch(`${basePathname}:fileType/:fileName`, authService.handleAuthenticationControl("Update", authConfigs.authenticationControl), authService.handleAccessControl("Update", "file-upload", authConfigs.accessControl), ...processMiddleware(middlewares?.beforeUpdateFile), fileUploadController.updateFile, ...processMiddleware(middlewares?.afterUpdateFile), sendResponse);
35
+ router.delete(`${basePathname}:fileType/:fileName`, authService.handleAuthenticationControl("Delete", authConfigs.authenticationControl), authService.handleAccessControl("Delete", "file-upload", authConfigs.accessControl), ...processMiddleware(middlewares?.beforeDeleteFile), fileUploadController.deleteFile, ...processMiddleware(middlewares?.afterDeleteFile), sendResponse);
48
36
  return router;
49
37
  }
50
38
  //# sourceMappingURL=file-upload.router.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-upload.router.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAE5D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,MAAM,MAAM,GAAW,MAAM,EA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YAAY,CACb,CAAC;IAGF,MAAM,CAAC,MAAM,CACX,GAAG,YAAY,qBAAqB,EACpC,WAAW,CAAC,2BAA2B,CACrC,QAAQ,EACR,WAAW,CAAC,qBAAqB,CAClC,EACD,WAAW,CAAC,mBAAmB,CAC7B,QAAQ,EACR,aAAa,EACb,WAAW,CAAC,aAAa,CAC1B,EACD,WAAW,EAAE,gBAAgB,IAAI,oBAAoB,CAAC,UAAU,EAChE,WAAW,EAAE,gBAAgB;QAC3B,CAAC,CAAC,oBAAoB,CAAC,UAAU;QACjC,CAAC,CAAC,WAAW,EAAE,eAAe,IAAI,YAAY,EAChD,WAAW,EAAE,gBAAgB,IAAI,WAAW,EAAE,eAAe;QAC3D,CAAC,CAAC,WAAW,EAAE,eAAe;QAC9B,CAAC,CAAC,YAAY,EAChB,YAAY,CACb,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { importPrismaModelModules } from \"../../utils/helpers/models.helpers\";\nimport authService from \"../auth/auth.service\";\nimport fileUploadController from \"./file-upload.controller\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport path from \"path\";\nimport express from \"express\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthConfigs } from \"../../types/auth\";\nimport { sendResponse } from \"../base/base.middlewares\";\n\nconst router: Router = Router();\n\nexport async function getFileUploadRouter({ fileUpload }: ArkosConfig) {\n const modelModules = await importPrismaModelModules(\"file-upload\");\n let { middlewares = {} as any, authConfigs = {} as AuthConfigs } = {};\n\n if (modelModules) {\n ({ middlewares = {}, authConfigs = {} } = modelModules);\n }\n\n let basePathname = fileUpload?.baseRoute || \"/api/uploads/\";\n\n if (!basePathname.startsWith(\"/\")) basePathname = \"/\" + basePathname;\n if (!basePathname.endsWith(\"/\")) basePathname = basePathname + \"/\";\n\n // Static file serving route\n router.get(\n `${basePathname}*`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...(middlewares?.beforeFindFile ? [middlewares?.beforeFindFile] : []),\n (req, res, next) => {\n req.url = req.url.replace(basePathname, \"/\");\n next();\n },\n express.static(\n path.resolve(process.cwd(), fileUpload?.baseUploadDir || \"uploads\"),\n deepmerge(\n {\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: true,\n index: false,\n cacheControl: true,\n },\n fileUpload?.expressStaticOptions || {}\n )\n )\n );\n\n // POST /{basePathname}:fileType - Upload File\n router.post(\n `${basePathname}:fileType`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n middlewares?.beforeUploadFile || fileUploadController.uploadFile,\n middlewares?.beforeUploadFile\n ? fileUploadController.uploadFile\n : middlewares?.afterUploadFile || sendResponse,\n middlewares?.beforeUploadFile && middlewares?.afterUploadFile\n ? middlewares?.afterUploadFile\n : sendResponse,\n sendResponse\n );\n\n // PATCH /{basePathname}:fileType/:fileName - Update File\n router.patch(\n `${basePathname}:fileType/:fileName`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n middlewares?.beforeUpdateFile || fileUploadController.updateFile,\n middlewares?.beforeUpdateFile\n ? fileUploadController.updateFile\n : middlewares?.afterUpdateFile || sendResponse,\n middlewares?.beforeUpdateFile && middlewares?.afterUpdateFile\n ? middlewares?.afterUpdateFile\n : sendResponse,\n sendResponse\n );\n\n // DELETE /{basePathname}:fileType/:fileName - Delete File\n router.delete(\n `${basePathname}:fileType/:fileName`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n middlewares?.beforeDeleteFile || fileUploadController.deleteFile,\n middlewares?.beforeDeleteFile\n ? fileUploadController.deleteFile\n : middlewares?.afterDeleteFile || sendResponse,\n middlewares?.beforeDeleteFile && middlewares?.afterDeleteFile\n ? middlewares?.afterDeleteFile\n : sendResponse,\n sendResponse\n );\n\n return router;\n}\n"]}
1
+ {"version":3,"file":"file-upload.router.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAE5D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,MAAM,MAAM,GAAW,MAAM,EAAE,CAAC;AAEhC,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,WAAwB;IAChE,MAAM,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;IAEnC,MAAM,YAAY,GAAG,MAAM,wBAAwB,CACjD,aAAa,EACb,WAAW,CACZ,CAAC;IACF,IAAI,EAAE,WAAW,GAAG,EAAS,EAAE,WAAW,GAAG,EAAiB,EAAE,GAAG,EAAE,CAAC;IAEtE,IAAI,YAAY,EAAE,CAAC;QACjB,CAAC,EAAE,WAAW,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,YAAY,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,YAAY,GAAG,UAAU,EAAE,SAAS,IAAI,eAAe,CAAC;IAE5D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W,CAAC,2BAA2B,CACrC,QAAQ,EACR,WAAW,CAAC,qBAAqB,CAClC,EACD,WAAW,CAAC,mBAAmB,CAC7B,QAAQ,EACR,aAAa,EACb,WAAW,CAAC,aAAa,CAC1B,EACD,GAAG,iBAAiB,CAAC,WAAW,EAAE,gBAAgB,CAAC,EACnD,oBAAoB,CAAC,UAAU,EAC/B,GAAG,iBAAiB,CAAC,WAAW,EAAE,eAAe,CAAC,EAClD,YAAY,CACb,CAAC;IAGF,MAAM,CAAC,MAAM,CACX,GAAG,YAAY,qBAAqB,EACpC,WAAW,CAAC,2BAA2B,CACrC,QAAQ,EACR,WAAW,CAAC,qBAAqB,CAClC,EACD,WAAW,CAAC,mBAAmB,CAC7B,QAAQ,EACR,aAAa,EACb,WAAW,CAAC,aAAa,CAC1B,EACD,GAAG,iBAAiB,CAAC,WAAW,EAAE,gBAAgB,CAAC,EACnD,oBAAoB,CAAC,UAAU,EAC/B,GAAG,iBAAiB,CAAC,WAAW,EAAE,eAAe,CAAC,EAClD,YAAY,CACb,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { importPrismaModelModules } from \"../../utils/helpers/models.helpers\";\nimport authService from \"../auth/auth.service\";\nimport fileUploadController from \"./file-upload.controller\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport path from \"path\";\nimport express from \"express\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthConfigs } from \"../../types/auth\";\nimport { sendResponse } from \"../base/base.middlewares\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\nimport { adjustRequestUrl } from \"./utils/helpers/file-upload.helpers\";\n\nconst router: Router = Router();\n\nexport async function getFileUploadRouter(arkosConfig: ArkosConfig) {\n const { fileUpload } = arkosConfig;\n\n const modelModules = await importPrismaModelModules(\n \"file-upload\",\n arkosConfig\n );\n let { middlewares = {} as any, authConfigs = {} as AuthConfigs } = {};\n\n if (modelModules) {\n ({ middlewares = {}, authConfigs = {} } = modelModules);\n }\n\n let basePathname = fileUpload?.baseRoute || \"/api/uploads/\";\n\n if (!basePathname.startsWith(\"/\")) basePathname = \"/\" + basePathname;\n if (!basePathname.endsWith(\"/\")) basePathname = basePathname + \"/\";\n\n // Static file serving route\n router.get(\n `${basePathname}*`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeFindFile),\n adjustRequestUrl,\n express.static(\n path.resolve(process.cwd(), fileUpload?.baseUploadDir || \"uploads\"),\n deepmerge(\n {\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: true,\n index: false,\n cacheControl: true,\n },\n fileUpload?.expressStaticOptions || {}\n )\n )\n );\n\n // POST /{basePathname}:fileType - Upload File\n router.post(\n `${basePathname}:fileType`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeUploadFile),\n fileUploadController.uploadFile,\n ...processMiddleware(middlewares?.afterUploadFile),\n sendResponse\n );\n\n // PATCH /{basePathname}:fileType/:fileName - Update File\n router.patch(\n `${basePathname}:fileType/:fileName`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeUpdateFile),\n fileUploadController.updateFile,\n ...processMiddleware(middlewares?.afterUpdateFile),\n sendResponse\n );\n\n // DELETE /{basePathname}:fileType/:fileName - Delete File\n router.delete(\n `${basePathname}:fileType/:fileName`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeDeleteFile),\n fileUploadController.deleteFile,\n ...processMiddleware(middlewares?.afterDeleteFile),\n sendResponse\n );\n\n return router;\n}\n"]}
@@ -5,6 +5,12 @@ import { promisify } from "util";
5
5
  import { getArkosConfig } from "../../../../server.js";
6
6
  import mimetype from "mimetype";
7
7
  import { fullCleanCwd } from "../../../../utils/helpers/fs.helpers.js";
8
+ export function adjustRequestUrl(req, _, next) {
9
+ const { fileUpload } = getArkosConfig();
10
+ req.url = req.url.replace(fileUpload?.baseRoute + "/" || "/api/uploads/", "/");
11
+ req.url = req.url.replace(fileUpload?.baseRoute || "/api/uploads/", "/");
12
+ next();
13
+ }
8
14
  export function extractRequestInfo(req) {
9
15
  const { fileUpload } = getArkosConfig();
10
16
  const protocol = req.headers["x-forwarded-proto"] === "https" ? "https" : "http";