arkos 1.4.0-canary.62 → 1.4.0-canary.64

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 (27) hide show
  1. package/dist/cjs/app.js.map +1 -1
  2. package/dist/cjs/modules/auth/auth.router.js +18 -19
  3. package/dist/cjs/modules/auth/auth.router.js.map +1 -1
  4. package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +8 -51
  5. package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
  6. package/dist/cjs/utils/arkos-router/index.js +9 -7
  7. package/dist/cjs/utils/arkos-router/index.js.map +1 -1
  8. package/dist/cjs/utils/arkos-router/utils/helpers/index.js +3 -3
  9. package/dist/cjs/utils/arkos-router/utils/helpers/index.js.map +1 -1
  10. package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
  11. package/dist/cjs/utils/helpers/routers.helpers.js +55 -4
  12. package/dist/cjs/utils/helpers/routers.helpers.js.map +1 -1
  13. package/dist/esm/app.js.map +1 -1
  14. package/dist/esm/modules/auth/auth.router.js +20 -21
  15. package/dist/esm/modules/auth/auth.router.js.map +1 -1
  16. package/dist/esm/modules/base/utils/helpers/base.router.helpers.js +9 -52
  17. package/dist/esm/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
  18. package/dist/esm/utils/arkos-router/index.js +9 -7
  19. package/dist/esm/utils/arkos-router/index.js.map +1 -1
  20. package/dist/esm/utils/arkos-router/utils/helpers/index.js +1 -1
  21. package/dist/esm/utils/arkos-router/utils/helpers/index.js.map +1 -1
  22. package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
  23. package/dist/esm/utils/helpers/routers.helpers.js +53 -4
  24. package/dist/esm/utils/helpers/routers.helpers.js.map +1 -1
  25. package/dist/types/modules/auth/auth.router.d.ts +1 -2
  26. package/dist/types/utils/helpers/routers.helpers.d.ts +8 -0
  27. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sourceRoot":"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H,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,EACnB,eAAe,CAChB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAI,iBAAiB,EAAE,YAAY,KAAK,KAAK,EAAE,CAAC;QAC9C,IAAI,OAAO,iBAAiB,EAAE,YAAY,KAAK,UAAU,EAAE,CAAC;YAC1D,WAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,WAAG,CAAC,GAAG,CAAC,kCAAY,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO,WAAG,CAAC;AACb,CAAC","sourcesContent":["import express, { IRouter, Router } from \"express\";\nimport cors from \"cors\";\nimport cookieParser from \"cookie-parser\";\nimport { getAuthRouter } from \"./modules/auth/auth.router\";\nimport {\n getPrismaModelsRouter,\n getAvailableResourcesAndRoutesRouter,\n} from \"./modules/base/base.router\";\nimport errorHandler from \"./modules/error-handler/error-handler.controller\";\nimport { rateLimit } from \"express-rate-limit\";\nimport compression from \"compression\";\nimport { handleRequestLogs } from \"./modules/base/base.middlewares\";\nimport { loadPrismaModule } from \"./utils/helpers/prisma.helpers\";\nimport { getFileUploadRouter } from \"./modules/file-upload/file-upload.router\";\nimport { queryParser } from \"./utils/helpers/query-parser.helpers\";\nimport deepmerge from \"./utils/helpers/deepmerge.helper\";\nimport { getSwaggerRouter } from \"./modules/swagger/swagger.router\";\nimport { loadAllModuleComponents } from \"./utils/dynamic-loader\";\nimport { AppError } from \"./exports/error-handler\";\nimport debuggerService from \"./modules/debugger/debugger.service\";\nimport { getArkosConfig } from \"./exports\";\nimport { ArkosInitConfig } from \"./types/arkos-config\";\nimport { isAuthenticationEnabled } from \"./utils/helpers/arkos-config.helpers\";\nexport const app: express.Express = express();\nconst knowModulesRouter = Router();\n\nexport async function bootstrap(\n initConfig: ArkosInitConfig\n): Promise<express.Express> {\n const arkosConfig = getArkosConfig();\n\n await Promise.all([\n loadPrismaModule(),\n loadAllModuleComponents(arkosConfig),\n initConfig?.configureApp && (await initConfig?.configureApp(app)),\n ]);\n\n const middlewaresConfig = arkosConfig?.middlewares;\n\n if (middlewaresConfig?.compression !== false) {\n if (typeof middlewaresConfig?.compression === \"function\") {\n app.use(middlewaresConfig.compression);\n } else {\n app.use(compression(middlewaresConfig?.compression || {}));\n }\n }\n\n if (middlewaresConfig?.rateLimit !== false) {\n if (typeof middlewaresConfig?.rateLimit === \"function\") {\n app.use(middlewaresConfig.rateLimit);\n } else {\n app.use(\n rateLimit(\n deepmerge(\n {\n windowMs: 60 * 1000,\n limit: 300,\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 middlewaresConfig?.rateLimit || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.cors !== false) {\n if (typeof middlewaresConfig?.cors === \"function\") {\n app.use(middlewaresConfig.cors);\n } else {\n app.use(\n cors(\n middlewaresConfig?.cors?.customHandler\n ? middlewaresConfig.cors.customHandler\n : deepmerge(\n {\n origin: (\n origin: string,\n cb: (err: Error | null, allow?: boolean) => void\n ) => {\n const allowed = (middlewaresConfig?.cors as any)\n ?.allowedOrigins;\n\n if (allowed === \"*\") cb(null, true);\n else if (Array.isArray(allowed))\n cb(null, !origin || allowed?.includes?.(origin));\n else if (typeof allowed === \"string\")\n cb(null, !origin || allowed === origin);\n else cb(null, false);\n },\n\n methods: [\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\"],\n allowedHeaders: [\n \"Content-Type\",\n \"Authorization\",\n \"Connection\",\n ],\n credentials: true,\n },\n middlewaresConfig?.cors?.options || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.expressJson !== false) {\n if (typeof middlewaresConfig?.expressJson === \"function\") {\n app.use(middlewaresConfig.expressJson);\n } else {\n app.use(express.json(middlewaresConfig?.expressJson || {}));\n }\n }\n\n if (middlewaresConfig?.cookieParser !== false) {\n if (typeof middlewaresConfig?.cookieParser === \"function\") {\n app.use(middlewaresConfig.cookieParser);\n } else {\n const params = Array.isArray(middlewaresConfig?.cookieParser)\n ? middlewaresConfig.cookieParser\n : [];\n app.use(cookieParser(...(params as any))); // FIXME: check types correctly\n }\n }\n\n if (middlewaresConfig?.queryParser !== false) {\n if (typeof middlewaresConfig?.queryParser === \"function\") {\n app.use(middlewaresConfig.queryParser);\n } else {\n app.use(\n queryParser(\n deepmerge(\n {\n parseNull: true,\n parseUndefined: true,\n parseBoolean: true,\n parseNumber: true,\n },\n middlewaresConfig?.queryParser || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.requestLogger !== false) {\n if (typeof middlewaresConfig?.requestLogger === \"function\") {\n app.use(middlewaresConfig.requestLogger);\n } else {\n app.use(handleRequestLogs);\n }\n }\n\n app.use(debuggerService.logRequestInfo);\n\n const routersConfig = arkosConfig?.routers;\n\n if (routersConfig?.welcomeRoute !== false) {\n if (typeof routersConfig?.welcomeRoute === \"function\") {\n app.get(\"/api\", routersConfig.welcomeRoute);\n } else {\n app.get(\"/api\", (_, res) => {\n res.status(200).json({ message: arkosConfig.welcomeMessage });\n });\n }\n }\n\n if (initConfig?.use)\n for (const mwOrRouter of initConfig.use) {\n app.use(mwOrRouter as IRouter);\n }\n\n const fileUploadRouter = getFileUploadRouter(arkosConfig);\n knowModulesRouter.use(fileUploadRouter);\n\n if (isAuthenticationEnabled()) {\n const authRouter = getAuthRouter(arkosConfig);\n knowModulesRouter.use(\"/api\", authRouter);\n }\n\n const modelsRouter = getPrismaModelsRouter(arkosConfig);\n knowModulesRouter.use(\"/api\", modelsRouter as any);\n\n app.use(knowModulesRouter);\n app.use(\"/api\", getAvailableResourcesAndRoutesRouter());\n\n if (\n arkosConfig.swagger &&\n (process.env.ARKOS_BUILD !== \"true\" ||\n arkosConfig.swagger.enableAfterBuild === true)\n )\n app.use(\"/api\", await getSwaggerRouter(arkosConfig, app));\n\n app.use(\"*\", (req) => {\n throw new AppError(\n \"Route not found\",\n 404,\n { route: req.path },\n \"RouteNotFound\"\n );\n });\n\n if (middlewaresConfig?.errorHandler !== false) {\n if (typeof middlewaresConfig?.errorHandler === \"function\") {\n app.use(middlewaresConfig.errorHandler);\n } else {\n app.use(errorHandler);\n }\n }\n\n return app;\n}\n"]}
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,8BA+LC;AAzND,mDAAmD;AACnD,gDAAwB;AACxB,kEAAyC;AACzC,4DAA2D;AAC3D,4DAGoC;AACpC,gHAA4E;AAC5E,2DAA+C;AAC/C,8DAAsC;AACtC,sEAAoE;AACpE,mEAAkE;AAClE,iFAA+E;AAC/E,+EAAmE;AACnE,wFAAyD;AACzD,qEAAoE;AACpE,2DAAiE;AACjE,2DAAmD;AACnD,2FAAkE;AAClE,uCAA2C;AAE3C,+EAA+E;AAClE,QAAA,GAAG,GAAoB,IAAA,iBAAO,GAAE,CAAC;AAC9C,MAAM,iBAAiB,GAAG,IAAA,gBAAM,GAAE,CAAC;AAE5B,KAAK,UAAU,SAAS,CAC7B,UAA2B;IAE3B,MAAM,WAAW,GAAG,IAAA,wBAAc,GAAE,CAAC;IAErC,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,IAAA,iCAAgB,GAAE;QAClB,IAAA,wCAAuB,EAAC,WAAW,CAAC;QACpC,UAAU,EAAE,YAAY,IAAI,CAAC,MAAM,UAAU,EAAE,YAAY,CAAC,WAAG,CAAC,CAAC;KAClE,CAAC,CAAC;IAEH,MAAM,iBAAiB,GAAG,WAAW,EAAE,WAAW,CAAC;IAEnD,IAAI,iBAAiB,EAAE,WAAW,KAAK,KAAK,EAAE,CAAC;QAC7C,IAAI,OAAO,iBAAiB,EAAE,WAAW,KAAK,UAAU,EAAE,CAAC;YACzD,WAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,WAAW,CA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I,CAAC;QAEhD,WAAG,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,IAAA,iCAAgB,EAAC,WAAW,EAAE,WAAG,CAAC,CAAC,CAAC;IAE5D,WAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE;QACnB,MAAM,IAAI,wBAAQ,CAChB,iBAAiB,EACjB,GAAG,EACH,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,EACnB,eAAe,CAChB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAI,iBAAiB,EAAE,YAAY,KAAK,KAAK,EAAE,CAAC;QAC9C,IAAI,OAAO,iBAAiB,EAAE,YAAY,KAAK,UAAU,EAAE,CAAC;YAC1D,WAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,WAAG,CAAC,GAAG,CAAC,kCAAY,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO,WAAG,CAAC;AACb,CAAC","sourcesContent":["import express, { IRouter, Router } from \"express\";\nimport cors from \"cors\";\nimport cookieParser from \"cookie-parser\";\nimport { getAuthRouter } from \"./modules/auth/auth.router\";\nimport {\n getPrismaModelsRouter,\n getAvailableResourcesAndRoutesRouter,\n} from \"./modules/base/base.router\";\nimport errorHandler from \"./modules/error-handler/error-handler.controller\";\nimport { rateLimit } from \"express-rate-limit\";\nimport compression from \"compression\";\nimport { handleRequestLogs } from \"./modules/base/base.middlewares\";\nimport { loadPrismaModule } from \"./utils/helpers/prisma.helpers\";\nimport { getFileUploadRouter } from \"./modules/file-upload/file-upload.router\";\nimport { queryParser } from \"./utils/helpers/query-parser.helpers\";\nimport deepmerge from \"./utils/helpers/deepmerge.helper\";\nimport { getSwaggerRouter } from \"./modules/swagger/swagger.router\";\nimport { loadAllModuleComponents } from \"./utils/dynamic-loader\";\nimport { AppError } from \"./exports/error-handler\";\nimport debuggerService from \"./modules/debugger/debugger.service\";\nimport { getArkosConfig } from \"./exports\";\nimport { ArkosInitConfig } from \"./types/arkos-config\";\nimport { isAuthenticationEnabled } from \"./utils/helpers/arkos-config.helpers\";\nexport const app: express.Express = express();\nconst knowModulesRouter = Router();\n\nexport async function bootstrap(\n initConfig: ArkosInitConfig\n): Promise<express.Express> {\n const arkosConfig = getArkosConfig();\n\n await Promise.all([\n loadPrismaModule(),\n loadAllModuleComponents(arkosConfig),\n initConfig?.configureApp && (await initConfig?.configureApp(app)),\n ]);\n\n const middlewaresConfig = arkosConfig?.middlewares;\n\n if (middlewaresConfig?.compression !== false) {\n if (typeof middlewaresConfig?.compression === \"function\") {\n app.use(middlewaresConfig.compression);\n } else {\n app.use(compression(middlewaresConfig?.compression || {}));\n }\n }\n\n if (middlewaresConfig?.rateLimit !== false) {\n if (typeof middlewaresConfig?.rateLimit === \"function\") {\n app.use(middlewaresConfig.rateLimit);\n } else {\n app.use(\n rateLimit(\n deepmerge(\n {\n windowMs: 60 * 1000,\n limit: 300,\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 middlewaresConfig?.rateLimit || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.cors !== false) {\n if (typeof middlewaresConfig?.cors === \"function\") {\n app.use(middlewaresConfig.cors);\n } else {\n app.use(\n cors(\n middlewaresConfig?.cors?.customHandler\n ? middlewaresConfig.cors.customHandler\n : deepmerge(\n {\n origin: (\n origin: string,\n cb: (err: Error | null, allow?: boolean) => void\n ) => {\n const allowed = (middlewaresConfig?.cors as any)\n ?.allowedOrigins;\n\n if (allowed === \"*\") cb(null, true);\n else if (Array.isArray(allowed))\n cb(null, !origin || allowed?.includes?.(origin));\n else if (typeof allowed === \"string\")\n cb(null, !origin || allowed === origin);\n else cb(null, false);\n },\n\n methods: [\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\"],\n allowedHeaders: [\n \"Content-Type\",\n \"Authorization\",\n \"Connection\",\n ],\n credentials: true,\n },\n middlewaresConfig?.cors?.options || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.expressJson !== false) {\n if (typeof middlewaresConfig?.expressJson === \"function\") {\n app.use(middlewaresConfig.expressJson);\n } else {\n app.use(express.json(middlewaresConfig?.expressJson || {}));\n }\n }\n\n if (middlewaresConfig?.cookieParser !== false) {\n if (typeof middlewaresConfig?.cookieParser === \"function\") {\n app.use(middlewaresConfig.cookieParser);\n } else {\n const params = Array.isArray(middlewaresConfig?.cookieParser)\n ? middlewaresConfig.cookieParser\n : [];\n app.use(cookieParser(...(params as any))); // FIXME: check types correctly\n }\n }\n\n if (middlewaresConfig?.queryParser !== false) {\n if (typeof middlewaresConfig?.queryParser === \"function\") {\n app.use(middlewaresConfig.queryParser);\n } else {\n app.use(\n queryParser(\n deepmerge(\n {\n parseNull: true,\n parseUndefined: true,\n parseBoolean: true,\n parseNumber: true,\n },\n middlewaresConfig?.queryParser || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.requestLogger !== false) {\n if (typeof middlewaresConfig?.requestLogger === \"function\") {\n app.use(middlewaresConfig.requestLogger);\n } else {\n app.use(handleRequestLogs);\n }\n }\n\n app.use(debuggerService.logRequestInfo);\n\n const routersConfig = arkosConfig?.routers;\n\n if (routersConfig?.welcomeRoute !== false) {\n if (typeof routersConfig?.welcomeRoute === \"function\") {\n app.get(\"/api\", routersConfig.welcomeRoute);\n } else {\n app.get(\"/api\", (_, res) => {\n res.status(200).json({ message: arkosConfig.welcomeMessage });\n });\n }\n }\n\n if (initConfig?.use)\n for (const mwOrRouter of initConfig.use) {\n app.use(mwOrRouter as IRouter);\n }\n\n const fileUploadRouter = getFileUploadRouter(arkosConfig);\n knowModulesRouter.use(fileUploadRouter);\n\n if (isAuthenticationEnabled()) {\n const authRouter = getAuthRouter(arkosConfig) as any;\n knowModulesRouter.use(\"/api\", authRouter);\n }\n\n const modelsRouter = getPrismaModelsRouter(arkosConfig);\n knowModulesRouter.use(\"/api\", modelsRouter as any);\n\n app.use(knowModulesRouter);\n app.use(\"/api\", getAvailableResourcesAndRoutesRouter());\n\n if (\n arkosConfig.swagger &&\n (process.env.ARKOS_BUILD !== \"true\" ||\n arkosConfig.swagger.enableAfterBuild === true)\n )\n app.use(\"/api\", await getSwaggerRouter(arkosConfig, app));\n\n app.use(\"*\", (req) => {\n throw new AppError(\n \"Route not found\",\n 404,\n { route: req.path },\n \"RouteNotFound\"\n );\n });\n\n if (middlewaresConfig?.errorHandler !== false) {\n if (typeof middlewaresConfig?.errorHandler === \"function\") {\n app.use(middlewaresConfig.errorHandler);\n } else {\n app.use(errorHandler);\n }\n }\n\n return app;\n}\n"]}
@@ -4,9 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getAuthRouter = getAuthRouter;
7
- const express_1 = require("express");
8
7
  const auth_controller_1 = require("./auth.controller");
