arkos 1.4.0-canary.82 → 1.4.0-canary.84

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 (55) hide show
  1. package/dist/cjs/modules/auth/auth.router.js +12 -12
  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 -10
  4. package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
  5. package/dist/cjs/modules/file-upload/file-upload.router.js +4 -1
  6. package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
  7. package/dist/cjs/modules/swagger/utils/helpers/class-validator-to-json-schema.js +2 -2
  8. package/dist/cjs/modules/swagger/utils/helpers/class-validator-to-json-schema.js.map +1 -1
  9. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +2 -2
  10. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +1 -1
  11. package/dist/cjs/utils/arkos-router/index.js +6 -5
  12. package/dist/cjs/utils/arkos-router/index.js.map +1 -1
  13. package/dist/cjs/utils/arkos-router/types/body-parser-config.js +3 -0
  14. package/dist/cjs/utils/arkos-router/types/body-parser-config.js.map +1 -0
  15. package/dist/cjs/utils/arkos-router/types/index.js.map +1 -1
  16. package/dist/cjs/utils/arkos-router/utils/helpers/index.js +13 -3
  17. package/dist/cjs/utils/arkos-router/utils/helpers/index.js.map +1 -1
  18. package/dist/cjs/utils/arkos-router/utils/helpers/upload-manager.js +5 -1
  19. package/dist/cjs/utils/arkos-router/utils/helpers/upload-manager.js.map +1 -1
  20. package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
  21. package/dist/cjs/utils/helpers/dynamic-loader.helpers.js +34 -55
  22. package/dist/cjs/utils/helpers/dynamic-loader.helpers.js.map +1 -1
  23. package/dist/cjs/utils/helpers/routers.helpers.js +6 -4
  24. package/dist/cjs/utils/helpers/routers.helpers.js.map +1 -1
  25. package/dist/esm/modules/auth/auth.router.js +12 -12
  26. package/dist/esm/modules/auth/auth.router.js.map +1 -1
  27. package/dist/esm/modules/base/utils/helpers/base.router.helpers.js +10 -10
  28. package/dist/esm/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
  29. package/dist/esm/modules/file-upload/file-upload.router.js +4 -1
  30. package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
  31. package/dist/esm/modules/swagger/utils/helpers/class-validator-to-json-schema.js +1 -1
  32. package/dist/esm/modules/swagger/utils/helpers/class-validator-to-json-schema.js.map +1 -1
  33. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +1 -1
  34. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +1 -1
  35. package/dist/esm/utils/arkos-router/index.js +6 -5
  36. package/dist/esm/utils/arkos-router/index.js.map +1 -1
  37. package/dist/esm/utils/arkos-router/types/body-parser-config.js +2 -0
  38. package/dist/esm/utils/arkos-router/types/body-parser-config.js.map +1 -0
  39. package/dist/esm/utils/arkos-router/types/index.js.map +1 -1
  40. package/dist/esm/utils/arkos-router/utils/helpers/index.js +13 -3
  41. package/dist/esm/utils/arkos-router/utils/helpers/index.js.map +1 -1
  42. package/dist/esm/utils/arkos-router/utils/helpers/upload-manager.js +5 -1
  43. package/dist/esm/utils/arkos-router/utils/helpers/upload-manager.js.map +1 -1
  44. package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
  45. package/dist/esm/utils/helpers/arkos-config.helpers.js +2 -2
  46. package/dist/esm/utils/helpers/dynamic-loader.helpers.js +34 -55
  47. package/dist/esm/utils/helpers/dynamic-loader.helpers.js.map +1 -1
  48. package/dist/esm/utils/helpers/routers.helpers.js +6 -4
  49. package/dist/esm/utils/helpers/routers.helpers.js.map +1 -1
  50. package/dist/types/modules/auth/auth.router.d.ts +1 -1
  51. package/dist/types/modules/base/utils/helpers/base.router.helpers.d.ts +1 -1
  52. package/dist/types/utils/arkos-router/types/body-parser-config.d.ts +18 -0
  53. package/dist/types/utils/arkos-router/types/index.d.ts +2 -17
  54. package/dist/types/utils/helpers/routers.helpers.d.ts +2 -1
  55. package/package.json +1 -1
@@ -16,7 +16,7 @@ const router_validator_1 = __importDefault(require("../base/utils/router-validat
16
16
  const fs_helpers_1 = require("../../utils/helpers/fs.helpers");
17
17
  const arkos_router_1 = __importDefault(require("../../utils/arkos-router"));
18
18
  const router = (0, arkos_router_1.default)();
19
- function getAuthRouter(arkosConfigs) {
19
+ function getAuthRouter(arkosConfig) {
20
20
  const { interceptors, dtos, schemas, prismaQueryOptions, router: customRouterModule, authConfigs, } = (0, dynamic_loader_1.getModuleComponents)("auth") || {};
21
21
  const routerConfig = customRouterModule?.config || {};
22
22
  const customRouter = customRouterModule?.default;
@@ -30,7 +30,7 @@ function getAuthRouter(arkosConfigs) {
30
30
  if (routerConfig?.disable === true)
31
31
  return router;
32
32
  const getValidationSchemaOrDto = (key) => {
33
- const validationConfigs = arkosConfigs?.validation;
33
+ const validationConfigs = arkosConfig?.validation;
34
34
  if (validationConfigs?.resolver === "class-validator")
35
35
  return dtos?.[key];
36
36
  else if (validationConfigs?.resolver === "zod")
@@ -38,13 +38,13 @@ function getAuthRouter(arkosConfigs) {
38
38
  return undefined;
39
39
  };
40
40
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "getMe")) {
41
- router.get((0, routers_helpers_1.createRouteConfig)("getMe", "users", "/me", routerConfig, "auth", true), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "getMe"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeGetMe), authController.getMe, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterGetMe), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onGetMeError, { type: "error" }));
41
+ router.get((0, routers_helpers_1.createRouteConfig)(arkosConfig, "getMe", "users", "/me", routerConfig, "auth", true), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "getMe"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeGetMe), authController.getMe, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterGetMe), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onGetMeError, { type: "error" }));
42
42
  }
43
43
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "updateMe")) {
44
- router.patch((0, routers_helpers_1.createRouteConfig)("updateMe", "users", "/me", routerConfig, "auth", true, getValidationSchemaOrDto("updateMe")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateMe"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeUpdateMe), authController.updateMe, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterUpdateMe), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onUpdateMeError, { type: "error" }));
44
+ router.patch((0, routers_helpers_1.createRouteConfig)(arkosConfig, "updateMe", "users", "/me", routerConfig, "auth", true, getValidationSchemaOrDto("updateMe")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateMe"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeUpdateMe), authController.updateMe, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterUpdateMe), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onUpdateMeError, { type: "error" }));
45
45
  }
46
46
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "deleteMe")) {
47
- router.delete((0, routers_helpers_1.createRouteConfig)("deleteMe", "users", "/me", routerConfig, "auth", true), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteMe"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeDeleteMe), authController.deleteMe, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterDeleteMe), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onDeleteMeError, { type: "error" }));
47
+ router.delete((0, routers_helpers_1.createRouteConfig)(arkosConfig, "deleteMe", "users", "/me", routerConfig, "auth", true), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteMe"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeDeleteMe), authController.deleteMe, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterDeleteMe), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onDeleteMeError, { type: "error" }));
48
48
  }
49
49
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "login") ||
50
50
  !(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "logout") ||
@@ -60,29 +60,29 @@ function getAuthRouter(arkosConfigs) {
60
60
  message: "Too many requests, please try again later",
61
61
  });
62
62
  },
63
- }, arkosConfigs?.authentication?.rateLimit || {})));
63
+ }, arkosConfig?.authentication?.rateLimit || {})));
64
64
  }
65
65
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "login")) {
66
- router.post((0, routers_helpers_1.createRouteConfig)("login", "auth", "/login", routerConfig, "auth", false, getValidationSchemaOrDto("login")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "login"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeLogin), authController.login, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterLogin), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onLoginError, { type: "error" }));
66
+ router.post((0, routers_helpers_1.createRouteConfig)(arkosConfig, "login", "auth", "/login", routerConfig, "auth", false, getValidationSchemaOrDto("login")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "login"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeLogin), authController.login, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterLogin), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onLoginError, { type: "error" }));
67
67
  }
68
68
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "logout")) {
69
- router.delete((0, routers_helpers_1.createRouteConfig)("logout", "auth", "/logout", routerConfig, "auth", true), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeLogout), authController.logout, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterLogout), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onLogoutError, { type: "error" }));
69
+ router.delete((0, routers_helpers_1.createRouteConfig)(arkosConfig, "logout", "auth", "/logout", routerConfig, "auth", true), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeLogout), authController.logout, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterLogout), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onLogoutError, { type: "error" }));
70
70
  }
71
71
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "signup")) {
72
- router.post((0, routers_helpers_1.createRouteConfig)("signup", "auth", "/signup", routerConfig, "auth", false, getValidationSchemaOrDto("signup")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "signup"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeSignup), authController.signup, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterSignup), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onSignupError, { type: "error" }));
72
+ router.post((0, routers_helpers_1.createRouteConfig)(arkosConfig, "signup", "auth", "/signup", routerConfig, "auth", false, getValidationSchemaOrDto("signup")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "signup"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeSignup), authController.signup, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterSignup), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onSignupError, { type: "error" }));
73
73
  }
74
74
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "updatePassword")) {
75
- router.post((0, routers_helpers_1.createRouteConfig)("updatePassword", "auth", "/update-password", routerConfig, "auth", true, getValidationSchemaOrDto("updatePassword")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updatePassword"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeUpdatePassword), authController.updatePassword, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterUpdatePassword), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onUpdatePasswordError, {
75
+ router.post((0, routers_helpers_1.createRouteConfig)(arkosConfig, "updatePassword", "auth", "/update-password", routerConfig, "auth", true, getValidationSchemaOrDto("updatePassword")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updatePassword"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeUpdatePassword), authController.updatePassword, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterUpdatePassword), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onUpdatePasswordError, {
76
76
  type: "error",
77
77
  }));
78
78
  }
79
79
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "findManyAuthAction")) {
80
- router.get((0, routers_helpers_1.createRouteConfig)("findManyAuthAction", "auth-actions", "", routerConfig, "auth", authConfigs), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeFindManyAuthAction), authController.findManyAuthAction, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterFindManyAuthAction), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onFindManyAuthActionError, {
80
+ router.get((0, routers_helpers_1.createRouteConfig)(arkosConfig, "findManyAuthAction", "auth-actions", "", routerConfig, "auth", authConfigs), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeFindManyAuthAction), authController.findManyAuthAction, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterFindManyAuthAction), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onFindManyAuthActionError, {
81
81
  type: "error",
82
82
  }));
83
83
  }
84
84
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "findOneAuthAction")) {
85
- router.get((0, routers_helpers_1.createRouteConfig)("findOneAuthAction", "auth-actions", "/:resourceName", routerConfig, "auth", authConfigs), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeFindOneAuthAction), authController.findOneAuthAction, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterFindOneAuthAction), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onFindOneAuthActionError, {
85
+ router.get((0, routers_helpers_1.createRouteConfig)(arkosConfig, "findOneAuthAction", "auth-actions", "/:resourceName", routerConfig, "auth", authConfigs), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeFindOneAuthAction), authController.findOneAuthAction, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterFindOneAuthAction), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onFindOneAuthActionError, {
86
86
  type: "error",
87
87
  }));
88
88
  }