9
- const auth_service_1 = __importDefault(require("./auth.service"));
10
8
  const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
11
9
  const dynamic_loader_1 = require("../../utils/dynamic-loader");
12
10
  const base_middlewares_1 = require("../base/base.middlewares");
@@ -16,9 +14,10 @@ const base_router_helpers_1 = require("../base/utils/helpers/base.router.helpers
16
14
  const debugger_service_1 = __importDefault(require("../debugger/debugger.service"));
17
15
  const router_validator_1 = __importDefault(require("../base/utils/router-validator"));
18
16
  const fs_helpers_1 = require("../../utils/helpers/fs.helpers");
19
- const router = (0, express_1.Router)();
17
+ const arkos_router_1 = __importDefault(require("../../utils/arkos-router"));
18
+ const router = (0, arkos_router_1.default)();
20
19
  function getAuthRouter(arkosConfigs) {
21
- const { interceptors, dtos, schemas, prismaQueryOptions, router: customRouterModule, } = (0, dynamic_loader_1.getModuleComponents)("auth") || {};
20
+ const { interceptors, dtos, schemas, prismaQueryOptions, router: customRouterModule, authConfigs, } = (0, dynamic_loader_1.getModuleComponents)("auth") || {};
22
21
  const routerConfig = customRouterModule?.config || {};
23
22
  const customRouter = customRouterModule?.default;
24
23
  if (customRouter && customRouterModule) {
@@ -32,22 +31,20 @@ function getAuthRouter(arkosConfigs) {
32
31
  return router;
33
32
  const getValidationSchemaOrDto = (key) => {
34
33
  const validationConfigs = arkosConfigs?.validation;
35
- if (validationConfigs?.resolver === "class-validator") {
34
+ if (validationConfigs?.resolver === "class-validator")
36
35
  return dtos?.[key];
37
- }
38
- else if (validationConfigs?.resolver === "zod") {
36
+ else if (validationConfigs?.resolver === "zod")
39
37
  return schemas?.[key];
40
- }
41
38
  return undefined;
42
39
  };
43
40
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "getMe")) {
44
- router.get("/users/me", auth_service_1.default.authenticate, (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)("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" }));
45
42
  }
46
43
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "updateMe")) {
47
- router.patch("/users/me", auth_service_1.default.authenticate, (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("updateMe")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateMe"), ...(0, routers_helpers_1.processMiddleware)(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)("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" }));
48
45
  }
49
46
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "deleteMe")) {
50
- router.delete("/users/me", auth_service_1.default.authenticate, (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)("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" }));
51
48
  }
52
49
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "login") ||
53
50
  !(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "logout") ||
@@ -66,27 +63,29 @@ function getAuthRouter(arkosConfigs) {
66
63
  }, arkosConfigs?.authentication?.requestRateLimitOptions || {})));
67
64
  }
68
65
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "login")) {
69
- router.post("/auth/login", (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(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)("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" }));
70
67
  }
71
68
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "logout")) {
72
- router.delete("/auth/logout", auth_service_1.default.authenticate, ...(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)("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" }));
73
70
  }
74
71
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "signup")) {
75
- router.post("/auth/signup", (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(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)("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" }));
76
73
  }
77
74
  if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "updatePassword")) {
78
- router.post("/auth/update-password", auth_service_1.default.authenticate, (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("updatePassword")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updatePassword"), ...(0, routers_helpers_1.processMiddleware)(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)("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, {
79
76
  type: "error",
80
77
  }));
81
78
  }
82
- if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "findManyAuthAction"))
83
- router.get("/auth-actions", auth_service_1.default.authenticate, auth_service_1.default.handleAccessControl("View", "auth-action"), ...(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, {
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, {
84
81
  type: "error",
85
82
  }));
86
- if (!(0, base_router_helpers_1.isEndpointDisabled)(routerConfig, "findOneAuthAction"))
87
- router.get("/auth-actions/:resourceName", auth_service_1.default.authenticate, auth_service_1.default.handleAccessControl("View", "auth-action"), ...(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, {
83
+ }
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, {
88
86
  type: "error",
89
87
  }));
88
+ }
90
89
  debugger_service_1.default.logModuleFinalRouter("auth", router);