@@ -1 +1 @@
1
- {"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":";;;;;AAuBA,sCAiQC;AAvRD,uDAA0D;AAC1D,4EAA2C;AAC3C,+DAAiE;AACjE,+DAGkC;AAElC,4FAA6D;AAE7D,yEAG6C;AAC7C,mFAA+E;AAC/E,oFAA2D;AAC3D,sFAA6D;AAC7D,+DAAsE;AACtE,4EAAmD;AAEnD,MAAM,MAAM,GAAG,IAAA,sBAAW,GAAE,CAAC;AAE7B,SAAgB,aAAa,CAAC,YAAyB;IACrD,MAAM,EACJ,YAAY,EACZ,IAAI,EACJ,OAAO,EACP,kBAAkB,EAClB,MAAM,EAAE,kBAAkB,EAC1B,WAAW,GACZ,GAAG,IAAA,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C,CACH,CAAC;IACJ,CAAC;IAED,0BAAe,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAa,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { authControllerFactory } from \"./auth.controller\";\nimport rateLimit from \"express-rate-limit\";\nimport { getModuleComponents } from \"../../utils/dynamic-loader\";\nimport {\n addPrismaQueryOptionsToRequest,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport { ArkosConfig } from \"../../types/new-arkos-config\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport {\n processMiddleware,\n createRouteConfig,\n} from \"../../utils/helpers/routers.helpers\";\nimport { isEndpointDisabled } from \"../base/utils/helpers/base.router.helpers\";\nimport debuggerService from \"../debugger/debugger.service\";\nimport routerValidator from \"../base/utils/router-validator\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\nimport ArkosRouter from \"../../utils/arkos-router\";\n\nconst router = ArkosRouter();\n\nexport function getAuthRouter(arkosConfigs: ArkosConfig) {\n const {\n interceptors,\n dtos,\n schemas,\n prismaQueryOptions,\n router: customRouterModule,\n authConfigs,\n } = getModuleComponents(\"auth\") || {};\n\n const routerConfig = customRouterModule?.config || {};\n const customRouter = customRouterModule?.default as Router;\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use(`/auth`, customRouter);\n else\n throw Error(\n `ValidationError: The exported router from auth.router.${getUserFileExtension()} is not a valid express or arkos Router.`\n );\n }\n\n const authController = authControllerFactory(interceptors);\n\n if (routerConfig?.disable === true) return router;\n\n const getValidationSchemaOrDto = (\n key: \"updateMe\" | \"updatePassword\" | \"login\" | \"signup\"\n ) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") return dtos?.[key];\n else if (validationConfigs?.resolver === \"zod\") return schemas?.[key];\n\n return undefined;\n };\n\n // GET /users/me - Get current user\n if (!isEndpointDisabled(routerConfig, \"getMe\")) {\n router.get(\n createRouteConfig(\"getMe\", \"users\", \"/me\", routerConfig, \"auth\", true),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...processMiddleware(interceptors?.beforeGetMe),\n authController.getMe,\n ...processMiddleware(interceptors?.afterGetMe),\n sendResponse,\n ...processMiddleware(interceptors?.onGetMeError, { type: \"error\" })\n );\n }\n\n // PATCH /users/me - Update current user\n if (!isEndpointDisabled(routerConfig, \"updateMe\")) {\n router.patch(\n createRouteConfig(\n \"updateMe\",\n \"users\",\n \"/me\",\n routerConfig,\n \"auth\",\n true,\n getValidationSchemaOrDto(\"updateMe\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...processMiddleware(interceptors?.beforeUpdateMe),\n authController.updateMe,\n ...processMiddleware(interceptors?.afterUpdateMe),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateMeError, { type: \"error\" })\n );\n }\n\n // DELETE /users/me - Delete current user\n if (!isEndpointDisabled(routerConfig, \"deleteMe\")) {\n router.delete(\n createRouteConfig(\"deleteMe\", \"users\", \"/me\", routerConfig, \"auth\", true),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...processMiddleware(interceptors?.beforeDeleteMe),\n authController.deleteMe,\n ...processMiddleware(interceptors?.afterDeleteMe),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteMeError, { type: \"error\" })\n );\n }\n\n // Apply rate limiting to auth routes\n if (\n !isEndpointDisabled(routerConfig, \"login\") ||\n !isEndpointDisabled(routerConfig, \"logout\") ||\n !isEndpointDisabled(routerConfig, \"signup\") ||\n !isEndpointDisabled(routerConfig, \"updatePassword\")\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: (_, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n arkosConfigs?.authentication?.rateLimit || {}\n )\n )\n );\n }\n\n // POST /auth/login - Login\n if (!isEndpointDisabled(routerConfig, \"login\")) {\n router.post(\n createRouteConfig(\n \"login\",\n \"auth\",\n \"/login\",\n routerConfig,\n \"auth\",\n false,\n getValidationSchemaOrDto(\"login\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...processMiddleware(interceptors?.beforeLogin),\n authController.login,\n ...processMiddleware(interceptors?.afterLogin),\n sendResponse,\n ...processMiddleware(interceptors?.onLoginError, { type: \"error\" })\n );\n }\n\n // DELETE /auth/logout - Logout\n if (!isEndpointDisabled(routerConfig, \"logout\")) {\n router.delete(\n createRouteConfig(\n \"logout\",\n \"auth\",\n \"/logout\",\n routerConfig,\n \"auth\",\n true\n ),\n ...processMiddleware(interceptors?.beforeLogout),\n authController.logout,\n ...processMiddleware(interceptors?.afterLogout),\n sendResponse,\n ...processMiddleware(interceptors?.onLogoutError, { type: \"error\" })\n );\n }\n\n // POST /auth/signup - Signup\n if (!isEndpointDisabled(routerConfig, \"signup\")) {\n router.post(\n createRouteConfig(\n \"signup\",\n \"auth\",\n \"/signup\",\n routerConfig,\n \"auth\",\n false,\n getValidationSchemaOrDto(\"signup\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...processMiddleware(interceptors?.beforeSignup),\n authController.signup,\n ...processMiddleware(interceptors?.afterSignup),\n sendResponse,\n ...processMiddleware(interceptors?.onSignupError, { type: \"error\" })\n );\n }\n\n // POST /auth/update-password - Update password\n if (!isEndpointDisabled(routerConfig, \"updatePassword\")) {\n router.post(\n createRouteConfig(\n \"updatePassword\",\n \"auth\",\n \"/update-password\",\n routerConfig,\n \"auth\",\n true,\n getValidationSchemaOrDto(\"updatePassword\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...processMiddleware(interceptors?.beforeUpdatePassword),\n authController.updatePassword,\n ...processMiddleware(interceptors?.afterUpdatePassword),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdatePasswordError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions - Find many auth actions\n if (!isEndpointDisabled(routerConfig, \"findManyAuthAction\")) {\n router.get(\n createRouteConfig(\n \"findManyAuthAction\",\n \"auth-actions\",\n \"\",\n routerConfig,\n \"auth\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeFindManyAuthAction),\n authController.findManyAuthAction,\n ...processMiddleware(interceptors?.afterFindManyAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindManyAuthActionError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions/:resourceName - Find one auth action\n if (!isEndpointDisabled(routerConfig, \"findOneAuthAction\")) {\n router.get(\n createRouteConfig(\n \"findOneAuthAction\",\n \"auth-actions\",\n \"/:resourceName\",\n routerConfig,\n \"auth\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeFindOneAuthAction),\n authController.findOneAuthAction,\n ...processMiddleware(interceptors?.afterFindOneAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindOneAuthActionError, {\n type: \"error\",\n })\n );\n }\n\n debuggerService.logModuleFinalRouter(\"auth\", router as any);\n return router;\n}\n"]}
1
+ {"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":";;;;;AAuBA,sCAwRC;AA9SD,uDAA0D;AAC1D,4EAA2C;AAC3C,+DAAiE;AACjE,+DAGkC;AAElC,4FAA6D;AAE7D,yEAG6C;AAC7C,mFAA+E;AAC/E,oFAA2D;AAC3D,sFAA6D;AAC7D,+DAAsE;AACtE,4EA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B,YAAY,EACZ,MAAM,EACN,WAAW,CACZ,EACD,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,uBAAuB,CAAC,EAC3D,cAAc,CAAC,iBAAiB,EAChC,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,sBAAsB,CAAC,EAC1D,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,wBAAwB,EAAE;YAC3D,IAAI,EAAE,OAAO;SACd,CAAC,CACH,CAAC;IACJ,CAAC;IAED,0BAAe,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAa,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { authControllerFactory } from \"./auth.controller\";\nimport rateLimit from \"express-rate-limit\";\nimport { getModuleComponents } from \"../../utils/dynamic-loader\";\nimport {\n addPrismaQueryOptionsToRequest,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport { ArkosConfig } from \"../../types/new-arkos-config\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport {\n processMiddleware,\n createRouteConfig,\n} from \"../../utils/helpers/routers.helpers\";\nimport { isEndpointDisabled } from \"../base/utils/helpers/base.router.helpers\";\nimport debuggerService from \"../debugger/debugger.service\";\nimport routerValidator from \"../base/utils/router-validator\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\nimport ArkosRouter from \"../../utils/arkos-router\";\n\nconst router = ArkosRouter();\n\nexport function getAuthRouter(arkosConfig: ArkosConfig) {\n const {\n interceptors,\n dtos,\n schemas,\n prismaQueryOptions,\n router: customRouterModule,\n authConfigs,\n } = getModuleComponents(\"auth\") || {};\n\n const routerConfig = customRouterModule?.config || {};\n const customRouter = customRouterModule?.default as Router;\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use(`/auth`, customRouter);\n else\n throw Error(\n `ValidationError: The exported router from auth.router.${getUserFileExtension()} is not a valid express or arkos Router.`\n );\n }\n\n const authController = authControllerFactory(interceptors);\n\n if (routerConfig?.disable === true) return router;\n\n const getValidationSchemaOrDto = (\n key: \"updateMe\" | \"updatePassword\" | \"login\" | \"signup\"\n ) => {\n const validationConfigs = arkosConfig?.validation;\n if (validationConfigs?.resolver === \"class-validator\") return dtos?.[key];\n else if (validationConfigs?.resolver === \"zod\") return schemas?.[key];\n\n return undefined;\n };\n\n // GET /users/me - Get current user\n if (!isEndpointDisabled(routerConfig, \"getMe\")) {\n router.get(\n createRouteConfig(\n arkosConfig,\n \"getMe\",\n \"users\",\n \"/me\",\n routerConfig,\n \"auth\",\n true\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...processMiddleware(interceptors?.beforeGetMe),\n authController.getMe,\n ...processMiddleware(interceptors?.afterGetMe),\n sendResponse,\n ...processMiddleware(interceptors?.onGetMeError, { type: \"error\" })\n );\n }\n\n // PATCH /users/me - Update current user\n if (!isEndpointDisabled(routerConfig, \"updateMe\")) {\n router.patch(\n createRouteConfig(\n arkosConfig,\n \"updateMe\",\n \"users\",\n \"/me\",\n routerConfig,\n \"auth\",\n true,\n getValidationSchemaOrDto(\"updateMe\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...processMiddleware(interceptors?.beforeUpdateMe),\n authController.updateMe,\n ...processMiddleware(interceptors?.afterUpdateMe),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateMeError, { type: \"error\" })\n );\n }\n\n // DELETE /users/me - Delete current user\n if (!isEndpointDisabled(routerConfig, \"deleteMe\")) {\n router.delete(\n createRouteConfig(\n arkosConfig,\n \"deleteMe\",\n \"users\",\n \"/me\",\n routerConfig,\n \"auth\",\n true\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...processMiddleware(interceptors?.beforeDeleteMe),\n authController.deleteMe,\n ...processMiddleware(interceptors?.afterDeleteMe),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteMeError, { type: \"error\" })\n );\n }\n\n // Apply rate limiting to auth routes\n if (\n !isEndpointDisabled(routerConfig, \"login\") ||\n !isEndpointDisabled(routerConfig, \"logout\") ||\n !isEndpointDisabled(routerConfig, \"signup\") ||\n !isEndpointDisabled(routerConfig, \"updatePassword\")\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: (_, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n arkosConfig?.authentication?.rateLimit || {}\n )\n )\n );\n }\n\n // POST /auth/login - Login\n if (!isEndpointDisabled(routerConfig, \"login\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"login\",\n \"auth\",\n \"/login\",\n routerConfig,\n \"auth\",\n false,\n getValidationSchemaOrDto(\"login\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...processMiddleware(interceptors?.beforeLogin),\n authController.login,\n ...processMiddleware(interceptors?.afterLogin),\n sendResponse,\n ...processMiddleware(interceptors?.onLoginError, { type: \"error\" })\n );\n }\n\n // DELETE /auth/logout - Logout\n if (!isEndpointDisabled(routerConfig, \"logout\")) {\n router.delete(\n createRouteConfig(\n arkosConfig,\n \"logout\",\n \"auth\",\n \"/logout\",\n routerConfig,\n \"auth\",\n true\n ),\n ...processMiddleware(interceptors?.beforeLogout),\n authController.logout,\n ...processMiddleware(interceptors?.afterLogout),\n sendResponse,\n ...processMiddleware(interceptors?.onLogoutError, { type: \"error\" })\n );\n }\n\n // POST /auth/signup - Signup\n if (!isEndpointDisabled(routerConfig, \"signup\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"signup\",\n \"auth\",\n \"/signup\",\n routerConfig,\n \"auth\",\n false,\n getValidationSchemaOrDto(\"signup\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...processMiddleware(interceptors?.beforeSignup),\n authController.signup,\n ...processMiddleware(interceptors?.afterSignup),\n sendResponse,\n ...processMiddleware(interceptors?.onSignupError, { type: \"error\" })\n );\n }\n\n // POST /auth/update-password - Update password\n if (!isEndpointDisabled(routerConfig, \"updatePassword\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"updatePassword\",\n \"auth\",\n \"/update-password\",\n routerConfig,\n \"auth\",\n true,\n getValidationSchemaOrDto(\"updatePassword\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...processMiddleware(interceptors?.beforeUpdatePassword),\n authController.updatePassword,\n ...processMiddleware(interceptors?.afterUpdatePassword),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdatePasswordError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions - Find many auth actions\n if (!isEndpointDisabled(routerConfig, \"findManyAuthAction\")) {\n router.get(\n createRouteConfig(\n arkosConfig,\n \"findManyAuthAction\",\n \"auth-actions\",\n \"\",\n routerConfig,\n \"auth\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeFindManyAuthAction),\n authController.findManyAuthAction,\n ...processMiddleware(interceptors?.afterFindManyAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindManyAuthActionError, {\n type: \"error\",\n })\n );\n }\n\n // GET /auth-actions/:resourceName - Find one auth action\n if (!isEndpointDisabled(routerConfig, \"findOneAuthAction\")) {\n router.get(\n createRouteConfig(\n arkosConfig,\n \"findOneAuthAction\",\n \"auth-actions\",\n \"/:resourceName\",\n routerConfig,\n \"auth\",\n authConfigs\n ),\n ...processMiddleware(interceptors?.beforeFindOneAuthAction),\n authController.findOneAuthAction,\n ...processMiddleware(interceptors?.afterFindOneAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindOneAuthActionError, {\n type: \"error\",\n })\n );\n }\n\n debuggerService.logModuleFinalRouter(\"auth\", router as any);\n return router;\n}\n"]}
@@ -16,7 +16,7 @@ const router_validator_1 = __importDefault(require("../router-validator"));
16
16
  const fs_helpers_1 = require("../../../../utils/helpers/fs.helpers");
17
17
  const prisma_schema_parser_1 = __importDefault(require("../../../../utils/prisma/prisma-schema-parser"));
18
18
  const debugger_service_1 = __importDefault(require("../../../debugger/debugger.service"));
19
- function setupRouters(router, arkosConfigs) {
19
+ function setupRouters(router, arkosConfig) {
20
20
  return prisma_schema_parser_1.default.getModelsAsArrayOfStrings().map(async (model) => {
21
21
  const modelNameInKebab = (0, utils_1.kebabCase)(model);
22
22
  const modelModules = (0, dynamic_loader_1.getModuleComponents)(modelNameInKebab) || {};
@@ -33,7 +33,7 @@ function setupRouters(router, arkosConfigs) {
33
33
  layer.method.toLowerCase() === method.toLowerCase());
34
34
  };
35
35
  const getValidationSchemaOrDto = (key) => {
36
- const validationConfigs = arkosConfigs?.validation;
36
+ const validationConfigs = arkosConfig?.validation;
37
37
  if (validationConfigs?.resolver === "class-validator") {
38
38
  return dtos?.[key];
39
39
  }
@@ -49,28 +49,28 @@ function setupRouters(router, arkosConfigs) {
49
49
  throw Error(`ValidationError: The exported router from ${modelNameInKebab}.router.${(0, fs_helpers_1.getUserFileExtension)()} is not a valid express Router.`);
50
50
  }
51
51
  if (!hasCustomImplementation(`/${routeName}`, "post")) {
52
- router.post((0, routers_helpers_1.createRouteConfig)("createOne", routeName, "", routerConfig, modelNameInKebab, authConfigs, getValidationSchemaOrDto("create")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createOne"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeCreateOne), controller.createOne, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterCreateOne), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onCreateOneError, { type: "error" }));
52
+ router.post((0, routers_helpers_1.createRouteConfig)(arkosConfig, "createOne", routeName, "", routerConfig, modelNameInKebab, authConfigs, getValidationSchemaOrDto("create")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createOne"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeCreateOne), controller.createOne, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterCreateOne), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onCreateOneError, { type: "error" }));
53
53
  }
54
54
  if (!hasCustomImplementation(`/${routeName}`, "get")) {
55
- router.get((0, routers_helpers_1.createRouteConfig)("findMany", routeName, "", routerConfig, modelNameInKebab, authConfigs), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findMany"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeFindMany), controller.findMany, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterFindMany), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onFindManyError, { type: "error" }));
55
+ router.get((0, routers_helpers_1.createRouteConfig)(arkosConfig, "findMany", routeName, "", routerConfig, modelNameInKebab, authConfigs), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findMany"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeFindMany), controller.findMany, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterFindMany), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onFindManyError, { type: "error" }));
56
56
  }
57
57
  if (!hasCustomImplementation(`/${routeName}/many`, "post")) {
58
- router.post((0, routers_helpers_1.createRouteConfig)("createMany", routeName, "/many", routerConfig, modelNameInKebab, authConfigs, getValidationSchemaOrDto("createMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createMany"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeCreateMany), controller.createMany, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterCreateMany), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onCreateManyError, { type: "error" }));
58
+ router.post((0, routers_helpers_1.createRouteConfig)(arkosConfig, "createMany", routeName, "/many", routerConfig, modelNameInKebab, authConfigs, getValidationSchemaOrDto("createMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createMany"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeCreateMany), controller.createMany, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterCreateMany), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onCreateManyError, { type: "error" }));
59
59
  }
60
60
  if (!hasCustomImplementation(`/${routeName}/many`, "patch")) {
61
- router.patch((0, routers_helpers_1.createRouteConfig)("updateMany", routeName, "/many", routerConfig, modelNameInKebab, authConfigs), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateMany"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeUpdateMany), controller.updateMany, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterUpdateMany), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onUpdateManyError, { type: "error" }));
61
+ router.patch((0, routers_helpers_1.createRouteConfig)(arkosConfig, "updateMany", routeName, "/many", routerConfig, modelNameInKebab, authConfigs), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateMany"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeUpdateMany), controller.updateMany, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterUpdateMany), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onUpdateManyError, { type: "error" }));
62
62
  }
63
63
  if (!hasCustomImplementation(`/${routeName}/many`, "delete")) {
64
- router.delete((0, routers_helpers_1.createRouteConfig)("deleteMany", routeName, "/many", routerConfig, modelNameInKebab, authConfigs), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteMany"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeDeleteMany), controller.deleteMany, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterDeleteMany), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onDeleteManyError, { type: "error" }));
64
+ router.delete((0, routers_helpers_1.createRouteConfig)(arkosConfig, "deleteMany", routeName, "/many", routerConfig, modelNameInKebab, authConfigs), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteMany"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeDeleteMany), controller.deleteMany, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterDeleteMany), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onDeleteManyError, { type: "error" }));
65
65
  }
66
66
  if (!hasCustomImplementation(`/${routeName}/:id`, "get")) {
67
- router.get((0, routers_helpers_1.createRouteConfig)("findOne", routeName, "/:id", routerConfig, modelNameInKebab, authConfigs), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findOne"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeFindOne), controller.findOne, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterFindOne), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onFindOneError, { type: "error" }));
67
+ router.get((0, routers_helpers_1.createRouteConfig)(arkosConfig, "findOne", routeName, "/:id", routerConfig, modelNameInKebab, authConfigs), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findOne"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeFindOne), controller.findOne, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterFindOne), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onFindOneError, { type: "error" }));
68
68
  }
69
69
  if (!hasCustomImplementation(`/${routeName}/:id`, "patch")) {
70
- router.patch((0, routers_helpers_1.createRouteConfig)("updateOne", routeName, "/:id", routerConfig, modelNameInKebab, authConfigs, getValidationSchemaOrDto("update")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateOne"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeUpdateOne), controller.updateOne, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterUpdateOne), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onUpdateOneError, { type: "error" }));
70
+ router.patch((0, routers_helpers_1.createRouteConfig)(arkosConfig, "updateOne", routeName, "/:id", routerConfig, modelNameInKebab, authConfigs, getValidationSchemaOrDto("update")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateOne"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeUpdateOne), controller.updateOne, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterUpdateOne), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onUpdateOneError, { type: "error" }));
71
71
  }
72
72
  if (!hasCustomImplementation(`/${routeName}/:id`, "delete")) {
73
- router.delete((0, routers_helpers_1.createRouteConfig)("deleteOne", routeName, "/:id", routerConfig, modelNameInKebab, authConfigs), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteOne"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeDeleteOne), controller.deleteOne, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterDeleteOne), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onDeleteOneError, { type: "error" }));
73
+ router.delete((0, routers_helpers_1.createRouteConfig)(arkosConfig, "deleteOne", routeName, "/:id", routerConfig, modelNameInKebab, authConfigs), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteOne"), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeDeleteOne), controller.deleteOne, ...(0, routers_helpers_1.processMiddleware)(interceptors?.afterDeleteOne), base_middlewares_1.sendResponse, ...(0, routers_helpers_1.processMiddleware)(interceptors?.onDeleteOneError, { type: "error" }));
74
74
  }
75
75
  debugger_service_1.default.logModuleFinalRouter(modelNameInKebab, router);
76
76
  });
@@ -1 +1 @@
1
- {"version":3,"file":"base.router.helpers.js","sourceRoot":"","sources":["../../../../../../src/modules/base/utils/helpers/base.router.helpers.ts"],"names":[],"mappings":";;;;;AA0BA,oCAiPC;AAED,gDAYC;AAED,0DAWC;AArSD,0DAAkC;AAElC,qDAAsD;AAOtD,qEAAuE;AACvE,2DAAuD;AACvD,6DAGgC;AAChC,+EAGmD;AACnD,2EAAkD;AAClD,qEAA4E;AAC5E,yGAA+E;AAC/E,0FAAiE;AAGjE,SAAgB,YAAY,CAAC,MAAoB,EAAE,YAAyB;IAC1E,OAAO,8BAAkB,CAAC,yBAAyB,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACxE,MAAM,gBAAgB,GAAG,IAAA,iBAAS,EAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,IAAA,oCAAmB,EAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;QAEjE,MAAM,EACJ,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EACJ,OAAO,GACR,GAAG,YAAY,CAAC;QAEjB,MAAM,SAAS,GAAG,mBAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACrD,MAAM,UAAU,GAAG,IAAI,gCAAc,CAAC,KAAK,CAAC,CAAC;QAE7C,MAAM,YAAY,GAAsB,kBAAkB,EAAE,MAAM,IAAI,EAAE,CAAC;QAEzE,MAAM,YAAY,GAAG,kBAAkB,EAAE,OAAiB,CAAC;QAC3D,MAAM,uBAAuB,GAAG,CAAC,IAAY,EA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Router } from \"express\";\nimport pluralize from \"pluralize\";\nimport { ArkosConfig, RouterConfig } from \"../../../../exports\";\nimport { kebabCase } from \"../../../../exports/utils\";\nimport { PrismaQueryOptions } from \"../../../../types\";\nimport {\n AuthRouterEndpoint,\n FileUploadRouterEndpoint,\n RouterEndpoint,\n} from \"../../../../types/router-config\";\nimport { getModuleComponents } from \"../../../../utils/dynamic-loader\";\nimport { BaseController } from \"../../base.controller\";\nimport {\n addPrismaQueryOptionsToRequest,\n sendResponse,\n} from \"../../base.middlewares\";\nimport {\n createRouteConfig,\n processMiddleware,\n} from \"../../../../utils/helpers/routers.helpers\";\nimport routerValidator from \"../router-validator\";\nimport { getUserFileExtension } from \"../../../../utils/helpers/fs.helpers\";\nimport prismaSchemaParser from \"../../../../utils/prisma/prisma-schema-parser\";\nimport debuggerService from \"../../../debugger/debugger.service\";\nimport { IArkosRouter } from \"../../../../utils/arkos-router/types\";\n\nexport function setupRouters(router: IArkosRouter, arkosConfigs: ArkosConfig) {\n return prismaSchemaParser.getModelsAsArrayOfStrings().map(async (model) => {\n const modelNameInKebab = kebabCase(model);\n const modelModules = getModuleComponents(modelNameInKebab) || {};\n\n const {\n interceptors,\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<any> = customRouterModule?.config || {};\n\n const customRouter = customRouterModule?.default 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 const getValidationSchemaOrDto = (\n key: \"create\" | \"update\" | \"createMany\" | \"updateMany\"\n ) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return (dtos as any)?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return (schemas as any)?.[key];\n }\n return undefined;\n };\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use(`/${routeName}`, customRouter);\n else\n throw Error(\n `ValidationError: The exported router from ${modelNameInKebab}.router.${getUserFileExtension()} is not a valid express Router.`\n );\n }\n\n // CREATE ONE\n if (!hasCustomImplementation(`/${routeName}`, \"post\")) {\n router.post(\n createRouteConfig(\n \"createOne\",\n routeName,\n \"\",\n routerConfig,\n modelNameInKebab,\n authConfigs,\n getValidationSchemaOrDto(\"create\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createOne\"\n ),\n ...processMiddleware(interceptors?.beforeCreateOne),\n controller.createOne,\n ...processMiddleware(interceptors?.afterCreateOne),\n sendResponse,\n ...processMiddleware(interceptors?.onCreateOneError, { type: \"error\" })\n );\n }\n\n // FIND MANY\n if (!hasCustomImplementation(`/${routeName}`, \"get\")) {\n router.get(\n createRouteConfig(\n \"findMany\",\n routeName,\n \"\",\n routerConfig,\n modelNameInKebab,\n authConfigs\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findMany\"\n ),\n ...processMiddleware(interceptors?.beforeFindMany),\n controller.findMany,\n ...processMiddleware(interceptors?.afterFindMany),\n sendResponse,\n ...processMiddleware(interceptors?.onFindManyError, { type: \"error\" })\n );\n }\n\n // CREATE MANY\n if (!hasCustomImplementation(`/${routeName}/many`, \"post\")) {\n router.post(\n createRouteConfig(\n \"createMany\",\n routeName,\n \"/many\",\n routerConfig,\n modelNameInKebab,\n authConfigs,\n getValidationSchemaOrDto(\"createMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createMany\"\n ),\n ...processMiddleware(interceptors?.beforeCreateMany),\n controller.createMany,\n ...processMiddleware(interceptors?.afterCreateMany),\n sendResponse,\n ...processMiddleware(interceptors?.onCreateManyError, { type: \"error\" })\n );\n }\n\n // UPDATE MANY\n if (!hasCustomImplementation(`/${routeName}/many`, \"patch\")) {\n router.patch(\n createRouteConfig(\n \"updateMany\",\n routeName,\n \"/many\",\n routerConfig,\n modelNameInKebab,\n authConfigs\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateMany\"\n ),\n ...processMiddleware(interceptors?.beforeUpdateMany),\n controller.updateMany,\n ...processMiddleware(interceptors?.afterUpdateMany),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateManyError, { type: \"error\" })\n );\n }\n\n // DELETE MANY\n if (!hasCustomImplementation(`/${routeName}/many`, \"delete\")) {\n router.delete(\n createRouteConfig(\n \"deleteMany\",\n routeName,\n \"/many\",\n routerConfig,\n modelNameInKebab,\n authConfigs\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteMany\"\n ),\n ...processMiddleware(interceptors?.beforeDeleteMany),\n controller.deleteMany,\n ...processMiddleware(interceptors?.afterDeleteMany),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteManyError, { type: \"error\" })\n );\n }\n\n // FIND ONE\n if (!hasCustomImplementation(`/${routeName}/:id`, \"get\")) {\n router.get(\n createRouteConfig(\n \"findOne\",\n routeName,\n \"/:id\",\n routerConfig,\n modelNameInKebab,\n authConfigs\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findOne\"\n ),\n ...processMiddleware(interceptors?.beforeFindOne),\n controller.findOne,\n ...processMiddleware(interceptors?.afterFindOne),\n sendResponse,\n ...processMiddleware(interceptors?.onFindOneError, { type: \"error\" })\n );\n }\n\n // UPDATE ONE\n if (!hasCustomImplementation(`/${routeName}/:id`, \"patch\")) {\n router.patch(\n createRouteConfig(\n \"updateOne\",\n routeName,\n \"/:id\",\n routerConfig,\n modelNameInKebab,\n authConfigs,\n getValidationSchemaOrDto(\"update\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateOne\"\n ),\n ...processMiddleware(interceptors?.beforeUpdateOne),\n controller.updateOne,\n ...processMiddleware(interceptors?.afterUpdateOne),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateOneError, { type: \"error\" })\n );\n }\n\n // DELETE ONE\n if (!hasCustomImplementation(`/${routeName}/:id`, \"delete\")) {\n router.delete(\n createRouteConfig(\n \"deleteOne\",\n routeName,\n \"/:id\",\n routerConfig,\n modelNameInKebab,\n authConfigs\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteOne\"\n ),\n ...processMiddleware(interceptors?.beforeDeleteOne),\n controller.deleteOne,\n ...processMiddleware(interceptors?.afterDeleteOne),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteOneError, { type: \"error\" })\n );\n }\n\n debuggerService.logModuleFinalRouter(modelNameInKebab, router as any);\n });\n}\n\nexport function isEndpointDisabled(\n routerConfig: RouterConfig<any>,\n endpoint: RouterEndpoint | AuthRouterEndpoint | FileUploadRouterEndpoint\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 as never] === 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;\n}\n"]}
1
+ {"version":3,"file":"base.router.helpers.js","sourceRoot":"","sources":["../../../../../../src/modules/base/utils/helpers/base.router.helpers.ts"],"names":[],"mappings":";;;;;AA0BA,oCAyPC;AAED,gDAYC;AAED,0DAWC;AA7SD,0DAAkC;AAElC,qDAAsD;AAOtD,qEAAuE;A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AE,gBAAgB,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CACxE,CAAC;QACJ,CAAC;QAED,0BAAe,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,MAAa,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,kBAAkB,CAChC,YAA+B,EAC/B,QAAwE;IAExE,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,QAAiB,CAAC,KAAK,IAAI,CAAC;IAE1D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAgB,uBAAuB,CACrC,YAAiB,EACjB,QAAgB;IAEhB,IAAI,CAAC,YAAY,EAAE,MAAM;QAAE,OAAO,KAAK,CAAC;IAExC,MAAM,eAAe,GAAG,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC;IACtD,IAAI,eAAe,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;QAAE,OAAO,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE9E,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { Router } from \"express\";\nimport pluralize from \"pluralize\";\nimport { ArkosConfig, RouterConfig } from \"../../../../exports\";\nimport { kebabCase } from \"../../../../exports/utils\";\nimport { PrismaQueryOptions } from \"../../../../types\";\nimport {\n AuthRouterEndpoint,\n FileUploadRouterEndpoint,\n RouterEndpoint,\n} from \"../../../../types/router-config\";\nimport { getModuleComponents } from \"../../../../utils/dynamic-loader\";\nimport { BaseController } from \"../../base.controller\";\nimport {\n addPrismaQueryOptionsToRequest,\n sendResponse,\n} from \"../../base.middlewares\";\nimport {\n createRouteConfig,\n processMiddleware,\n} from \"../../../../utils/helpers/routers.helpers\";\nimport routerValidator from \"../router-validator\";\nimport { getUserFileExtension } from \"../../../../utils/helpers/fs.helpers\";\nimport prismaSchemaParser from \"../../../../utils/prisma/prisma-schema-parser\";\nimport debuggerService from \"../../../debugger/debugger.service\";\nimport { IArkosRouter } from \"../../../../utils/arkos-router/types\";\n\nexport function setupRouters(router: IArkosRouter, arkosConfig: ArkosConfig) {\n return prismaSchemaParser.getModelsAsArrayOfStrings().map(async (model) => {\n const modelNameInKebab = kebabCase(model);\n const modelModules = getModuleComponents(modelNameInKebab) || {};\n\n const {\n interceptors,\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<any> = customRouterModule?.config || {};\n\n const customRouter = customRouterModule?.default 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 const getValidationSchemaOrDto = (\n key: \"create\" | \"update\" | \"createMany\" | \"updateMany\"\n ) => {\n const validationConfigs = arkosConfig?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return (dtos as any)?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return (schemas as any)?.[key];\n }\n return undefined;\n };\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use(`/${routeName}`, customRouter);\n else\n throw Error(\n `ValidationError: The exported router from ${modelNameInKebab}.router.${getUserFileExtension()} is not a valid express Router.`\n );\n }\n\n // CREATE ONE\n if (!hasCustomImplementation(`/${routeName}`, \"post\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"createOne\",\n routeName,\n \"\",\n routerConfig,\n modelNameInKebab,\n authConfigs,\n getValidationSchemaOrDto(\"create\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createOne\"\n ),\n ...processMiddleware(interceptors?.beforeCreateOne),\n controller.createOne,\n ...processMiddleware(interceptors?.afterCreateOne),\n sendResponse,\n ...processMiddleware(interceptors?.onCreateOneError, { type: \"error\" })\n );\n }\n\n // FIND MANY\n if (!hasCustomImplementation(`/${routeName}`, \"get\")) {\n router.get(\n createRouteConfig(\n arkosConfig,\n \"findMany\",\n routeName,\n \"\",\n routerConfig,\n modelNameInKebab,\n authConfigs\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findMany\"\n ),\n ...processMiddleware(interceptors?.beforeFindMany),\n controller.findMany,\n ...processMiddleware(interceptors?.afterFindMany),\n sendResponse,\n ...processMiddleware(interceptors?.onFindManyError, { type: \"error\" })\n );\n }\n\n // CREATE MANY\n if (!hasCustomImplementation(`/${routeName}/many`, \"post\")) {\n router.post(\n createRouteConfig(\n arkosConfig,\n \"createMany\",\n routeName,\n \"/many\",\n routerConfig,\n modelNameInKebab,\n authConfigs,\n getValidationSchemaOrDto(\"createMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createMany\"\n ),\n ...processMiddleware(interceptors?.beforeCreateMany),\n controller.createMany,\n ...processMiddleware(interceptors?.afterCreateMany),\n sendResponse,\n ...processMiddleware(interceptors?.onCreateManyError, { type: \"error\" })\n );\n }\n\n // UPDATE MANY\n if (!hasCustomImplementation(`/${routeName}/many`, \"patch\")) {\n router.patch(\n createRouteConfig(\n arkosConfig,\n \"updateMany\",\n routeName,\n \"/many\",\n routerConfig,\n modelNameInKebab,\n authConfigs\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateMany\"\n ),\n ...processMiddleware(interceptors?.beforeUpdateMany),\n controller.updateMany,\n ...processMiddleware(interceptors?.afterUpdateMany),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateManyError, { type: \"error\" })\n );\n }\n\n // DELETE MANY\n if (!hasCustomImplementation(`/${routeName}/many`, \"delete\")) {\n router.delete(\n createRouteConfig(\n arkosConfig,\n \"deleteMany\",\n routeName,\n \"/many\",\n routerConfig,\n modelNameInKebab,\n authConfigs\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteMany\"\n ),\n ...processMiddleware(interceptors?.beforeDeleteMany),\n controller.deleteMany,\n ...processMiddleware(interceptors?.afterDeleteMany),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteManyError, { type: \"error\" })\n );\n }\n\n // FIND ONE\n if (!hasCustomImplementation(`/${routeName}/:id`, \"get\")) {\n router.get(\n createRouteConfig(\n arkosConfig,\n \"findOne\",\n routeName,\n \"/:id\",\n routerConfig,\n modelNameInKebab,\n authConfigs\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findOne\"\n ),\n ...processMiddleware(interceptors?.beforeFindOne),\n controller.findOne,\n ...processMiddleware(interceptors?.afterFindOne),\n sendResponse,\n ...processMiddleware(interceptors?.onFindOneError, { type: \"error\" })\n );\n }\n\n // UPDATE ONE\n if (!hasCustomImplementation(`/${routeName}/:id`, \"patch\")) {\n router.patch(\n createRouteConfig(\n arkosConfig,\n \"updateOne\",\n routeName,\n \"/:id\",\n routerConfig,\n modelNameInKebab,\n authConfigs,\n getValidationSchemaOrDto(\"update\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateOne\"\n ),\n ...processMiddleware(interceptors?.beforeUpdateOne),\n controller.updateOne,\n ...processMiddleware(interceptors?.afterUpdateOne),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateOneError, { type: \"error\" })\n );\n }\n\n // DELETE ONE\n if (!hasCustomImplementation(`/${routeName}/:id`, \"delete\")) {\n router.delete(\n createRouteConfig(\n arkosConfig,\n \"deleteOne\",\n routeName,\n \"/:id\",\n routerConfig,\n modelNameInKebab,\n authConfigs\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteOne\"\n ),\n ...processMiddleware(interceptors?.beforeDeleteOne),\n controller.deleteOne,\n ...processMiddleware(interceptors?.afterDeleteOne),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteOneError, { type: \"error\" })\n );\n }\n\n debuggerService.logModuleFinalRouter(modelNameInKebab, router as any);\n });\n}\n\nexport function isEndpointDisabled(\n routerConfig: RouterConfig<any>,\n endpoint: RouterEndpoint | AuthRouterEndpoint | FileUploadRouterEndpoint\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 as never] === 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;\n}\n"]}
@@ -45,7 +45,10 @@ function getFileUploadRouter(arkosConfig) {
45
45
  if (!basePathname.endsWith("/"))
46
46
  basePathname = basePathname + "/";
47
47
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "findFile")) {
48
- router.get(`${basePathname}*`, auth_service_1.default.handleAuthenticationControl("View", authConfigs.authenticationControl), auth_service_1.default.handleAccessControl("View", "file-upload", authConfigs.accessControl), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeFindFile), file_upload_helpers_1.adjustRequestUrl, express_2.default.static(path_1.default.resolve(process.cwd(), fileUpload?.baseUploadDir || "uploads"), (0, deepmerge_helper_1.default)({
48
+ const baseUploadDirFullPath = path_1.default.resolve(path_1.default
49
+ .join(process.cwd(), fileUpload?.baseUploadDir || "uploads")
50
+ .replaceAll("//", "/"));
51
+ router.get(`${basePathname}*`, auth_service_1.default.handleAuthenticationControl("View", authConfigs.authenticationControl), auth_service_1.default.handleAccessControl("View", "file-upload", authConfigs.accessControl), ...(0, routers_helpers_1.processMiddleware)(interceptors?.beforeFindFile), file_upload_helpers_1.adjustRequestUrl, express_2.default.static(baseUploadDirFullPath, (0, deepmerge_helper_1.default)({
49
52
  maxAge: "1y",
50
53
  etag: true,
51
54
  lastModified: true,
@@ -1 +1 @@
1
- {"version":3,"file":"file-upload.router.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.router.ts"],"names":[],"mappings":";;;;;AAmBA,kDAkIC;AArJD,qCAAiC;AACjC,+DAAiE;AACjE,wEAA+C;AAC/C,sFAA4D;AAC5D,sDAA8B;AAC9B,4FAA6D;AAE7D,+DAAwD;AACxD,yEAAwE;AACxE,6EAAuE;AACvE,mFAA+E;AAC/E,oFAA2D;AAC3D,sFAA6D;AAC7D,+DAAsE;AAEtE,gDAAwB;AAExB,MAAM,MAAM,GAAW,IAAA,gBAAM,GAAE,CAAC;AAEhC,SAAgB,mBAAmB,CAAC,WAAwB;IAC1D,MAAM,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;IAEnC,MAAM,gBAAgB,GAAG,IAAA,oCAAmB,EAAC,aAAa,CAAC,CAAC;IAC5D,IAAI,EACF,YAAY,GAAG,EAAS,EACxB,WAAW,GAAG,EAAiB,EAC/B,MAAM,EAAE,kBAAkB,GAC3B,GAAQ,EAAE,CAAC;IAEZ,IAAI,gBAAgB;QAClB,CAAC;YACC,YAAY,GAAG,EAAE;YACjB,WAAW,GAAG,EAAE;YAChB,MAAM,EAAE,kBAAkB;SAC3B,GAAG,gBAAgB,CAAC,CAAC;IAExB,MAAM,YAAY,GAAG,kBAAkB,EAAE,MAAM,IAAI,EAAE,CAAC;IACtD,IAAI,YAAY,EAAE,OAAO,KAAK,IAAI;QAAE,OAAO,MAAM,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AC;IACJ,CAAC;IAED,IAAI,CAAC,IAAA,wCAAkB,EAAC,YAAY,EAAE,YAAY,CAAC,EAAE,CAAC;QACpD,MAAM,CAAC,MAAM,CACX,GAAG,YAAY,qBAAqB,EACpC,sBAAW,CAAC,2BAA2B,CACrC,QAAQ,EACR,WAAW,CAAC,qBAAqB,CAClC,EACD,sBAAW,CAAC,mBAAmB,CAC7B,QAAQ,EACR,aAAa,EACb,WAAW,CAAC,aAAa,CAC1B,EACD,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,gBAAgB,CAAC,EACpD,gCAAoB,CAAC,UAAU,EAC/B,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,eAAe,CAAC,EACnD,+BAAY,EACZ,GAAG,IAAA,mCAAiB,EAAC,YAAY,EAAE,iBAAiB,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CACzE,CAAC;IACJ,CAAC;IAED,0BAAe,CAAC,oBAAoB,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { getModuleComponents } from \"../../utils/dynamic-loader\";\nimport authService from \"../auth/auth.service\";\nimport fileUploadController from \"./file-upload.controller\";\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\";\nimport { isEndpointDisabled } from \"../base/utils/helpers/base.router.helpers\";\nimport debuggerService from \"../debugger/debugger.service\";\nimport routerValidator from \"../base/utils/router-validator\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\nimport { ArkosConfig } from \"../../exports\";\nimport path from \"path\";\n\nconst router: Router = Router();\n\nexport function getFileUploadRouter(arkosConfig: ArkosConfig) {\n const { fileUpload } = arkosConfig;\n\n const moduleComponents = getModuleComponents(\"file-upload\");\n let {\n interceptors = {} as any,\n authConfigs = {} as AuthConfigs,\n router: customRouterModule,\n }: any = {};\n\n if (moduleComponents)\n ({\n interceptors = {},\n authConfigs = {},\n router: customRouterModule,\n } = moduleComponents);\n\n const routerConfig = customRouterModule?.config || {};\n if (routerConfig?.disable === true) return router;\n\n const customRouter = customRouterModule?.default as Router;\n let basePathname = fileUpload?.baseRoute || \"/api/uploads/\";\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use(basePathname, customRouter);\n else\n throw Error(\n `ValidationError: The exported router from file-upload.router.${getUserFileExtension()} is not a valid express or arkos Router.`\n );\n }\n\n if (!basePathname.startsWith(\"/\")) basePathname = \"/\" + basePathname;\n if (!basePathname.endsWith(\"/\")) basePathname = basePathname + \"/\";\n\n if (!isEndpointDisabled(routerConfig, \"findFile\")) {\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(interceptors?.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?.expressStatic || {}\n )\n ),\n ...processMiddleware(interceptors?.onFindFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"uploadFile\")) {\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(interceptors?.beforeUploadFile),\n fileUploadController.uploadFile,\n ...processMiddleware(interceptors?.afterUploadFile),\n sendResponse,\n ...processMiddleware(interceptors?.onUploadFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"updateFile\")) {\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(interceptors?.beforeUpdateFile),\n fileUploadController.updateFile,\n ...processMiddleware(interceptors?.afterUpdateFile),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"deleteFile\")) {\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(interceptors?.beforeDeleteFile),\n fileUploadController.deleteFile,\n ...processMiddleware(interceptors?.afterDeleteFile),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteFileError, { type: \"error\" })\n );\n }\n\n debuggerService.logModuleFinalRouter(\"file-upload\", router);\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":";;;;;AAmBA,kDAuIC;AA1JD,qCAAiC;AACjC,+DAAiE;AACjE,wEAA+C;AAC/C,sFAA4D;AAC5D,sDAA8B;AAC9B,4FAA6D;AAE7D,+DAAwD;AACxD,yEAAwE;AACxE,6EAAuE;AACvE,mFAA+E;AAC/E,oFAA2D;AAC3D,sFAA6D;AAC7D,+DAAsE;AAEtE,gDAAwB;AAExB,MAAM,MAAM,GAAW,IAAA,gBAAM,GAAE,CAAC;AAEhC,SAAgB,mBAAmB,CAAC,WAAwB;IAC1D,MAAM,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;IAEnC,MAAM,gBAAgB,GAAG,IAAA,oCAAmB,EAAC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ader\";\nimport authService from \"../auth/auth.service\";\nimport fileUploadController from \"./file-upload.controller\";\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\";\nimport { isEndpointDisabled } from \"../base/utils/helpers/base.router.helpers\";\nimport debuggerService from \"../debugger/debugger.service\";\nimport routerValidator from \"../base/utils/router-validator\";\nimport { getUserFileExtension } from \"../../utils/helpers/fs.helpers\";\nimport { ArkosConfig } from \"../../exports\";\nimport path from \"path\";\n\nconst router: Router = Router();\n\nexport function getFileUploadRouter(arkosConfig: ArkosConfig) {\n const { fileUpload } = arkosConfig;\n\n const moduleComponents = getModuleComponents(\"file-upload\");\n let {\n interceptors = {} as any,\n authConfigs = {} as AuthConfigs,\n router: customRouterModule,\n }: any = {};\n\n if (moduleComponents)\n ({\n interceptors = {},\n authConfigs = {},\n router: customRouterModule,\n } = moduleComponents);\n\n const routerConfig = customRouterModule?.config || {};\n if (routerConfig?.disable === true) return router;\n\n const customRouter = customRouterModule?.default as Router;\n let basePathname = fileUpload?.baseRoute || \"/api/uploads/\";\n\n if (customRouter && customRouterModule) {\n if (routerValidator.isExpressRouter(customRouter))\n router.use(basePathname, customRouter);\n else\n throw Error(\n `ValidationError: The exported router from file-upload.router.${getUserFileExtension()} is not a valid express or arkos Router.`\n );\n }\n\n if (!basePathname.startsWith(\"/\")) basePathname = \"/\" + basePathname;\n if (!basePathname.endsWith(\"/\")) basePathname = basePathname + \"/\";\n\n if (!isEndpointDisabled(routerConfig, \"findFile\")) {\n const baseUploadDirFullPath = path.resolve(\n path\n .join(process.cwd(), fileUpload?.baseUploadDir || \"uploads\")\n .replaceAll(\"//\", \"/\")\n );\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(interceptors?.beforeFindFile),\n adjustRequestUrl,\n express.static(\n baseUploadDirFullPath,\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?.expressStatic || {}\n )\n ),\n ...processMiddleware(interceptors?.onFindFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"uploadFile\")) {\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(interceptors?.beforeUploadFile),\n fileUploadController.uploadFile,\n ...processMiddleware(interceptors?.afterUploadFile),\n sendResponse,\n ...processMiddleware(interceptors?.onUploadFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"updateFile\")) {\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(interceptors?.beforeUpdateFile),\n fileUploadController.updateFile,\n ...processMiddleware(interceptors?.afterUpdateFile),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateFileError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"deleteFile\")) {\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(interceptors?.beforeDeleteFile),\n fileUploadController.deleteFile,\n ...processMiddleware(interceptors?.afterDeleteFile),\n sendResponse,\n ...processMiddleware(interceptors?.onDeleteFileError, { type: \"error\" })\n );\n }\n\n debuggerService.logModuleFinalRouter(\"file-upload\", router);\n return router;\n}\n"]}
@@ -4,12 +4,12 @@ exports.default = classValidatorToJsonSchema;
4
4
  exports.resolveReferences = resolveReferences;
5
5
  exports.extractSchemaName = extractSchemaName;
6
6
  const class_validator_1 = require("class-validator");
7
- const storage_1 = require("class-transformer/cjs/storage");
7
+ const storage_js_1 = require("class-transformer/cjs/storage.js");
8
8
  const class_validator_jsonschema_1 = require("class-validator-jsonschema");
9
9
  function classValidatorToJsonSchema(decoratedClass) {
10
10
  const jsonSchemas = (0, class_validator_jsonschema_1.validationMetadatasToSchemas)({
11
11
  classValidatorMetadataStorage: (0, class_validator_1.getMetadataStorage)(),
12
- classTransformerMetadataStorage: storage_1.defaultMetadataStorage,
12
+ classTransformerMetadataStorage: storage_js_1.defaultMetadataStorage,
13
13
  refPointerPrefix: "#/components/schemas/",
14
14
  });
15
15
  const targetSchema = jsonSchemas[decoratedClass.name];
@@ -1 +1 @@
1
- {"version":3,"file":"class-validator-to-json-schema.js","sourceRoot":"","sources":["../../../../../../src/modules/swagger/utils/helpers/class-validator-to-json-schema.ts"],"names":[],"mappings":";;AAIA,6CAcC;AAED,8CAuCC;AAED,8CAGC;AAhED,qDAAqD;AACrD,2DAAuE;AACvE,2EAA0E;AAE1E,SAAwB,0BAA0B,CAChD,cAA8C;IAE9C,MAAM,WAAW,GAAG,IAAA,yDAA4B,EAAC;QAC/C,6BAA6B,EAAE,IAAA,oCAAkB,GAAE;QACnD,+BAA+B,EAAE,gCAAsB;QACvD,gBAAgB,EAAE,uBAAuB;KAC1C,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAEtD,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAE/B,OAAO,iBAAiB,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;AACtD,CAAC;AAED,SAAgB,iBAAiB,CAC/B,MAAW,EAC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,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAgB,iBAAiB,CAAC,GAAW;IAC3C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import { getMetadataStorage } from \"class-validator\";\nimport { defaultMetadataStorage } from \"class-transformer/cjs/storage\";\nimport { validationMetadatasToSchemas } from \"class-validator-jsonschema\";\n\nexport default function classValidatorToJsonSchema(\n decoratedClass: new (...args: any[]) => object\n): any {\n const jsonSchemas = validationMetadatasToSchemas({\n classValidatorMetadataStorage: getMetadataStorage(),\n classTransformerMetadataStorage: defaultMetadataStorage,\n refPointerPrefix: \"#/components/schemas/\",\n });\n\n const targetSchema = jsonSchemas[decoratedClass.name];\n\n if (!targetSchema) return null;\n\n return resolveReferences(targetSchema, jsonSchemas);\n}\n\nexport function resolveReferences(\n schema: any,\n allSchemas: Record<string, any>,\n visited = new Set<string>()\n): any {\n if (!schema || typeof schema !== \"object\") return schema;\n\n if (schema.$ref) {\n const refName = extractSchemaName(schema.$ref);\n\n if (visited.has(refName))\n return {\n $resolvedRef: refName,\n description: `Circular reference to ${refName}`,\n };\n\n const referencedSchema = allSchemas[refName];\n if (referencedSchema) {\n visited.add(refName);\n const resolved = resolveReferences(referencedSchema, allSchemas, visited);\n visited.delete(refName);\n\n const { $ref, ...rest } = schema;\n return { ...resolved, ...rest };\n }\n\n return schema;\n }\n\n if (Array.isArray(schema)) {\n return schema.map((item) => resolveReferences(item, allSchemas, visited));\n }\n\n const result: any = {};\n for (const [key, value] of Object.entries(schema)) {\n result[key] = resolveReferences(value, allSchemas, visited);\n }\n\n return result;\n}\n\nexport function extractSchemaName(ref: string): string {\n const parts = ref.split(\"/\");\n return parts[parts.length - 1];\n}\n"]}
1
+ {"version":3,"file":"class-validator-to-json-schema.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,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;YACjC,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC;QAClC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED,MAAM,MAAM,GAAQ,EAAE,CAAC;IACvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,MAAM,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAgB,iBAAiB,CAAC,GAAW;IAC3C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import { getMetadataStorage } from \"class-validator\";\nimport { defaultMetadataStorage } from \"class-transformer/cjs/storage.js\";\nimport { validationMetadatasToSchemas } from \"class-validator-jsonschema\";\n\nexport default function classValidatorToJsonSchema(\n decoratedClass: new (...args: any[]) => object\n): any {\n const jsonSchemas = validationMetadatasToSchemas({\n classValidatorMetadataStorage: getMetadataStorage(),\n classTransformerMetadataStorage: defaultMetadataStorage,\n refPointerPrefix: \"#/components/schemas/\",\n });\n\n const targetSchema = jsonSchemas[decoratedClass.name];\n\n if (!targetSchema) return null;\n\n return resolveReferences(targetSchema, jsonSchemas);\n}\n\nexport function resolveReferences(\n schema: any,\n allSchemas: Record<string, any>,\n visited = new Set<string>()\n): any {\n if (!schema || typeof schema !== \"object\") return schema;\n\n if (schema.$ref) {\n const refName = extractSchemaName(schema.$ref);\n\n if (visited.has(refName))\n return {\n $resolvedRef: refName,\n description: `Circular reference to ${refName}`,\n };\n\n const referencedSchema = allSchemas[refName];\n if (referencedSchema) {\n visited.add(refName);\n const resolved = resolveReferences(referencedSchema, allSchemas, visited);\n visited.delete(refName);\n\n const { $ref, ...rest } = schema;\n return { ...resolved, ...rest };\n }\n\n return schema;\n }\n\n if (Array.isArray(schema)) {\n return schema.map((item) => resolveReferences(item, allSchemas, visited));\n }\n\n const result: any = {};\n for (const [key, value] of Object.entries(schema)) {\n result[key] = resolveReferences(value, allSchemas, visited);\n }\n\n return result;\n}\n\nexport function extractSchemaName(ref: string): string {\n const parts = ref.split(\"/\");\n return parts[parts.length - 1];\n}\n"]}
@@ -10,7 +10,7 @@ const dynamic_loader_1 = require("../../../../../utils/dynamic-loader");
10
10
  const swagger_router_helpers_1 = require("../swagger.router.helpers");
11
11
  const prisma_schema_parser_1 = __importDefault(require("../../../../../utils/prisma/prisma-schema-parser"));
12
12
  const fs_helpers_1 = require("../../../../../utils/helpers/fs.helpers");
13
- const storage_1 = require("class-transformer/cjs/storage");
13
+ const storage_js_1 = require("class-transformer/cjs/storage.js");
14
14
  function generateClassValidatorJsonSchemas() {
15
15
  const requiredAppModules = [
16
16
  ...prisma_schema_parser_1.default.getModelsAsArrayOfStrings(),
@@ -19,7 +19,7 @@ function generateClassValidatorJsonSchemas() {
19
19
  const schemas = {};
20
20
  const jsonSchema = (0, class_validator_jsonschema_1.validationMetadatasToSchemas)({
21
21
  classValidatorMetadataStorage: (0, class_validator_1.getMetadataStorage)(),
22
- classTransformerMetadataStorage: storage_1.defaultMetadataStorage,
22
+ classTransformerMetadataStorage: storage_js_1.defaultMetadataStorage,
23
23
  refPointerPrefix: "#/components/schemas/",
24
24
  });
25
25
  requiredAppModules.forEach((modelName) => {
@@ -1 +1 @@
1
- {"version":3,"file":"generate-class-validator-json-schemas.js","sourceRoot":"","sources":["../../../../../../../src/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.ts"],"names":[],"mappings":";;;;;AAQA,8EA+CC;AAvDD,2EAA0E;AAC1E,qDAAqD;AACrD,wEAA0E;AAC1E,sEAAqE;AACrE,4GAAkF;AAClF,wEAA+E;AAC/E,2DAAuE;AAEvE,SAAgB,iCAAiC;IAC/C,MAAM,kBAAkB,GAAG;QACzB,GAAG,8BAAkB,CAAC,yBAAyB,EAAE;QACjD,MAAM;KACP,CAAC;IACF,MAAM,OAAO,GAAwB,EAAE,CAAC;IAExC,MAAM,UAAU,GAAG,IAAA,yDAA4B,EAAC;QAC9C,6BAA6B,EAAE,IAAA,oCAAkB,GAAE;QACnD,+BAA+B,EAAE,gCAAsB;QACvD,gBAAgB,EAAE,uBAAuB;KAC1C,CAAC,CAAC;IAEH,kBAAkB,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QACvC,MAAM,gBAAgB,GAAG,IAAA,oCAAmB,EAAC,SAAS,CAAC,CAAC;QAExD,IAAI,gBAAgB,EAAE,IAAI,EAAE,CAAC;YAC3B,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,EAAE;gBACpE,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;gBACnD,IAAI,QAAQ,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;oBACjE,IAAI,CAAC;wBACH,MAAM,UAAU,GAAG,IAAA,iDAAwB,EACzC,OAAO,EACP,SAAS,EACT,KAAK,CACN,CAAC;wBAEF,IAAI,OAAO,CAAC,UAAU,CAAC;4BACrB,MAAM,KAAK,CACT,qBAAqB,QAAQ,CAAC,IAAI,4BAA4B,IAAA,iCAAoB,GAAE,uFAAuF,CAC5K,CAAC;wBAEJ,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;oBACxD,CAAC;oBAAC,OAAO,GAAQ,EAAE,CAAC;wBAClB,MAAM,IAAI,KAAK,CACb,iCAAiC,OAAO,IAAI,SAAS,KAAK,GAAG,CAAC,OAAO,EAAE,CACxE,CAAC;oBACJ,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE;QACzD,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;YAAE,OAAO,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { validationMetadatasToSchemas } from \"class-validator-jsonschema\";\nimport { getMetadataStorage } from \"class-validator\";\nimport { getModuleComponents } from \"../../../../../utils/dynamic-loader\";\nimport { getCorrectJsonSchemaName } from \"../swagger.router.helpers\";\nimport prismaSchemaParser from \"../../../../../utils/prisma/prisma-schema-parser\";\nimport { getUserFileExtension } from \"../../../../../utils/helpers/fs.helpers\";\nimport { defaultMetadataStorage } from \"class-transformer/cjs/storage\";\n\nexport function generateClassValidatorJsonSchemas() {\n const requiredAppModules = [\n ...prismaSchemaParser.getModelsAsArrayOfStrings(),\n \"auth\",\n ];\n const schemas: Record<string, any> = {};\n\n const jsonSchema = validationMetadatasToSchemas({\n classValidatorMetadataStorage: getMetadataStorage(),\n classTransformerMetadataStorage: defaultMetadataStorage,\n refPointerPrefix: \"#/components/schemas/\",\n });\n\n requiredAppModules.forEach((modelName) => {\n const moduleComponents = getModuleComponents(modelName);\n\n if (moduleComponents?.dtos) {\n Object.entries(moduleComponents.dtos).forEach(([dtoType, dtoClass]) => {\n const ignoredDtoTypes = [\"createone\", \"updateone\"];\n if (dtoClass && !ignoredDtoTypes.includes(dtoType.toLowerCase())) {\n try {\n const schemaName = getCorrectJsonSchemaName(\n dtoType,\n modelName,\n \"Dto\"\n );\n\n if (schemas[schemaName])\n throw Error(\n `Found more then 1 ${dtoClass.name} classes among your .dto.${getUserFileExtension()} files, there is no way to correctly generate json-schemas for swagger documentation.`\n );\n\n schemas[schemaName] = jsonSchema[dtoClass.name] || {};\n } catch (err: any) {\n throw new Error(\n `Failed to generate schema for ${dtoType} ${modelName}: ${err.message}`\n );\n }\n }\n });\n }\n });\n\n Object.entries(jsonSchema).forEach(([className, schema]) => {\n if (!schemas[className]) schemas[className] = schema;\n });\n return schemas;\n}\n"]}
1
+ {"version":3,"file":"generate-class-validator-json-schemas.js","sourceRoot":"","sources":["../../../../../../../src/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.ts"],"names":[],"mappings":";;;;;AAQA,8EA+CC;AAvDD,2EAA0E;AAC1E,qDAAqD;AACrD,wEAA0E;AAC1E,sEAAqE;AACrE,4GAAkF;AAClF,wEAA+E;AAC/E,iEAA0E;AAE1E,SAAgB,iCAAiC;IAC/C,MAAM,kBAAkB,GAAG;QACzB,GAAG,8BAAkB,CAAC,yBAAyB,EAAE;QACjD,MAAM;KACP,CAAC;IACF,MAAM,OAAO,GAAwB,EAAE,CAAC;IAExC,MAAM,UAAU,GAAG,IAAA,yDAA4B,EAAC;QAC9C,6BAA6B,EAAE,IAAA,oCAAkB,GAAE;QACnD,+BAA+B,EAAE,mCAAsB;QACvD,gBAAgB,EAAE,uBAAuB;KAC1C,CAAC,CAAC;IAEH,kBAAkB,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QACvC,MAAM,gBAAgB,GAAG,IAAA,oCAAmB,EAAC,SAAS,CAAC,CAAC;QAExD,IAAI,gBAAgB,EAAE,IAAI,EAAE,CAAC;YAC3B,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,EAAE;gBACpE,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;gBACnD,IAAI,QAAQ,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;oBACjE,IAAI,CAAC;wBACH,MAAM,UAAU,GAAG,IAAA,iDAAwB,EACzC,OAAO,EACP,SAAS,EACT,KAAK,CACN,CAAC;wBAEF,IAAI,OAAO,CAAC,UAAU,CAAC;4BACrB,MAAM,KAAK,CACT,qBAAqB,QAAQ,CAAC,IAAI,4BAA4B,IAAA,iCAAoB,GAAE,uFAAuF,CAC5K,CAAC;wBAEJ,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;oBACxD,CAAC;oBAAC,OAAO,GAAQ,EAAE,CAAC;wBAClB,MAAM,IAAI,KAAK,CACb,iCAAiC,OAAO,IAAI,SAAS,KAAK,GAAG,CAAC,OAAO,EAAE,CACxE,CAAC;oBACJ,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE;QACzD,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;YAAE,OAAO,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { validationMetadatasToSchemas } from \"class-validator-jsonschema\";\nimport { getMetadataStorage } from \"class-validator\";\nimport { getModuleComponents } from \"../../../../../utils/dynamic-loader\";\nimport { getCorrectJsonSchemaName } from \"../swagger.router.helpers\";\nimport prismaSchemaParser from \"../../../../../utils/prisma/prisma-schema-parser\";\nimport { getUserFileExtension } from \"../../../../../utils/helpers/fs.helpers\";\nimport { defaultMetadataStorage } from \"class-transformer/cjs/storage.js\";\n\nexport function generateClassValidatorJsonSchemas() {\n const requiredAppModules = [\n ...prismaSchemaParser.getModelsAsArrayOfStrings(),\n \"auth\",\n ];\n const schemas: Record<string, any> = {};\n\n const jsonSchema = validationMetadatasToSchemas({\n classValidatorMetadataStorage: getMetadataStorage(),\n classTransformerMetadataStorage: defaultMetadataStorage,\n refPointerPrefix: \"#/components/schemas/\",\n });\n\n requiredAppModules.forEach((modelName) => {\n const moduleComponents = getModuleComponents(modelName);\n\n if (moduleComponents?.dtos) {\n Object.entries(moduleComponents.dtos).forEach(([dtoType, dtoClass]) => {\n const ignoredDtoTypes = [\"createone\", \"updateone\"];\n if (dtoClass && !ignoredDtoTypes.includes(dtoType.toLowerCase())) {\n try {\n const schemaName = getCorrectJsonSchemaName(\n dtoType,\n modelName,\n \"Dto\"\n );\n\n if (schemas[schemaName])\n throw Error(\n `Found more then 1 ${dtoClass.name} classes among your .dto.${getUserFileExtension()} files, there is no way to correctly generate json-schemas for swagger documentation.`\n );\n\n schemas[schemaName] = jsonSchema[dtoClass.name] || {};\n } catch (err: any) {\n throw new Error(\n `Failed to generate schema for ${dtoType} ${modelName}: ${err.message}`\n );\n }\n }\n });\n }\n });\n\n Object.entries(jsonSchema).forEach(([className, schema]) => {\n if (!schemas[className]) schemas[className] = schema;\n });\n return schemas;\n}\n"]}
@@ -35,8 +35,8 @@ function ArkosRouter() {
35
35
  return function (config, ...handlers) {
36
36
  if (config.disabled)
37
37
  return;
38
- const route = config.path;
39
- if (!route)
38
+ const path = config.path;
39
+ if (!path)
40
40
  throw Error("Please pass valid value for path field to use in your route");
41
41
  if (!route_config_validator_1.default.isArkosRouteConfig(config))
42
42
  throw Error(`First argument of ArkosRouter().${prop}() must be a valid ArkosRouteConfig object with path field, but recevied ${typeof config === "object" ? JSON.stringify(config, null, 2) : config}`);
@@ -58,6 +58,7 @@ function ArkosRouter() {
58
58
  const validationConfig = arkosConfig.validation;
59
59
  const authenticationConfig = arkosConfig.authentication;
60
60
  const strictValidation = validationConfig?.strict;
61
+ const route = `${method.toUpperCase()} ${path}`;
61
62
  if (strictValidation &&
62
63
  (!("validation" in config) ||
63
64
  ("validation" in config &&
@@ -65,14 +66,14 @@ function ArkosRouter() {
65
66
  config.validation !== undefined)))
66
67
  throw Error("When using strict validation you must either pass { validation: false } in order to explicitly tell that no input will be received, or pass `undefined` for each input type e.g { validation: { query: undefined } } in order to deny the input of given request input.");
67
68
  if (!validationConfig?.resolver && config.validation)
68
- throw Error("Trying to pass validators into route config validation option without choosing a validation resolver under arkos.init({ validation: { resolver: '' } })");
69
+ throw Error(`Trying to pass validators into route ${route} config validation option without choosing a validation resolver under arkos.init({ validation: { resolver: '' } })`);
69
70
  if (config.authentication && !authenticationConfig?.mode)
70
- throw Error("Trying to authenticate a route without choosing an authentication mode under arkos.init({ authentication: { mode: '' } })");
71
+ throw Error(`Trying to authenticate route ${route} without choosing an authentication mode under arkos.init({ authentication: { mode: '' } })`);
71
72
  handlers = [...(0, helpers_1.getMiddlewareStack)(config), ...handlers];
72
73
  if (config.experimental?.uploads &&
73
74
  config.experimental.uploads.deleteOnError !== false)
74
75
  handlers.push((0, error_handler_1.catchAsync)(upload_manager_1.default.handleFileCleanup(config.experimental.uploads), { type: "error" }));
75
- return originalMethod.call(target, route, ...handlers);
76
+ return originalMethod.call(target, path, ...handlers);
76
77
  };
77
78
  }
78
79
  return originalMethod;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/arkos-router/index.ts"],"names":[],"mappings":";;;;;AAsCA,8BA6GC;AAED,wDAkFC;AAvOD,qCAAiC;AAGjC,sFAA4D;AAC5D,oFAA0D;AAC1D,6CAAyE;AACzE,2CAA+C;AAC/C,+DAAyD;AAEzD,4EAAiD;AACjD,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AAI,IAAI,EAAE;YAChD,WAAW,EAAE,OAAO,EAAE,WAAW,IAAI,GAAG,MAAM,IAAI,IAAI,EAAE;YACxD,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC;YACnC,WAAW,EAAE,GAAG,MAAM,CAAC,WAAW,EAAE,IAAI,IAAI,EAAE;YAC9C,UAAU,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,GAAG,UAAU,CAAC;YACnE,GAAG,CAAC,CAAC,gBAAgB,CAAC,WAAW;gBAC/B,MAAM,EAAE,UAAU;gBAClB,MAAM,EAAE,UAAU,EAAE,IAAI,IAAI;gBAC1B,WAAW,EAAE;oBACX,OAAO,EAAE;wBACP,kBAAkB,EAAE;4BAClB,MAAM,EAAE,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,IAAW,CAAC;yBAC/D;qBACF;iBACF;aACF,CAAC;YACJ,GAAG,gBAAgB;SACpB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { IArkosRouter, ArkosRouteConfig } from \"./types\";\nimport { OpenAPIV3 } from \"openapi-types\";\nimport RouteConfigValidator from \"./route-config-validator\";\nimport RouteConfigRegistry from \"./route-config-registry\";\nimport { extractArkosRoutes, getMiddlewareStack } from \"./utils/helpers\";\nimport { getArkosConfig } from \"../../exports\";\nimport { catchAsync } from \"../../exports/error-handler\";\nimport { ArkosErrorRequestHandler, ArkosRequestHandler } from \"../../types\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport classValidatorToJsonSchema from \"../../modules/swagger/utils/helpers/class-validator-to-json-schema\";\nimport openApiSchemaConverter from \"../../modules/swagger/utils/helpers/openapi-schema-converter\";\nimport uploadManager from \"./utils/helpers/upload-manager\";\n\n/**\n * Creates an enhanced Express Router with features like OpenAPI documentation capabilities and smart data validation.\n *\n * The ArkosRouter extends the standard Express Router with the ability to\n * automatically capture OpenAPI metadata from route configurations.\n *\n * @example\n * const router = ArkosRouter();\n *\n * router.get(\n * {\n * path: \"/users/:id\",\n * openapi: {\n * summary: \"Get user by ID\",\n * tags: [\"Users\"]\n * }\n * },\n * (req, res) => { ... }\n * );\n *\n * @returns {IArkosRouter} A proxied Express Router instance with enhanced OpenAPI capabilities\n *\n * @see {@link ArkosRouteConfig} for configuration options\n */\nexport default function ArkosRouter(): IArkosRouter {\n const router: IArkosRouter = Router();\n\n return new Proxy(router, {\n get(target, prop, receiver) {\n const originalMethod = Reflect.get(target, prop, receiver);\n\n const httpMethods = [\n \"get\",\n \"post\",\n \"put\",\n \"patch\",\n \"delete\",\n \"all\",\n \"head\",\n \"trace\",\n \"options\",\n ];\n\n type ArkosAnyRequestHandler =\n | ArkosRequestHandler\n | ArkosErrorRequestHandler;\n\n if (httpMethods.includes(prop as string)) {\n return function (\n config: ArkosRouteConfig,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n if (config.disabled) return;\n\n const route = config.path;\n\n if (!route)\n throw Error(\n \"Please pass valid value for path field to use in your route\"\n );\n\n if (!RouteConfigValidator.isArkosRouteConfig(config))\n throw Error(\n `First argument of ArkosRouter().${prop as string}() must be a valid ArkosRouteConfig object with path field, but recevied ${typeof config === \"object\" ? JSON.stringify(config, null, 2) : config}`\n );\n\n const method = prop as string;\n\n if (handlers.length > 0) {\n handlers = handlers.map(\n (handler: ArkosAnyRequestHandler | ArkosAnyRequestHandler[]) => {\n return typeof handler === \"function\"\n ? catchAsync(handler, {\n type: handler.length > 3 ? \"error\" : \"normal\",\n })\n : handler.map((nesteHandler: any) =>\n catchAsync(nesteHandler, {\n type: handler.length > 3 ? \"error\" : \"normal\",\n })\n );\n }\n );\n\n const finalHandler = handlers[handlers.length - 1];\n RouteConfigRegistry.register(finalHandler, config, method);\n }\n\n const arkosConfig = getArkosConfig();\n const validationConfig = arkosConfig.validation;\n const authenticationConfig = arkosConfig.authentication;\n const strictValidation = validationConfig?.strict;\n\n if (\n strictValidation &&\n (!(\"validation\" in config) ||\n (\"validation\" in config &&\n !config.validation &&\n config.validation !== undefined))\n )\n throw Error(\n \"When using strict validation you must either pass { validation: false } in order to explicitly tell that no input will be received, or pass `undefined` for each input type e.g { validation: { query: undefined } } in order to deny the input of given request input.\"\n );\n\n if (!validationConfig?.resolver && config.validation)\n throw Error(\n \"Trying to pass validators into route config validation option without choosing a validation resolver under arkos.init({ validation: { resolver: '' } })\"\n );\n\n if (config.authentication && !authenticationConfig?.mode)\n throw Error(\n \"Trying to authenticate a route without choosing an authentication mode under arkos.init({ authentication: { mode: '' } })\"\n );\n\n handlers = [...getMiddlewareStack(config), ...handlers];\n\n if (\n config.experimental?.uploads &&\n config.experimental.uploads.deleteOnError !== false\n )\n handlers.push(\n catchAsync(\n uploadManager.handleFileCleanup(config.experimental.uploads),\n { type: \"error\" }\n )\n );\n\n return originalMethod.call(target, route, ...handlers);\n };\n }\n // }\n return originalMethod;\n },\n }) as IArkosRouter;\n}\n\nexport function generateOpenAPIFromApp(app: any) {\n const routes = extractArkosRoutes(app);\n const arkosConfig = getArkosConfig();\n\n let paths: Record<\n string,\n Record<string, Partial<OpenAPIV3.OperationObject>>\n > = {};\n\n routes.forEach(({ path, method, config }) => {\n if (config?.experimental?.openapi === false) return;\n\n if (!paths[path]) paths[path] = {};\n\n if (typeof config?.experimental?.openapi === \"boolean\") {\n config = {\n ...config,\n experimental: {\n ...config.experimental,\n openapi: {},\n },\n };\n }\n\n const openapi =\n typeof config?.experimental?.openapi === \"object\" &&\n config.experimental.openapi !== null\n ? config.experimental.openapi\n : {};\n\n const validatorToJsonSchema =\n arkosConfig?.validation?.resolver === \"zod\"\n ? zodToJsonSchema\n : classValidatorToJsonSchema;\n\n let parameters = [];\n const validationToParameterMapping = {\n query: \"query\",\n params: \"path\",\n headers: \"header\",\n cookies: \"cookie\",\n };\n\n if (typeof config?.validation !== \"boolean\" && config?.validation) {\n for (const [key, val] of Object.entries(config?.validation)) {\n if ([\"body\"].includes(key)) continue;\n if ((config?.validation as any)[key]) {\n const jsonSchema = validatorToJsonSchema(val as any);\n const params = openApiSchemaConverter.jsonSchemaToOpeApiParameters(\n (validationToParameterMapping as any)[key],\n jsonSchema\n );\n parameters.push(...params);\n }\n }\n }\n\n const convertedOpenAPI =\n openApiSchemaConverter.convertOpenAPIConfig(openapi);\n\n (paths as any)[path][method.toLowerCase()] = {\n summary: openapi?.summary || `${method} ${path}`,\n description: openapi?.description || `${method} ${path}`,\n tags: openapi?.tags || [\"Defaults\"],\n operationId: `${method.toLowerCase()}:${path}`,\n parameters: [...(convertedOpenAPI.parameters || []), ...parameters],\n ...(!convertedOpenAPI.requestBody &&\n config?.validation &&\n config?.validation?.body && {\n requestBody: {\n content: {\n \"application/json\": {\n schema: validatorToJsonSchema(config?.validation?.body as any),\n },\n },\n },\n }),\n ...convertedOpenAPI,\n };\n });\n\n return paths;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/arkos-router/index.ts"],"names":[],"mappings":";;;;;AAsCA,8BA8GC;AAED,wDAkFC;AAxOD,qCAAiC;AAGjC,sFAA4D;AAC5D,oFAA0D;AAC1D,6CAAyE;AACzE,2CAA+C;AAC/C,+DAAyD;AAEzD,4EAAiD;AACjD,wIAA4G;AAC5G,4HAAkG;AAClG,oFAA2D;AA0B3D,SAAwB,WAAW;IACjC,MAAM,MAAM,GAAiB,IAAA,gBAAM,GAAE,CAAC;IAEtC,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAE3D,MAAM,WAAW,GAAG;gBAClB,KAAK;gBACL,MAAM;gBACN,KAAK;gBACL,OAAO;gBACP,QAAQ;gBACR,KAAK;gBACL,MAAM;gBACN,OAAO;gBACP,SAAS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AG,CAAC,CAAC,gBAAgB,CAAC,WAAW;gBAC/B,MAAM,EAAE,UAAU;gBAClB,MAAM,EAAE,UAAU,EAAE,IAAI,IAAI;gBAC1B,WAAW,EAAE;oBACX,OAAO,EAAE;wBACP,kBAAkB,EAAE;4BAClB,MAAM,EAAE,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,IAAW,CAAC;yBAC/D;qBACF;iBACF;aACF,CAAC;YACJ,GAAG,gBAAgB;SACpB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { IArkosRouter, ArkosRouteConfig } from \"./types\";\nimport { OpenAPIV3 } from \"openapi-types\";\nimport RouteConfigValidator from \"./route-config-validator\";\nimport RouteConfigRegistry from \"./route-config-registry\";\nimport { extractArkosRoutes, getMiddlewareStack } from \"./utils/helpers\";\nimport { getArkosConfig } from \"../../exports\";\nimport { catchAsync } from \"../../exports/error-handler\";\nimport { ArkosErrorRequestHandler, ArkosRequestHandler } from \"../../types\";\nimport zodToJsonSchema from \"zod-to-json-schema\";\nimport classValidatorToJsonSchema from \"../../modules/swagger/utils/helpers/class-validator-to-json-schema\";\nimport openApiSchemaConverter from \"../../modules/swagger/utils/helpers/openapi-schema-converter\";\nimport uploadManager from \"./utils/helpers/upload-manager\";\n\n/**\n * Creates an enhanced Express Router with features like OpenAPI documentation capabilities and smart data validation.\n *\n * The ArkosRouter extends the standard Express Router with the ability to\n * automatically capture OpenAPI metadata from route configurations.\n *\n * @example\n * const router = ArkosRouter();\n *\n * router.get(\n * {\n * path: \"/users/:id\",\n * openapi: {\n * summary: \"Get user by ID\",\n * tags: [\"Users\"]\n * }\n * },\n * (req, res) => { ... }\n * );\n *\n * @returns {IArkosRouter} A proxied Express Router instance with enhanced OpenAPI capabilities\n *\n * @see {@link ArkosRouteConfig} for configuration options\n */\nexport default function ArkosRouter(): IArkosRouter {\n const router: IArkosRouter = Router();\n\n return new Proxy(router, {\n get(target, prop, receiver) {\n const originalMethod = Reflect.get(target, prop, receiver);\n\n const httpMethods = [\n \"get\",\n \"post\",\n \"put\",\n \"patch\",\n \"delete\",\n \"all\",\n \"head\",\n \"trace\",\n \"options\",\n ];\n\n type ArkosAnyRequestHandler =\n | ArkosRequestHandler\n | ArkosErrorRequestHandler;\n\n if (httpMethods.includes(prop as string)) {\n return function (\n config: ArkosRouteConfig,\n ...handlers: ArkosAnyRequestHandler[]\n ) {\n if (config.disabled) return;\n\n const path = config.path;\n\n if (!path)\n throw Error(\n \"Please pass valid value for path field to use in your route\"\n );\n\n if (!RouteConfigValidator.isArkosRouteConfig(config))\n throw Error(\n `First argument of ArkosRouter().${prop as string}() must be a valid ArkosRouteConfig object with path field, but recevied ${typeof config === \"object\" ? JSON.stringify(config, null, 2) : config}`\n );\n\n const method = prop as string;\n\n if (handlers.length > 0) {\n handlers = handlers.map(\n (handler: ArkosAnyRequestHandler | ArkosAnyRequestHandler[]) => {\n return typeof handler === \"function\"\n ? catchAsync(handler, {\n type: handler.length > 3 ? \"error\" : \"normal\",\n })\n : handler.map((nesteHandler: any) =>\n catchAsync(nesteHandler, {\n type: handler.length > 3 ? \"error\" : \"normal\",\n })\n );\n }\n );\n\n const finalHandler = handlers[handlers.length - 1];\n RouteConfigRegistry.register(finalHandler, config, method);\n }\n\n const arkosConfig = getArkosConfig();\n const validationConfig = arkosConfig.validation;\n const authenticationConfig = arkosConfig.authentication;\n const strictValidation = validationConfig?.strict;\n const route = `${method.toUpperCase()} ${path}`;\n\n if (\n strictValidation &&\n (!(\"validation\" in config) ||\n (\"validation\" in config &&\n !config.validation &&\n config.validation !== undefined))\n )\n throw Error(\n \"When using strict validation you must either pass { validation: false } in order to explicitly tell that no input will be received, or pass `undefined` for each input type e.g { validation: { query: undefined } } in order to deny the input of given request input.\"\n );\n\n if (!validationConfig?.resolver && config.validation)\n throw Error(\n `Trying to pass validators into route ${route} config validation option without choosing a validation resolver under arkos.init({ validation: { resolver: '' } })`\n );\n\n if (config.authentication && !authenticationConfig?.mode)\n throw Error(\n `Trying to authenticate route ${route} without choosing an authentication mode under arkos.init({ authentication: { mode: '' } })`\n );\n\n handlers = [...getMiddlewareStack(config), ...handlers];\n\n if (\n config.experimental?.uploads &&\n config.experimental.uploads.deleteOnError !== false\n )\n handlers.push(\n catchAsync(\n uploadManager.handleFileCleanup(config.experimental.uploads),\n { type: \"error\" }\n )\n );\n\n return originalMethod.call(target, path, ...handlers);\n };\n }\n // }\n return originalMethod;\n },\n }) as IArkosRouter;\n}\n\nexport function generateOpenAPIFromApp(app: any) {\n const routes = extractArkosRoutes(app);\n const arkosConfig = getArkosConfig();\n\n let paths: Record<\n string,\n Record<string, Partial<OpenAPIV3.OperationObject>>\n > = {};\n\n routes.forEach(({ path, method, config }) => {\n if (config?.experimental?.openapi === false) return;\n\n if (!paths[path]) paths[path] = {};\n\n if (typeof config?.experimental?.openapi === \"boolean\") {\n config = {\n ...config,\n experimental: {\n ...config.experimental,\n openapi: {},\n },\n };\n }\n\n const openapi =\n typeof config?.experimental?.openapi === \"object\" &&\n config.experimental.openapi !== null\n ? config.experimental.openapi\n : {};\n\n const validatorToJsonSchema =\n arkosConfig?.validation?.resolver === \"zod\"\n ? zodToJsonSchema\n : classValidatorToJsonSchema;\n\n let parameters = [];\n const validationToParameterMapping = {\n query: \"query\",\n params: \"path\",\n headers: \"header\",\n cookies: \"cookie\",\n };\n\n if (typeof config?.validation !== \"boolean\" && config?.validation) {\n for (const [key, val] of Object.entries(config?.validation)) {\n if ([\"body\"].includes(key)) continue;\n if ((config?.validation as any)[key]) {\n const jsonSchema = validatorToJsonSchema(val as any);\n const params = openApiSchemaConverter.jsonSchemaToOpeApiParameters(\n (validationToParameterMapping as any)[key],\n jsonSchema\n );\n parameters.push(...params);\n }\n }\n }\n\n const convertedOpenAPI =\n openApiSchemaConverter.convertOpenAPIConfig(openapi);\n\n (paths as any)[path][method.toLowerCase()] = {\n summary: openapi?.summary || `${method} ${path}`,\n description: openapi?.description || `${method} ${path}`,\n tags: openapi?.tags || [\"Defaults\"],\n operationId: `${method.toLowerCase()}:${path}`,\n parameters: [...(convertedOpenAPI.parameters || []), ...parameters],\n ...(!convertedOpenAPI.requestBody &&\n config?.validation &&\n config?.validation?.body && {\n requestBody: {\n content: {\n \"application/json\": {\n schema: validatorToJsonSchema(config?.validation?.body as any),\n },\n },\n },\n }),\n ...convertedOpenAPI,\n };\n });\n\n return paths;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=body-parser-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-parser-config.js","sourceRoot":"","sources":["../../../../../src/utils/arkos-router/types/body-parser-config.ts"],"names":[],"mappings":"","sourcesContent":["import express from \"express\";\nimport { Options as MulterOptions } from \"multer\";\n\nexport type BodyParserConfig =\n | { parser: \"json\"; options?: Parameters<typeof express.json>[0] }\n | {\n parser: \"urlencoded\";\n options?: Parameters<typeof express.urlencoded>[0];\n }\n | { parser: \"raw\"; options?: Parameters<typeof express.raw>[0] }\n | { parser: \"multipart\"; options?: MulterOptions[\"limits\"] }\n | { parser: \"text\"; options?: Parameters<typeof express.text>[0] };\n"]}