91
90
  return router;
92
91
  }
@@ -1 +1 @@
1
- {"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":";;;;;AAqBA,sCAsNC;AA3OD,qCAAiC;AACjC,uDAA0D;AAC1D,kEAAyC;AACzC,4EAA2C;AAC3C,+DAAiE;AACjE,+DAIkC;AAElC,4FAA6D;AAE7D,yEAAwE;AACxE,mFAA+E;AAC/E,oFAA2D;AAC3D,sFAA6D;AAC7D,+DAAsE;AAEtE,MAAM,MAAM,GAAW,IAAA,gBAAM,GAAE,CAAC;AAEhC,SAAgB,aAAa,CAAC,YAAyB;IACrD,MAAM,EACJ,YAAY,EACZ,IAAI,EACJ,OAAO,EACP,kBAAkB,EAClB,MAAM,EAAE,kBAAkB,GAC3B,GAAG,IAAA,oCAAmB,EAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAEtC,MAAM,YAAY,GAAG,kBAAkB,EAAE,MAAM,IAAI,EAAE,CAAC;IACtD,MAAM,YAAY,GAAG,kBAAkB,EAAE,OAAiB,CAAC;IAE3D,IAAI,YAAY,IAAI,kBAAkB,EAAE,CAAC;QACvC,IAAI,0BAAe,CAAC,eAAe,CAAC,YAAY,CAAC;YAC/C,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;;YAElC,MAAM,KAAK,CACT,yDAAyD,IAAA,iCAAoB,GAAE,0CAA0C,CAC1H,CAAC;IACN,CAAC;IAED,MAAM,cAAc,GAAG,IAAA,uCAAqB,EAAC,YAAY,CAAC,CAAC;IAE3D,IAAI,YAAY,EAAE,OAAO,KAAK,IAAI;QAAE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D,MAAM,CAAC,GAAG,CACR,6BAA6B,EAC7B,sBAAW,CAAC,YAAY,EACxB,sBAAW,CAAC,mBAAmB,CAAC,MAAM,EAAE,aAAa,CAAC,EACtD,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;IAEJ,0BAAe,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { authControllerFactory } from \"./auth.controller\";\nimport authService from \"./auth.service\";\nimport rateLimit from \"express-rate-limit\";\nimport { getModuleComponents } from \"../../utils/dynamic-loader\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\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 { processMiddleware } 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\";\n\nconst router: Router = Router();\n\nexport function getAuthRouter(arkosConfigs: ArkosConfig) {\n const {\n interceptors,\n dtos,\n schemas,\n prismaQueryOptions,\n router: customRouterModule,\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\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n if (!isEndpointDisabled(routerConfig, \"getMe\")) {\n router.get(\n \"/users/me\",\n authService.authenticate,\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 if (!isEndpointDisabled(routerConfig, \"updateMe\")) {\n router.patch(\n \"/users/me\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMe\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...processMiddleware(interceptors?.beforeUpdateMe),\n authController.updateMe,\n ...processMiddleware(interceptors?.afterUpdateMe),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdateMeError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"deleteMe\")) {\n router.delete(\n \"/users/me\",\n authService.authenticate,\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 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?.requestRateLimitOptions || {}\n )\n )\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"login\")) {\n router.post(\n \"/auth/login\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"login\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...processMiddleware(interceptors?.beforeLogin),\n authController.login,\n ...processMiddleware(interceptors?.afterLogin),\n sendResponse,\n ...processMiddleware(interceptors?.onLoginError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"logout\")) {\n router.delete(\n \"/auth/logout\",\n authService.authenticate,\n ...processMiddleware(interceptors?.beforeLogout),\n authController.logout,\n ...processMiddleware(interceptors?.afterLogout),\n sendResponse,\n ...processMiddleware(interceptors?.onLogoutError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"signup\")) {\n router.post(\n \"/auth/signup\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"signup\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...processMiddleware(interceptors?.beforeSignup),\n authController.signup,\n ...processMiddleware(interceptors?.afterSignup),\n sendResponse,\n ...processMiddleware(interceptors?.onSignupError, { type: \"error\" })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"updatePassword\")) {\n router.post(\n \"/auth/update-password\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updatePassword\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...processMiddleware(interceptors?.beforeUpdatePassword),\n authController.updatePassword,\n ...processMiddleware(interceptors?.afterUpdatePassword),\n sendResponse,\n ...processMiddleware(interceptors?.onUpdatePasswordError, {\n type: \"error\",\n })\n );\n }\n\n if (!isEndpointDisabled(routerConfig, \"findManyAuthAction\"))\n router.get(\n \"/auth-actions\",\n authService.authenticate,\n authService.handleAccessControl(\"View\", \"auth-action\"),\n ...processMiddleware(interceptors?.beforeFindManyAuthAction),\n authController.findManyAuthAction,\n ...processMiddleware(interceptors?.afterFindManyAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindManyAuthActionError, {\n type: \"error\",\n })\n );\n\n if (!isEndpointDisabled(routerConfig, \"findOneAuthAction\"))\n router.get(\n \"/auth-actions/:resourceName\",\n authService.authenticate,\n authService.handleAccessControl(\"View\", \"auth-action\"),\n ...processMiddleware(interceptors?.beforeFindOneAuthAction),\n authController.findOneAuthAction,\n ...processMiddleware(interceptors?.afterFindOneAuthAction),\n sendResponse,\n ...processMiddleware(interceptors?.onFindOneAuthActionError, {\n type: \"error\",\n })\n );\n\n debuggerService.logModuleFinalRouter(\"auth\", router);\n return router;\n}\n"]}
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;IAC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AAsB,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(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?.requestRateLimitOptions || {}\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"]}
@@ -16,7 +16,6 @@ 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
- const deepmerge_helper_1 = __importDefault(require("../../../../utils/helpers/deepmerge.helper"));
20
19
  function setupRouters(router, arkosConfigs) {
21
20
  return prisma_schema_parser_1.default.getModelsAsArrayOfStrings().map(async (model) => {
22
21
  const modelNameInKebab = (0, utils_1.kebabCase)(model);
@@ -49,75 +48,33 @@ function setupRouters(router, arkosConfigs) {
49
48
  else
50
49
  throw Error(`ValidationError: The exported router from ${modelNameInKebab}.router.${(0, fs_helpers_1.getUserFileExtension)()} is not a valid express Router.`);
51
50
  }
52
- const createRouteConfig = (endpoint, path, validationSchema) => {
53
- const config = {
54
- route: `/${routeName}${path}`,
55
- disabled: isEndpointDisabled(routerConfig, endpoint),
56
- authentication: getAuthenticationConfig(endpoint, modelNameInKebab, authConfigs),
57
- validation: validationSchema ? { body: validationSchema } : undefined,
58
- experimental: { openapi: false },
59
- };
60
- const endpointConfig = routerConfig[endpoint];
61
- if (endpointConfig)
62
- (0, deepmerge_helper_1.default)(config, endpointConfig);
63
- return config;
64
- };
65
51
  if (!hasCustomImplementation(`/${routeName}`, "post")) {
66
- router.post(createRouteConfig("createOne", "", 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)("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" }));
67
53
  }
68
54
  if (!hasCustomImplementation(`/${routeName}`, "get")) {
69
- router.get(createRouteConfig("findMany", ""), (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)("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" }));
70
56
  }
71
57
  if (!hasCustomImplementation(`/${routeName}/many`, "post")) {
72
- router.post(createRouteConfig("createMany", "/many", getValidationSchemaOrDto("create")), (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)("createMany", routeName, "/many", routerConfig, modelNameInKebab, authConfigs, getValidationSchemaOrDto("create")), (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" }));
73
59
  }
74
60
  if (!hasCustomImplementation(`/${routeName}/many`, "patch")) {
75
- router.patch(createRouteConfig("updateMany", "/many"), (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)("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" }));
76
62
  }
77
63
  if (!hasCustomImplementation(`/${routeName}/many`, "delete")) {
78
- router.delete(createRouteConfig("deleteMany", "/many"), (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)("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" }));
79
65
  }
80
66
  if (!hasCustomImplementation(`/${routeName}/:id`, "get")) {
81
- router.get(createRouteConfig("findOne", "/:id"), (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)("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" }));
82
68
  }
83
69
  if (!hasCustomImplementation(`/${routeName}/:id`, "patch")) {
84
- router.patch(createRouteConfig("updateOne", "/:id", 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)("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" }));
85
71
  }
86
72
  if (!hasCustomImplementation(`/${routeName}/:id`, "delete")) {
87
- router.delete(createRouteConfig("deleteOne", "/:id"), (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)("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" }));
88
74
  }
89
75
  debugger_service_1.default.logModuleFinalRouter(modelNameInKebab, router);
90
76
  });
91
77
  }
92
- function getAuthenticationConfig(endpoint, modelName, authConfigs) {
93
- const actionMap = {
94
- createOne: "Create",
95
- findMany: "View",
96
- createMany: "Create",
97
- updateMany: "Update",
98
- deleteMany: "Delete",
99
- findOne: "View",
100
- updateOne: "Update",
101
- deleteOne: "Delete",
102
- };
103
- const action = actionMap[endpoint];
104
- const authenticationControl = authConfigs?.authenticationControl;
105
- if ((authenticationControl &&
106
- typeof authenticationControl === "object" &&
107
- (authenticationControl[action] === true ||
108
- authenticationControl[action] !== false)) ||
109
- authenticationControl === true ||
110
- (!authenticationControl && authenticationControl !== false)) {
111
- return {
112
- resource: (0, utils_1.kebabCase)(pluralize_1.default.singular(modelName)),
113
- action: action,
114
- rule: Array.isArray(authConfigs?.accessControl)
115
- ? authConfigs?.accessControl
116
- : (authConfigs?.accessControl || {})[action] || [],
117
- };
118
- }
119
- return false;
120
- }
121
78
  function isEndpointDisabled(routerConfig, endpoint) {
122
79
  if (!routerConfig?.disable)
123
80
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"base.router.helpers.js","sourceRoot":"","sources":["../../../../../../src/modules/base/utils/helpers/base.router.helpers.ts"],"names":[],"mappings":";;;;;AAyBA,oCAmNC;AAyCD,gDAYC;AAED,0DAWC;AA7SD,0DAAkC;AAElC,qDAAsD;AAOtD,qEAAuE;AACvE,2DAAuD;AACvD,6DAGgC;AAChC,+EAA8E;AAC9E,2EAAkD;AAClD,qEAA4E;AAC5E,yGAA+E;AAC/E,0FAAiE;AAGjE,kGAAmE;AAEnE,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,EAAE,MAAc,EAAE,EAAE;YAC/D,OAAO,Y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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 { processMiddleware } 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 { AccessAction, AuthConfigs } from \"../../../../types/auth\";\nimport { IArkosRouter } from \"../../../../utils/arkos-router/types\";\nimport deepmerge from \"../../../../utils/helpers/deepmerge.helper\";\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 = (key: \"create\" | \"update\") => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n if (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 const createRouteConfig = (\n endpoint: RouterEndpoint,\n path: string,\n validationSchema?: any\n ) => {\n const config: any = {\n route: `/${routeName}${path}`,\n disabled: isEndpointDisabled(routerConfig, endpoint),\n authentication: getAuthenticationConfig(\n endpoint,\n modelNameInKebab,\n authConfigs\n ),\n validation: validationSchema ? { body: validationSchema } : undefined,\n experimental: { openapi: false },\n };\n\n const endpointConfig = (routerConfig as any)[endpoint];\n if (endpointConfig) deepmerge(config, endpointConfig);\n\n return config;\n };\n\n // CREATE ONE\n if (!hasCustomImplementation(`/${routeName}`, \"post\")) {\n router.post(\n createRouteConfig(\"createOne\", \"\", getValidationSchemaOrDto(\"create\")),\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(\"findMany\", \"\"),\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 \"/many\",\n getValidationSchemaOrDto(\"create\")\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(\"updateMany\", \"/many\"),\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(\"deleteMany\", \"/many\"),\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(\"findOne\", \"/:id\"),\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 \"/:id\",\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(\"deleteOne\", \"/:id\"),\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\nfunction getAuthenticationConfig(\n endpoint: RouterEndpoint,\n modelName: string,\n authConfigs?: AuthConfigs\n) {\n const actionMap: Record<RouterEndpoint, AccessAction> = {\n createOne: \"Create\",\n findMany: \"View\",\n createMany: \"Create\",\n updateMany: \"Update\",\n deleteMany: \"Delete\",\n findOne: \"View\",\n updateOne: \"Update\",\n deleteOne: \"Delete\",\n };\n\n const action = actionMap[endpoint];\n const authenticationControl = authConfigs?.authenticationControl;\n\n if (\n (authenticationControl &&\n typeof authenticationControl === \"object\" &&\n (authenticationControl[action] === true ||\n authenticationControl[action] !== false)) ||\n authenticationControl === true ||\n (!authenticationControl && authenticationControl !== false)\n ) {\n return {\n resource: kebabCase(pluralize.singular(modelName)),\n action: action,\n rule: Array.isArray(authConfigs?.accessControl)\n ? authConfigs?.accessControl\n : (authConfigs?.accessControl || {})[action] || [],\n };\n }\n\n return false;\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,oCA+OC;AAED,gDAYC;AAED,0DAWC;AAnSD,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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,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, 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 = (key: \"create\" | \"update\") => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n if (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(\"create\")\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"]}
@@ -40,13 +40,15 @@ function ArkosRouter() {
40
40
  throw Error(`First argument of ArkosRouter().${prop}() must be a valid ArkosRouteConfig but recevied ${config}`);
41
41
  const method = prop;
42
42
  if (handlers.length > 0) {
43
- handlers = handlers.map((handler) => typeof handler === "function"
44
- ? (0, error_handler_1.catchAsync)(handler, {
45
- type: handler.length > 3 ? "error" : "normal",
46
- })
47
- : handler.map((nesteHandler) => (0, error_handler_1.catchAsync)(nesteHandler, {
48
- type: handler.length > 3 ? "error" : "normal",
49
- })));
43
+ handlers = handlers.map((handler) => {
44
+ return typeof handler === "function"
45
+ ? (0, error_handler_1.catchAsync)(handler, {
46
+ type: handler.length > 3 ? "error" : "normal",
47
+ })
48
+ : handler.map((nesteHandler) => (0, error_handler_1.catchAsync)(nesteHandler, {
49
+ type: handler.length > 3 ? "error" : "normal",
50
+ }));
51
+ });
50
52
  const finalHandler = handlers[handlers.length - 1];
51
53
  route_config_registry_1.default.register(finalHandler, config, method);
52
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/arkos-router/index.ts"],"names":[],"mappings":";;;;;AAsCA,8BAuGC;AAED,wDAkFC;AAjOD,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;aACV,CAAC;YAMF,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAc,CAAC,EAAE,CAAC;gBACzC,OAAO,UACL,MAAwB,EACxB,GAAG,QAAkC;oBAErC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,CAAC;oBACrC,MAAM,UAAU,GAAG,qBAAqB,CAAC,GAAU,CAAC,CAAC;oBACrD,MAAM,MAAM,GAAG,kCAAsB,CAAC,4BAA4B,CAC/D,4BAAoC,CAAC,GAAG,CAAC,EAC1C,UAAU,CACX,CAAC;oBACF,UAAU,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;gBAC7B,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,gBAAgB,GACpB,kCAAsB,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEtD,KAAa,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG;YAC3C,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,GAAG,MAAM,IAAI,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 * route: \"/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.route;\n\n if (!RouteConfigValidator.isArkosRouteConfig(config))\n throw Error(\n `First argument of ArkosRouter().${prop as string}() must be a valid ArkosRouteConfig but recevied ${config}`\n );\n\n const method = prop as string;\n\n if (handlers.length > 0) {\n handlers = handlers.map(\n (handler: ArkosAnyRequestHandler | ArkosAnyRequestHandler[]) =>\n 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 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,8BAwGC;AAED,wDAkFC;AAlOD,qCAAiC;AAGjC,sFAA4D;AAC5D,oFAA0D;AAC1D,6CAAyE;AACzE,2CAA+C;AAC/C,+DAAyD;AAEzD,4EAAiD;AACjD,wIAA4G;AAC5G,4HAAkG;AAClG,oFAA2D;AA0B3D,SAAwB,WAAW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C,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 * route: \"/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.route;\n\n if (!RouteConfigValidator.isArkosRouteConfig(config))\n throw Error(\n `First argument of ArkosRouter().${prop as string}() must be a valid ArkosRouteConfig but recevied ${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"]}
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.extractArkosRoutes = extractArkosRoutes;
7
7
  exports.getMiddlewareStack = getMiddlewareStack;
8
8
  const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
9
- const services_1 = require("../../../../exports/services");
9
+ const auth_service_1 = __importDefault(require("../../../../modules/auth/auth.service"));
10
10
  const base_middlewares_1 = require("../../../../modules/base/base.middlewares");
11
11
  const route_config_registry_1 = __importDefault(require("../../route-config-registry"));
12
12
  const express_1 = __importDefault(require("express"));
@@ -62,11 +62,11 @@ function extractArkosRoutes(app, basePath = "") {
62
62
  function getMiddlewareStack(config) {
63
63
  const middlewares = [];
64
64
  if (config.authentication)
65
- middlewares.push(services_1.authService.authenticate);
65
+ middlewares.push(auth_service_1.default.authenticate);
66
66
  if (typeof config.authentication === "object" &&
67
67
  config.authentication.action &&
68
68
  config.authentication.resource)
69
- middlewares.push(services_1.authService.handleAccessControl(config.authentication.action, config.authentication.resource, { [config.authentication.action]: config.authentication?.rule }));
69
+ middlewares.push(auth_service_1.default.handleAccessControl(config.authentication.action, config.authentication.resource, { [config.authentication.action]: config.authentication?.rule }));
70
70
  if (config.rateLimit)
71
71
  middlewares.push((0, express_rate_limit_1.default)(config.rateLimit));
72
72
  if (config.compression)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/utils/arkos-router/utils/helpers/index.ts"],"names":[],"mappings":";;;;;AAUA,gDA+DC;AAED,gDAyCC;AApHD,4EAA2C;AAC3C,2DAA2D;AAC3D,gFAAkF;AAClF,wF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AAM,CAAC,SAAS;QAAE,WAAW,CAAC,IAAI,CAAC,IAAA,4BAAS,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IACpE,IAAI,MAAM,CAAC,WAAW;QAAE,WAAW,CAAC,IAAI,CAAC,IAAA,qBAAW,EAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IAC1E,IAAI,MAAM,CAAC,WAAW;QAAE,WAAW,CAAC,IAAI,CAAC,IAAA,kCAAW,EAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IAE1E,IACE,OAAO,MAAM,EAAE,UAAU,KAAK,QAAQ;QACtC,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC;QAE1E,WAAW,CAAC,IAAI,CACd,iBAAO,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAC7D,CAAC;IAEJ,IAAI,MAAM,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC;QACjC,WAAW,CAAC,IAAI,CAAC,wBAAa,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;QAE1E,WAAW,CAAC,IAAI,CAAC,IAAA,wCAAqB,EAAC,MAAM,CAAC,CAAC,CAAC;QAEhD,WAAW,CAAC,IAAI,CACd,wBAAa,CAAC,gBAAgB,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAC5D,CAAC;IACJ,CAAC;;QAAM,WAAW,CAAC,IAAI,CAAC,IAAA,wCAAqB,EAAC,MAAM,CAAC,CAAC,CAAC;IAEvD,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import rateLimit from \"express-rate-limit\";\nimport { authService } from \"../../../../exports/services\";\nimport { validateRequestInputs } from \"../../../../modules/base/base.middlewares\";\nimport RouteConfigRegistry from \"../../route-config-registry\";\nimport { ArkosRouteConfig } from \"../../types\";\nimport express from \"express\";\nimport compression from \"compression\";\nimport { queryParser } from \"../../../helpers/query-parser.helpers\";\nimport uploadManager from \"./upload-manager\";\n\nexport function extractArkosRoutes(\n app: any,\n basePath = \"\"\n): Array<{\n path: string;\n method: string;\n config?: ArkosRouteConfig;\n}> {\n const routes: Array<{\n path: string;\n method: string;\n config?: ArkosRouteConfig;\n }> = [];\n\n function extractFromStack(stack: any[], prefix = \"\") {\n stack.forEach((layer: any) => {\n if (layer.route) {\n const fullPath = prefix + layer.route.path;\n const methods = Object.keys(layer.route.methods);\n\n methods.forEach((method) => {\n const handlers = layer.route.stack || [];\n let config: ArkosRouteConfig | undefined;\n\n for (const handler of handlers) {\n const foundConfig = RouteConfigRegistry.get(handler.handle);\n\n if (foundConfig) {\n config = foundConfig;\n routes.push({\n path: fullPath,\n method: method.toUpperCase(),\n config,\n });\n\n break;\n }\n }\n });\n } else if (layer.name === \"router\" && layer.handle?.stack) {\n let nestedPrefix = prefix;\n\n if (layer.regexp) {\n const match = layer.regexp\n .toString()\n .match(/\\/\\^?(\\\\\\/[^?]+|\\/[^?]+)/);\n if (match) {\n nestedPrefix = prefix + \"/\" + match[1].replace(/\\\\\\//g, \"/\");\n nestedPrefix = nestedPrefix\n .replace(/\\/\\//g, \"/\")\n .replace(/\\/$/, \"\");\n }\n }\n\n extractFromStack(layer.handle.stack, nestedPrefix);\n }\n });\n }\n\n const stack = app._router?.stack || app.stack;\n if (stack) extractFromStack(stack, basePath);\n\n return routes;\n}\n\nexport function getMiddlewareStack(config: ArkosRouteConfig) {\n const middlewares = [];\n\n if (config.authentication) middlewares.push(authService.authenticate);\n\n if (\n typeof config.authentication === \"object\" &&\n config.authentication.action &&\n config.authentication.resource\n )\n middlewares.push(\n authService.handleAccessControl(\n config.authentication.action,\n config.authentication.resource,\n { [config.authentication.action]: config.authentication?.rule }\n )\n );\n\n if (config.rateLimit) middlewares.push(rateLimit(config.rateLimit));\n if (config.compression) middlewares.push(compression(config.compression));\n if (config.queryParser) middlewares.push(queryParser(config.queryParser));\n\n if (\n typeof config?.bodyParser === \"object\" &&\n [\"json\", \"urlencoded\", \"raw\", \"text\"].includes(config?.bodyParser?.parser)\n )\n middlewares.push(\n express[config.bodyParser.parser](config.bodyParser.options)\n );\n\n if (config.experimental?.uploads) {\n middlewares.push(uploadManager.handleUpload(config.experimental.uploads));\n\n middlewares.push(validateRequestInputs(config));\n\n middlewares.push(\n uploadManager.handlePostUpload(config.experimental.uploads)\n );\n } else middlewares.push(validateRequestInputs(config));\n\n return middlewares;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/utils/arkos-router/utils/helpers/index.ts"],"names":[],"mappings":";;;;;AAUA,gDA+DC;AAED,gDAyCC;AApHD,4EAA2C;AAC3C,yFAAgE;AAChE,gFAAkF;AAClF,wFAA8D;AAE9D,sDAA8B;AAC9B,8DAAsC;AACtC,gFAAoE;AACpE,sEAA6C;AAE7C,SAAgB,kBAAkB,CAChC,GAAQ,EACR,QAAQ,GAAG,EAAE;IAMb,MAAM,MAAM,GAIP,EAAE,CAAC;IAER,SAAS,gBAAgB,CAAC,KAAY,EAAE,MAAM,GAAG,EAAE;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE;YAC3B,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;gBAChB,MAAM,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;gBAC3C,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAEjD,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;oBACzB,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;oBACzC,IAAI,MAAoC,CAAC;oBAEzC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;w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C,WAAW,CAAC,IAAI,CAAC,wBAAa,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;QAE1E,WAAW,CAAC,IAAI,CAAC,IAAA,wCAAqB,EAAC,MAAM,CAAC,CAAC,CAAC;QAEhD,WAAW,CAAC,IAAI,CACd,wBAAa,CAAC,gBAAgB,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAC5D,CAAC;IACJ,CAAC;;QAAM,WAAW,CAAC,IAAI,CAAC,IAAA,wCAAqB,EAAC,MAAM,CAAC,CAAC,CAAC;IAEvD,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import rateLimit from \"express-rate-limit\";\nimport authService from \"../../../../modules/auth/auth.service\";\nimport { validateRequestInputs } from \"../../../../modules/base/base.middlewares\";\nimport RouteConfigRegistry from \"../../route-config-registry\";\nimport { ArkosRouteConfig } from \"../../types\";\nimport express from \"express\";\nimport compression from \"compression\";\nimport { queryParser } from \"../../../helpers/query-parser.helpers\";\nimport uploadManager from \"./upload-manager\";\n\nexport function extractArkosRoutes(\n app: any,\n basePath = \"\"\n): Array<{\n path: string;\n method: string;\n config?: ArkosRouteConfig;\n}> {\n const routes: Array<{\n path: string;\n method: string;\n config?: ArkosRouteConfig;\n }> = [];\n\n function extractFromStack(stack: any[], prefix = \"\") {\n stack.forEach((layer: any) => {\n if (layer.route) {\n const fullPath = prefix + layer.route.path;\n const methods = Object.keys(layer.route.methods);\n\n methods.forEach((method) => {\n const handlers = layer.route.stack || [];\n let config: ArkosRouteConfig | undefined;\n\n for (const handler of handlers) {\n const foundConfig = RouteConfigRegistry.get(handler.handle);\n\n if (foundConfig) {\n config = foundConfig;\n routes.push({\n path: fullPath,\n method: method.toUpperCase(),\n config,\n });\n\n break;\n }\n }\n });\n } else if (layer.name === \"router\" && layer.handle?.stack) {\n let nestedPrefix = prefix;\n\n if (layer.regexp) {\n const match = layer.regexp\n .toString()\n .match(/\\/\\^?(\\\\\\/[^?]+|\\/[^?]+)/);\n if (match) {\n nestedPrefix = prefix + \"/\" + match[1].replace(/\\\\\\//g, \"/\");\n nestedPrefix = nestedPrefix\n .replace(/\\/\\//g, \"/\")\n .replace(/\\/$/, \"\");\n }\n }\n\n extractFromStack(layer.handle.stack, nestedPrefix);\n }\n });\n }\n\n const stack = app._router?.stack || app.stack;\n if (stack) extractFromStack(stack, basePath);\n\n return routes;\n}\n\nexport function getMiddlewareStack(config: ArkosRouteConfig) {\n const middlewares = [];\n\n if (config.authentication) middlewares.push(authService.authenticate);\n\n if (\n typeof config.authentication === \"object\" &&\n config.authentication.action &&\n config.authentication.resource\n )\n middlewares.push(\n authService.handleAccessControl(\n config.authentication.action,\n config.authentication.resource,\n { [config.authentication.action]: config.authentication?.rule }\n )\n );\n\n if (config.rateLimit) middlewares.push(rateLimit(config.rateLimit));\n if (config.compression) middlewares.push(compression(config.compression));\n if (config.queryParser) middlewares.push(queryParser(config.queryParser));\n\n if (\n typeof config?.bodyParser === \"object\" &&\n [\"json\", \"urlencoded\", \"raw\", \"text\"].includes(config?.bodyParser?.parser)\n )\n middlewares.push(\n express[config.bodyParser.parser](config.bodyParser.options)\n );\n\n if (config.experimental?.uploads) {\n middlewares.push(uploadManager.handleUpload(config.experimental.uploads));\n\n middlewares.push(validateRequestInputs(config));\n\n middlewares.push(\n uploadManager.handlePostUpload(config.experimental.uploads)\n );\n } else middlewares.push(validateRequestInputs(config));\n\n return middlewares;\n}\n"]}