arkos 1.2.30-test → 1.2.31-test
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.
- package/dist/cjs/modules/auth/auth.router.js +8 -82
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +9 -93
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js +6 -19
- package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js +7 -0
- package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js.map +1 -1
- package/dist/cjs/server.js +1 -1
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/utils/cli/dev.js +5 -5
- package/dist/cjs/utils/cli/dev.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/cjs/utils/features/api.features.js +9 -3
- package/dist/cjs/utils/features/api.features.js.map +1 -1
- package/dist/cjs/utils/helpers/routers.helpers.js +21 -0
- package/dist/cjs/utils/helpers/routers.helpers.js.map +1 -0
- package/dist/cjs/utils/sheu.js +101 -125
- package/dist/cjs/utils/sheu.js.map +1 -1
- package/dist/esm/modules/auth/auth.router.js +8 -82
- package/dist/esm/modules/auth/auth.router.js.map +1 -1
- package/dist/esm/modules/base/utils/helpers/base.router.helpers.js +9 -93
- package/dist/esm/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.router.js +6 -19
- package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/esm/modules/file-upload/utils/helpers/file-upload.helpers.js +6 -0
- package/dist/esm/modules/file-upload/utils/helpers/file-upload.helpers.js.map +1 -1
- package/dist/esm/server.js +1 -1
- package/dist/esm/server.js.map +1 -1
- package/dist/esm/utils/cli/dev.js +5 -5
- package/dist/esm/utils/cli/dev.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/esm/utils/features/api.features.js +9 -3
- package/dist/esm/utils/features/api.features.js.map +1 -1
- package/dist/esm/utils/helpers/routers.helpers.js +16 -0
- package/dist/esm/utils/helpers/routers.helpers.js.map +1 -0
- package/dist/esm/utils/sheu.js +101 -125
- package/dist/esm/utils/sheu.js.map +1 -1
- package/dist/types/modules/error-handler/utils/catch-async.d.ts +1 -0
- package/dist/types/modules/file-upload/utils/helpers/file-upload.helpers.d.ts +2 -1
- package/dist/types/utils/features/api.features.d.ts +1 -0
- package/dist/types/utils/helpers/routers.helpers.d.ts +2 -0
- package/dist/types/utils/sheu.d.ts +66 -21
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import rateLimit from "express-rate-limit";
|
|
|
5
5
|
import { importPrismaModelModules } from "../../utils/helpers/models.helpers.js";
|
|
6
6
|
import { addPrismaQueryOptionsToRequest, handleRequestBodyValidationAndTransformation, sendResponse, } from "../base/base.middlewares.js";
|
|
7
7
|
import deepmerge from "../../utils/helpers/deepmerge.helper.js";
|
|
8
|
-
import
|
|
8
|
+
import { processMiddleware } from "../../utils/helpers/routers.helpers.js";
|
|
9
9
|
const router = Router();
|
|
10
10
|
export async function getAuthRouter(arkosConfigs) {
|
|
11
11
|
const { middlewares, dtos, schemas, prismaQueryOptions } = await importPrismaModelModules("auth", arkosConfigs);
|
|
@@ -20,43 +20,10 @@ export async function getAuthRouter(arkosConfigs) {
|
|
|
20
20
|
}
|
|
21
21
|
return undefined;
|
|
22
22
|
};
|
|
23
|
-
const safeCatchAsync = (middleware) => {
|
|
24
|
-
return middleware ? catchAsync(middleware) : undefined;
|
|
25
|
-
};
|
|
26
23
|
router
|
|
27
|
-
.get("/users/me", authService.authenticate, addPrismaQueryOptionsToRequest(prismaQueryOptions, "getMe"), ...
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
? authController.getMe
|
|
31
|
-
: safeCatchAsync(middlewares?.afterGetMe) || sendResponse,
|
|
32
|
-
safeCatchAsync(middlewares?.beforeGetMe) &&
|
|
33
|
-
safeCatchAsync(middlewares?.afterGetMe)
|
|
34
|
-
? safeCatchAsync(middlewares?.afterGetMe)
|
|
35
|
-
: sendResponse,
|
|
36
|
-
sendResponse,
|
|
37
|
-
].filter((middleware) => !!middleware))
|
|
38
|
-
.patch("/users/me", authService.authenticate, handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("updateMe")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateMe"), ...[
|
|
39
|
-
safeCatchAsync(middlewares?.beforeUpdateMe) || authController.updateMe,
|
|
40
|
-
safeCatchAsync(middlewares?.beforeUpdateMe)
|
|
41
|
-
? authController.updateMe
|
|
42
|
-
: safeCatchAsync(middlewares?.afterUpdateMe) || sendResponse,
|
|
43
|
-
safeCatchAsync(middlewares?.beforeUpdateMe) &&
|
|
44
|
-
safeCatchAsync(middlewares?.afterUpdateMe)
|
|
45
|
-
? safeCatchAsync(middlewares?.afterUpdateMe)
|
|
46
|
-
: sendResponse,
|
|
47
|
-
sendResponse,
|
|
48
|
-
].filter((middleware) => !!middleware))
|
|
49
|
-
.delete("/users/me", authService.authenticate, addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteMe"), ...[
|
|
50
|
-
safeCatchAsync(middlewares?.beforeDeleteMe) || authController.deleteMe,
|
|
51
|
-
safeCatchAsync(middlewares?.beforeDeleteMe)
|
|
52
|
-
? authController.deleteMe
|
|
53
|
-
: safeCatchAsync(middlewares?.afterDeleteMe) || sendResponse,
|
|
54
|
-
safeCatchAsync(middlewares?.beforeDeleteMe) &&
|
|
55
|
-
safeCatchAsync(middlewares?.afterDeleteMe)
|
|
56
|
-
? safeCatchAsync(middlewares?.afterDeleteMe)
|
|
57
|
-
: sendResponse,
|
|
58
|
-
sendResponse,
|
|
59
|
-
].filter((middleware) => !!middleware));
|
|
24
|
+
.get("/users/me", authService.authenticate, addPrismaQueryOptionsToRequest(prismaQueryOptions, "getMe"), ...processMiddleware(middlewares?.beforeGetMe), authController.getMe, ...processMiddleware(middlewares?.afterGetMe), sendResponse)
|
|
25
|
+
.patch("/users/me", authService.authenticate, handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("updateMe")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateMe"), ...processMiddleware(middlewares?.beforeUpdateMe), authController.updateMe, ...processMiddleware(middlewares?.afterUpdateMe), sendResponse)
|
|
26
|
+
.delete("/users/me", authService.authenticate, addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteMe"), ...processMiddleware(middlewares?.beforeDeleteMe), authController.deleteMe, ...processMiddleware(middlewares?.afterDeleteMe), sendResponse);
|
|
60
27
|
router.use("/auth", rateLimit(deepmerge({
|
|
61
28
|
windowMs: 5000,
|
|
62
29
|
limit: 10,
|
|
@@ -68,51 +35,10 @@ export async function getAuthRouter(arkosConfigs) {
|
|
|
68
35
|
});
|
|
69
36
|
},
|
|
70
37
|
}, arkosConfigs?.authentication?.requestRateLimitOptions || {})));
|
|
71
|
-
router.post("/auth/login", handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("login")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "login"), ...
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
: safeCatchAsync(middlewares?.afterLogin) || sendResponse,
|
|
76
|
-
safeCatchAsync(middlewares?.beforeLogin) &&
|
|
77
|
-
safeCatchAsync(middlewares?.afterLogin)
|
|
78
|
-
? safeCatchAsync(middlewares?.afterLogin)
|
|
79
|
-
: sendResponse,
|
|
80
|
-
sendResponse,
|
|
81
|
-
].filter((middleware) => !!middleware));
|
|
82
|
-
router.delete("/auth/logout", authService.authenticate, ...[
|
|
83
|
-
safeCatchAsync(middlewares?.beforeLogout) || authController.logout,
|
|
84
|
-
safeCatchAsync(middlewares?.beforeLogout)
|
|
85
|
-
? authController.logout
|
|
86
|
-
: safeCatchAsync(middlewares?.afterLogout) || sendResponse,
|
|
87
|
-
safeCatchAsync(middlewares?.beforeLogout) &&
|
|
88
|
-
safeCatchAsync(middlewares?.afterLogout)
|
|
89
|
-
? safeCatchAsync(middlewares?.afterLogout)
|
|
90
|
-
: sendResponse,
|
|
91
|
-
sendResponse,
|
|
92
|
-
].filter((middleware) => !!middleware));
|
|
93
|
-
router.post("/auth/signup", handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("signup")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "signup"), ...[
|
|
94
|
-
safeCatchAsync(middlewares?.beforeSignup) || authController.signup,
|
|
95
|
-
safeCatchAsync(middlewares?.beforeSignup)
|
|
96
|
-
? authController.signup
|
|
97
|
-
: safeCatchAsync(middlewares?.afterSignup) || sendResponse,
|
|
98
|
-
safeCatchAsync(middlewares?.beforeSignup) &&
|
|
99
|
-
safeCatchAsync(middlewares?.afterSignup)
|
|
100
|
-
? safeCatchAsync(middlewares?.afterSignup)
|
|
101
|
-
: sendResponse,
|
|
102
|
-
sendResponse,
|
|
103
|
-
].filter((middleware) => !!middleware));
|
|
104
|
-
router.post("/auth/update-password", authService.authenticate, handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("updatePassword")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updatePassword"), ...[
|
|
105
|
-
safeCatchAsync(middlewares?.beforeUpdatePassword) ||
|
|
106
|
-
authController.updatePassword,
|
|
107
|
-
safeCatchAsync(middlewares?.beforeUpdatePassword)
|
|
108
|
-
? authController.updatePassword
|
|
109
|
-
: safeCatchAsync(middlewares?.afterUpdatePassword) || sendResponse,
|
|
110
|
-
safeCatchAsync(middlewares?.beforeUpdatePassword) &&
|
|
111
|
-
safeCatchAsync(middlewares?.afterUpdatePassword)
|
|
112
|
-
? safeCatchAsync(middlewares?.afterUpdatePassword)
|
|
113
|
-
: sendResponse,
|
|
114
|
-
sendResponse,
|
|
115
|
-
].filter((middleware) => !!middleware));
|
|
38
|
+
router.post("/auth/login", handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("login")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "login"), ...processMiddleware(middlewares?.beforeLogin), authController.login, ...processMiddleware(middlewares?.afterLogin), sendResponse);
|
|
39
|
+
router.delete("/auth/logout", authService.authenticate, ...processMiddleware(middlewares?.beforeLogout), authController.logout, ...processMiddleware(middlewares?.afterLogout), sendResponse);
|
|
40
|
+
router.post("/auth/signup", handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("signup")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "signup"), ...processMiddleware(middlewares?.beforeSignup), authController.signup, ...processMiddleware(middlewares?.afterSignup), sendResponse);
|
|
41
|
+
router.post("/auth/update-password", authService.authenticate, handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("updatePassword")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updatePassword"), ...processMiddleware(middlewares?.beforeUpdatePassword), authController.updatePassword, ...processMiddleware(middlewares?.afterUpdatePassword), sendResponse);
|
|
116
42
|
return router;
|
|
117
43
|
}
|
|
118
44
|
//# sourceMappingURL=auth.router.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,WAAW,MAAM,gBAAgB,CAAC;AACzC,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EACL,8BAA8B,EAC9B,4CAA4C,EAC5C,YAAY,GACb,MAAM,0BAA0B,CAAC;AAElC,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAE7D,OAAO,UAAU,MAAM,oCAAoC,CAA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ACD,8BAA8B,CAC5B,kBAAiD,EACjD,gBAAgB,CACjB,EACD,GAAG;QACD,cAAc,CAAC,WAAW,EAAE,oBAAoB,CAAC;YAC/C,cAAc,CAAC,cAAc;QAC/B,cAAc,CAAC,WAAW,EAAE,oBAAoB,CAAC;YAC/C,CAAC,CAAC,cAAc,CAAC,cAAc;YAC/B,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB,CAAC,IAAI,YAAY;QACpE,cAAc,CAAC,WAAW,EAAE,oBAAoB,CAAC;YACjD,cAAc,CAAC,WAAW,EAAE,mBAAmB,CAAC;YAC9C,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB,CAAC;YAClD,CAAC,CAAC,YAAY;QAChB,YAAY;KACb,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CACvC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { authControllerFactory } from \"./auth.controller\";\nimport authService from \"./auth.service\";\nimport rateLimit from \"express-rate-limit\";\nimport { importPrismaModelModules } from \"../../utils/helpers/models.helpers\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport catchAsync from \"../error-handler/utils/catch-async\";\n\nconst router: Router = Router();\n\nexport async function getAuthRouter(arkosConfigs: ArkosConfig) {\n const { middlewares, dtos, schemas, prismaQueryOptions } =\n await importPrismaModelModules(\"auth\", arkosConfigs);\n const authController = await authControllerFactory(middlewares);\n\n // Helper to get the correct schema or DTO based on Arkos Config\n const getValidationSchemaOrDto = (key: string) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n // Helper to conditionally wrap middleware with catchAsync\n const safeCatchAsync = (middleware: any) => {\n return middleware ? catchAsync(middleware) : undefined;\n };\n\n router\n .get(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeGetMe) || authController.getMe,\n safeCatchAsync(middlewares?.beforeGetMe)\n ? authController.getMe\n : safeCatchAsync(middlewares?.afterGetMe) || sendResponse,\n safeCatchAsync(middlewares?.beforeGetMe) &&\n safeCatchAsync(middlewares?.afterGetMe)\n ? safeCatchAsync(middlewares?.afterGetMe)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n )\n .patch(\n \"/users/me\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMe\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdateMe) || authController.updateMe,\n safeCatchAsync(middlewares?.beforeUpdateMe)\n ? authController.updateMe\n : safeCatchAsync(middlewares?.afterUpdateMe) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdateMe) &&\n safeCatchAsync(middlewares?.afterUpdateMe)\n ? safeCatchAsync(middlewares?.afterUpdateMe)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n )\n .delete(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeDeleteMe) || authController.deleteMe,\n safeCatchAsync(middlewares?.beforeDeleteMe)\n ? authController.deleteMe\n : safeCatchAsync(middlewares?.afterDeleteMe) || sendResponse,\n safeCatchAsync(middlewares?.beforeDeleteMe) &&\n safeCatchAsync(middlewares?.afterDeleteMe)\n ? safeCatchAsync(middlewares?.afterDeleteMe)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n\n router.use(\n \"/auth\",\n rateLimit(\n deepmerge(\n {\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n handler: (req, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n arkosConfigs?.authentication?.requestRateLimitOptions || {}\n )\n )\n );\n\n router.post(\n \"/auth/login\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"login\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeLogin) || authController.login,\n safeCatchAsync(middlewares?.beforeLogin)\n ? authController.login\n : safeCatchAsync(middlewares?.afterLogin) || sendResponse,\n safeCatchAsync(middlewares?.beforeLogin) &&\n safeCatchAsync(middlewares?.afterLogin)\n ? safeCatchAsync(middlewares?.afterLogin)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n\n router.delete(\n \"/auth/logout\",\n authService.authenticate,\n ...[\n safeCatchAsync(middlewares?.beforeLogout) || authController.logout,\n safeCatchAsync(middlewares?.beforeLogout)\n ? authController.logout\n : safeCatchAsync(middlewares?.afterLogout) || sendResponse,\n safeCatchAsync(middlewares?.beforeLogout) &&\n safeCatchAsync(middlewares?.afterLogout)\n ? safeCatchAsync(middlewares?.afterLogout)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n\n router.post(\n \"/auth/signup\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"signup\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeSignup) || authController.signup,\n safeCatchAsync(middlewares?.beforeSignup)\n ? authController.signup\n : safeCatchAsync(middlewares?.afterSignup) || sendResponse,\n safeCatchAsync(middlewares?.beforeSignup) &&\n safeCatchAsync(middlewares?.afterSignup)\n ? safeCatchAsync(middlewares?.afterSignup)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n\n router.post(\n \"/auth/update-password\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updatePassword\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdatePassword) ||\n authController.updatePassword,\n safeCatchAsync(middlewares?.beforeUpdatePassword)\n ? authController.updatePassword\n : safeCatchAsync(middlewares?.afterUpdatePassword) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdatePassword) &&\n safeCatchAsync(middlewares?.afterUpdatePassword)\n ? safeCatchAsync(middlewares?.afterUpdatePassword)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n\n return router;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"auth.router.js","sourceRoot":"","sources":["../../../../src/modules/auth/auth.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,WAAW,MAAM,gBAAgB,CAAC;AACzC,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EACL,8BAA8B,EAC9B,4CAA4C,EAC5C,YAAY,GACb,MAAM,0BAA0B,CAAC;AAElC,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,MAAM,MAAM,GAAW,MAAM,EAAE,CAAC;AAEhC,M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AAC,EAC/C,cAAc,CAAC,MAAM,EACrB,GAAG,iBAAiB,CAAC,WAAW,EAAE,WAAW,CAAC,EAC9C,YAAY,CACb,CAAC;IAEF,MAAM,CAAC,IAAI,CACT,uBAAuB,EACvB,WAAW,CAAC,YAAY,EACxB,4CAA4C,CAC1C,wBAAwB,CAAC,gBAAgB,CAAC,CAC3C,EACD,8BAA8B,CAC5B,kBAAiD,EACjD,gBAAgB,CACjB,EACD,GAAG,iBAAiB,CAAC,WAAW,EAAE,oBAAoB,CAAC,EACvD,cAAc,CAAC,cAAc,EAC7B,GAAG,iBAAiB,CAAC,WAAW,EAAE,mBAAmB,CAAC,EACtD,YAAY,CACb,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { authControllerFactory } from \"./auth.controller\";\nimport authService from \"./auth.service\";\nimport rateLimit from \"express-rate-limit\";\nimport { importPrismaModelModules } from \"../../utils/helpers/models.helpers\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../base/base.middlewares\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthPrismaQueryOptions } from \"../../types\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\n\nconst router: Router = Router();\n\nexport async function getAuthRouter(arkosConfigs: ArkosConfig) {\n const { middlewares, dtos, schemas, prismaQueryOptions } =\n await importPrismaModelModules(\"auth\", arkosConfigs);\n const authController = await authControllerFactory(middlewares);\n\n // Helper to get the correct schema or DTO based on Arkos Config\n const getValidationSchemaOrDto = (key: string) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n router\n .get(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"getMe\"\n ),\n ...processMiddleware(middlewares?.beforeGetMe),\n authController.getMe,\n ...processMiddleware(middlewares?.afterGetMe),\n sendResponse\n )\n .patch(\n \"/users/me\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMe\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updateMe\"\n ),\n ...processMiddleware(middlewares?.beforeUpdateMe),\n authController.updateMe,\n ...processMiddleware(middlewares?.afterUpdateMe),\n sendResponse\n )\n .delete(\n \"/users/me\",\n authService.authenticate,\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"deleteMe\"\n ),\n ...processMiddleware(middlewares?.beforeDeleteMe),\n authController.deleteMe,\n ...processMiddleware(middlewares?.afterDeleteMe),\n sendResponse\n );\n\n router.use(\n \"/auth\",\n rateLimit(\n deepmerge(\n {\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n handler: (req, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n arkosConfigs?.authentication?.requestRateLimitOptions || {}\n )\n )\n );\n\n router.post(\n \"/auth/login\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"login\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"login\"\n ),\n ...processMiddleware(middlewares?.beforeLogin),\n authController.login,\n ...processMiddleware(middlewares?.afterLogin),\n sendResponse\n );\n\n router.delete(\n \"/auth/logout\",\n authService.authenticate,\n ...processMiddleware(middlewares?.beforeLogout),\n authController.logout,\n ...processMiddleware(middlewares?.afterLogout),\n sendResponse\n );\n\n router.post(\n \"/auth/signup\",\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"signup\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"signup\"\n ),\n ...processMiddleware(middlewares?.beforeSignup),\n authController.signup,\n ...processMiddleware(middlewares?.afterSignup),\n sendResponse\n );\n\n router.post(\n \"/auth/update-password\",\n authService.authenticate,\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updatePassword\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as AuthPrismaQueryOptions<any>,\n \"updatePassword\"\n ),\n ...processMiddleware(middlewares?.beforeUpdatePassword),\n authController.updatePassword,\n ...processMiddleware(middlewares?.afterUpdatePassword),\n sendResponse\n );\n\n return router;\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { importPrismaModelModules } from "../../../../utils/helpers/models.helpe
|
|
|
4
4
|
import authService from "../../../auth/auth.service.js";
|
|
5
5
|
import { BaseController } from "../../base.controller.js";
|
|
6
6
|
import { addPrismaQueryOptionsToRequest, handleRequestBodyValidationAndTransformation, sendResponse, } from "../../base.middlewares.js";
|
|
7
|
-
import
|
|
7
|
+
import { processMiddleware } from "../../../../utils/helpers/routers.helpers.js";
|
|
8
8
|
export function setupRouters(models, router, arkosConfigs) {
|
|
9
9
|
return models.map(async (model) => {
|
|
10
10
|
const modelNameInKebab = kebabCase(model);
|
|
@@ -33,121 +33,37 @@ export function setupRouters(models, router, arkosConfigs) {
|
|
|
33
33
|
};
|
|
34
34
|
if (customRouterModule?.default && !routerConfig?.disable)
|
|
35
35
|
router.use(`/${routeName}`, customRouterModule.default);
|
|
36
|
-
function safeCatchAsync(middleware) {
|
|
37
|
-
return middleware ? catchAsync(middleware) : undefined;
|
|
38
|
-
}
|
|
39
36
|
if (!isEndpointDisabled(routerConfig, "createOne") &&
|
|
40
37
|
!hasCustomImplementation(`/${routeName}`, "post")) {
|
|
41
|
-
router.post(`/${routeName}`, authService.handleAuthenticationControl("Create", authConfigs?.authenticationControl), authService.handleAccessControl("Create", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("create")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "createOne"), ...
|
|
42
|
-
safeCatchAsync(middlewares?.beforeCreateOne) || controller.createOne,
|
|
43
|
-
safeCatchAsync(middlewares?.beforeCreateOne)
|
|
44
|
-
? controller.createOne
|
|
45
|
-
: safeCatchAsync(middlewares?.afterCreateOne) || sendResponse,
|
|
46
|
-
safeCatchAsync(middlewares?.beforeCreateOne) &&
|
|
47
|
-
safeCatchAsync(middlewares?.afterCreateOne)
|
|
48
|
-
? safeCatchAsync(middlewares?.afterCreateOne)
|
|
49
|
-
: sendResponse,
|
|
50
|
-
].filter((m) => !!m), sendResponse);
|
|
38
|
+
router.post(`/${routeName}`, authService.handleAuthenticationControl("Create", authConfigs?.authenticationControl), authService.handleAccessControl("Create", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("create")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "createOne"), ...processMiddleware(middlewares?.beforeCreateOne), controller.createOne, ...processMiddleware(middlewares?.afterCreateOne), sendResponse);
|
|
51
39
|
}
|
|
52
40
|
if (!isEndpointDisabled(routerConfig, "findMany") &&
|
|
53
41
|
!hasCustomImplementation(`/${routeName}`, "get")) {
|
|
54
|
-
router.get(`/${routeName}`, authService.handleAuthenticationControl("View", authConfigs?.authenticationControl), authService.handleAccessControl("View", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), addPrismaQueryOptionsToRequest(prismaQueryOptions, "findMany"), ...
|
|
55
|
-
safeCatchAsync(middlewares?.beforeFindMany) || controller.findMany,
|
|
56
|
-
safeCatchAsync(middlewares?.beforeFindMany)
|
|
57
|
-
? controller.findMany
|
|
58
|
-
: safeCatchAsync(middlewares?.afterFindMany) || sendResponse,
|
|
59
|
-
safeCatchAsync(middlewares?.beforeFindMany) &&
|
|
60
|
-
safeCatchAsync(middlewares?.afterFindMany)
|
|
61
|
-
? safeCatchAsync(middlewares?.afterFindMany)
|
|
62
|
-
: sendResponse,
|
|
63
|
-
sendResponse,
|
|
64
|
-
].filter((m) => !!m));
|
|
42
|
+
router.get(`/${routeName}`, authService.handleAuthenticationControl("View", authConfigs?.authenticationControl), authService.handleAccessControl("View", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), addPrismaQueryOptionsToRequest(prismaQueryOptions, "findMany"), ...processMiddleware(middlewares?.beforeFindMany), controller.findMany, ...processMiddleware(middlewares?.afterFindMany), sendResponse);
|
|
65
43
|
}
|
|
66
44
|
if (!isEndpointDisabled(routerConfig, "createMany") &&
|
|
67
45
|
!hasCustomImplementation(`/${routeName}/many`, "post")) {
|
|
68
|
-
router.post(`/${routeName}/many`, authService.handleAuthenticationControl("Create", authConfigs?.authenticationControl), authService.handleAccessControl("Create", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("createMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "createMany"), ...
|
|
69
|
-
safeCatchAsync(middlewares?.beforeCreateMany) ||
|
|
70
|
-
controller.createMany,
|
|
71
|
-
safeCatchAsync(middlewares?.beforeCreateMany)
|
|
72
|
-
? controller.createMany
|
|
73
|
-
: safeCatchAsync(middlewares?.afterCreateMany) || sendResponse,
|
|
74
|
-
safeCatchAsync(middlewares?.beforeCreateMany) &&
|
|
75
|
-
safeCatchAsync(middlewares?.afterCreateMany)
|
|
76
|
-
? safeCatchAsync(middlewares?.afterCreateMany)
|
|
77
|
-
: sendResponse,
|
|
78
|
-
sendResponse,
|
|
79
|
-
].filter((m) => !!m));
|
|
46
|
+
router.post(`/${routeName}/many`, authService.handleAuthenticationControl("Create", authConfigs?.authenticationControl), authService.handleAccessControl("Create", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("createMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "createMany"), ...processMiddleware(middlewares?.beforeCreateMany), controller.createMany, ...processMiddleware(middlewares?.afterCreateMany), sendResponse);
|
|
80
47
|
}
|
|
81
48
|
if (!isEndpointDisabled(routerConfig, "updateMany") &&
|
|
82
49
|
!hasCustomImplementation(`/${routeName}/many`, "patch")) {
|
|
83
|
-
router.patch(`/${routeName}/many`, authService.handleAuthenticationControl("Update", authConfigs?.authenticationControl), authService.handleAccessControl("Update", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("updateMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateMany"), ...
|
|
84
|
-
safeCatchAsync(middlewares?.beforeUpdateMany) ||
|
|
85
|
-
controller.updateMany,
|
|
86
|
-
safeCatchAsync(middlewares?.beforeUpdateMany)
|
|
87
|
-
? controller.updateMany
|
|
88
|
-
: safeCatchAsync(middlewares?.afterUpdateMany) || sendResponse,
|
|
89
|
-
safeCatchAsync(middlewares?.beforeUpdateMany) &&
|
|
90
|
-
safeCatchAsync(middlewares?.afterUpdateMany)
|
|
91
|
-
? safeCatchAsync(middlewares?.afterUpdateMany)
|
|
92
|
-
: sendResponse,
|
|
93
|
-
sendResponse,
|
|
94
|
-
].filter((m) => !!m));
|
|
50
|
+
router.patch(`/${routeName}/many`, authService.handleAuthenticationControl("Update", authConfigs?.authenticationControl), authService.handleAccessControl("Update", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("updateMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateMany"), ...processMiddleware(middlewares?.beforeUpdateMany), controller.updateMany, ...processMiddleware(middlewares?.afterUpdateMany), sendResponse);
|
|
95
51
|
}
|
|
96
52
|
if (!isEndpointDisabled(routerConfig, "deleteMany") &&
|
|
97
53
|
!hasCustomImplementation(`/${routeName}/many`, "delete")) {
|
|
98
|
-
router.delete(`/${routeName}/many`, authService.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), authService.handleAccessControl("Delete", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("deleteMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteMany"), ...
|
|
99
|
-
safeCatchAsync(middlewares?.beforeDeleteMany) ||
|
|
100
|
-
controller.deleteMany,
|
|
101
|
-
safeCatchAsync(middlewares?.beforeDeleteMany)
|
|
102
|
-
? controller.deleteMany
|
|
103
|
-
: safeCatchAsync(middlewares?.afterDeleteMany) || sendResponse,
|
|
104
|
-
safeCatchAsync(middlewares?.beforeDeleteMany) &&
|
|
105
|
-
safeCatchAsync(middlewares?.afterDeleteMany)
|
|
106
|
-
? safeCatchAsync(middlewares?.afterDeleteMany)
|
|
107
|
-
: sendResponse,
|
|
108
|
-
sendResponse,
|
|
109
|
-
].filter((middleware) => !!middleware));
|
|
54
|
+
router.delete(`/${routeName}/many`, authService.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), authService.handleAccessControl("Delete", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("deleteMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteMany"), ...processMiddleware(middlewares?.beforeDeleteMany), controller.deleteMany, ...processMiddleware(middlewares?.afterDeleteMany), sendResponse);
|
|
110
55
|
}
|
|
111
56
|
if (!isEndpointDisabled(routerConfig, "findOne") &&
|
|
112
57
|
!hasCustomImplementation(`/${routeName}/:id`, "get")) {
|
|
113
|
-
router.get(`/${routeName}/:id`, authService.handleAuthenticationControl("View", authConfigs?.authenticationControl), authService.handleAccessControl("View", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("findOne")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "findOne"), ...
|
|
114
|
-
safeCatchAsync(middlewares?.beforeFindOne) || controller.findOne,
|
|
115
|
-
safeCatchAsync(middlewares?.beforeFindOne)
|
|
116
|
-
? controller.findOne
|
|
117
|
-
: safeCatchAsync(middlewares?.afterFindOne) || sendResponse,
|
|
118
|
-
safeCatchAsync(middlewares?.beforeFindOne) &&
|
|
119
|
-
safeCatchAsync(middlewares?.afterFindOne)
|
|
120
|
-
? safeCatchAsync(middlewares?.afterFindOne)
|
|
121
|
-
: sendResponse,
|
|
122
|
-
sendResponse,
|
|
123
|
-
].filter((m) => !!m));
|
|
58
|
+
router.get(`/${routeName}/:id`, authService.handleAuthenticationControl("View", authConfigs?.authenticationControl), authService.handleAccessControl("View", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("findOne")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "findOne"), ...processMiddleware(middlewares?.beforeFindOne), controller.findOne, ...processMiddleware(middlewares?.afterFindOne), sendResponse);
|
|
124
59
|
}
|
|
125
60
|
if (!isEndpointDisabled(routerConfig, "updateOne") &&
|
|
126
61
|
!hasCustomImplementation(`/${routeName}/:id`, "patch")) {
|
|
127
|
-
router.patch(`/${routeName}/:id`, authService.handleAuthenticationControl("Update", authConfigs?.authenticationControl), authService.handleAccessControl("Update", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("update")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateOne"), ...
|
|
128
|
-
safeCatchAsync(middlewares?.beforeUpdateOne) || controller.updateOne,
|
|
129
|
-
safeCatchAsync(middlewares?.beforeUpdateOne)
|
|
130
|
-
? controller.updateOne
|
|
131
|
-
: safeCatchAsync(middlewares?.afterUpdateOne) || sendResponse,
|
|
132
|
-
safeCatchAsync(middlewares?.beforeUpdateOne) &&
|
|
133
|
-
safeCatchAsync(middlewares?.afterUpdateOne)
|
|
134
|
-
? safeCatchAsync(middlewares?.afterUpdateOne)
|
|
135
|
-
: sendResponse,
|
|
136
|
-
].filter((m) => !!m), sendResponse);
|
|
62
|
+
router.patch(`/${routeName}/:id`, authService.handleAuthenticationControl("Update", authConfigs?.authenticationControl), authService.handleAccessControl("Update", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("update")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateOne"), ...processMiddleware(middlewares?.beforeUpdateOne), controller.updateOne, ...processMiddleware(middlewares?.afterUpdateOne), sendResponse);
|
|
137
63
|
}
|
|
138
64
|
if (!isEndpointDisabled(routerConfig, "deleteOne") &&
|
|
139
65
|
!hasCustomImplementation(`/${routeName}/:id`, "delete")) {
|
|
140
|
-
router.delete(`/${routeName}/:id`, authService.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), authService.handleAccessControl("Delete", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("delete")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteOne"), ...
|
|
141
|
-
safeCatchAsync(middlewares?.beforeDeleteOne) || controller.deleteOne,
|
|
142
|
-
safeCatchAsync(middlewares?.beforeDeleteOne)
|
|
143
|
-
? controller.deleteOne
|
|
144
|
-
: safeCatchAsync(middlewares?.afterDeleteOne) || sendResponse,
|
|
145
|
-
safeCatchAsync(middlewares?.beforeDeleteOne) &&
|
|
146
|
-
safeCatchAsync(middlewares?.afterDeleteOne)
|
|
147
|
-
? safeCatchAsync(middlewares?.afterDeleteOne)
|
|
148
|
-
: sendResponse,
|
|
149
|
-
sendResponse,
|
|
150
|
-
].filter((m) => !!m));
|
|
66
|
+
router.delete(`/${routeName}/:id`, authService.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), authService.handleAccessControl("Delete", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("delete")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteOne"), ...processMiddleware(middlewares?.beforeDeleteOne), controller.deleteOne, ...processMiddleware(middlewares?.afterDeleteOne), sendResponse);
|
|
151
67
|
}
|
|
152
68
|
});
|
|
153
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.router.helpers.js","sourceRoot":"","sources":["../../../../../../src/modules/base/utils/helpers/base.router.helpers.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,WAAW,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,8BAA8B,EAC9B,4CAA4C,EAC5C,YAAY,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,UAAU,MAAM,0CAA0C,CAAC;AAElE,MAAM,UAAU,YAAY,CAC1B,MAAgB,EAChB,MAAc,EACd,YAAyB;IAEzB,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAChC,MAAM,gBAAgB,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,MAAM,wBAAwB,CACjD,gBAAgB,EAChB,YAAY,CACb,CAAC;QACF,MAAM,EACJ,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EACJ,OAAO,GACR,GAAG,YAAY,CAAC;QAEjB,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACrD,MAAM,UAAU,GAAG,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;QAE7C,MAAM,YAAY,GAAiB,kBAAkB,EAA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C;QAAE,OAAO,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE9E,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { Router } from \"express\";\nimport pluralize from \"pluralize\";\nimport { ArkosConfig, RouterConfig } from \"../../../../exports\";\nimport { kebabCase } from \"../../../../exports/utils\";\nimport { PrismaQueryOptions } from \"../../../../types\";\nimport { RouterEndpoint } from \"../../../../types/router-config\";\nimport { importPrismaModelModules } from \"../../../../utils/helpers/models.helpers\";\nimport authService from \"../../../auth/auth.service\";\nimport { BaseController } from \"../../base.controller\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../../base.middlewares\";\nimport catchAsync from \"../../../error-handler/utils/catch-async\";\n\nexport function setupRouters(\n models: string[],\n router: Router,\n arkosConfigs: ArkosConfig\n) {\n return models.map(async (model) => {\n const modelNameInKebab = kebabCase(model);\n const modelModules = await importPrismaModelModules(\n modelNameInKebab,\n arkosConfigs\n );\n const {\n middlewares,\n authConfigs,\n prismaQueryOptions,\n router: customRouterModule,\n dtos,\n schemas,\n } = modelModules;\n\n const routeName = pluralize.plural(modelNameInKebab);\n const controller = new BaseController(model);\n\n const routerConfig: RouterConfig = customRouterModule?.config || {};\n\n // Check if custom implementation exists\n const customRouter = (customRouterModule as Router) || {};\n const hasCustomImplementation = (path: string, method: string) => {\n return customRouter.stack?.some(\n (layer) =>\n (layer.path === `/api/${path}` ||\n layer.path === `api/${path}` ||\n layer.path === `api/${path}/` ||\n layer.path === `/api/${path}/`) &&\n layer.method.toLowerCase() === method.toLowerCase()\n );\n };\n\n // Helper to get the correct schema or DTO based on Arkos Config\n const getValidationSchemaOrDto = (key: string) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n // If the custom router has its own routes, add them\n if (customRouterModule?.default && !routerConfig?.disable)\n router.use(`/${routeName}`, customRouterModule.default);\n\n function safeCatchAsync(middleware: any) {\n return middleware ? catchAsync(middleware) : undefined;\n }\n\n // POST /{routeName} - Create One\n if (\n !isEndpointDisabled(routerConfig, \"createOne\") &&\n !hasCustomImplementation(`/${routeName}`, \"post\")\n ) {\n router.post(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"create\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeCreateOne) || controller.createOne,\n safeCatchAsync(middlewares?.beforeCreateOne)\n ? controller.createOne\n : safeCatchAsync(middlewares?.afterCreateOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeCreateOne) &&\n safeCatchAsync(middlewares?.afterCreateOne)\n ? safeCatchAsync(middlewares?.afterCreateOne)\n : sendResponse,\n ].filter((m) => !!m),\n sendResponse\n );\n }\n\n // GET /{routeName} - Find Many\n if (\n !isEndpointDisabled(routerConfig, \"findMany\") &&\n !hasCustomImplementation(`/${routeName}`, \"get\")\n ) {\n router.get(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeFindMany) || controller.findMany,\n safeCatchAsync(middlewares?.beforeFindMany)\n ? controller.findMany\n : safeCatchAsync(middlewares?.afterFindMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeFindMany) &&\n safeCatchAsync(middlewares?.afterFindMany)\n ? safeCatchAsync(middlewares?.afterFindMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // POST /{routeName}/many - Create Many\n if (\n !isEndpointDisabled(routerConfig, \"createMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"post\")\n ) {\n router.post(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"createMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeCreateMany) ||\n controller.createMany,\n safeCatchAsync(middlewares?.beforeCreateMany)\n ? controller.createMany\n : safeCatchAsync(middlewares?.afterCreateMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeCreateMany) &&\n safeCatchAsync(middlewares?.afterCreateMany)\n ? safeCatchAsync(middlewares?.afterCreateMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // PATCH /{routeName}/many - Update Many\n if (\n !isEndpointDisabled(routerConfig, \"updateMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdateMany) ||\n controller.updateMany,\n safeCatchAsync(middlewares?.beforeUpdateMany)\n ? controller.updateMany\n : safeCatchAsync(middlewares?.afterUpdateMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdateMany) &&\n safeCatchAsync(middlewares?.afterUpdateMany)\n ? safeCatchAsync(middlewares?.afterUpdateMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // DELETE /{routeName}/many - Delete Many\n if (\n !isEndpointDisabled(routerConfig, \"deleteMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"deleteMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeDeleteMany) ||\n controller.deleteMany,\n safeCatchAsync(middlewares?.beforeDeleteMany)\n ? controller.deleteMany\n : safeCatchAsync(middlewares?.afterDeleteMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeDeleteMany) &&\n safeCatchAsync(middlewares?.afterDeleteMany)\n ? safeCatchAsync(middlewares?.afterDeleteMany)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n }\n\n // GET /{routeName}/:id - Find One\n if (\n !isEndpointDisabled(routerConfig, \"findOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"get\")\n ) {\n router.get(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"findOne\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeFindOne) || controller.findOne,\n safeCatchAsync(middlewares?.beforeFindOne)\n ? controller.findOne\n : safeCatchAsync(middlewares?.afterFindOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeFindOne) &&\n safeCatchAsync(middlewares?.afterFindOne)\n ? safeCatchAsync(middlewares?.afterFindOne)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // PATCH /{routeName}/:id - Update One\n if (\n !isEndpointDisabled(routerConfig, \"updateOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"update\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdateOne) || controller.updateOne,\n safeCatchAsync(middlewares?.beforeUpdateOne)\n ? controller.updateOne\n : safeCatchAsync(middlewares?.afterUpdateOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdateOne) &&\n safeCatchAsync(middlewares?.afterUpdateOne)\n ? safeCatchAsync(middlewares?.afterUpdateOne)\n : sendResponse,\n ].filter((m) => !!m),\n sendResponse\n );\n }\n\n // DELETE /{routeName}/:id - Delete One\n if (\n !isEndpointDisabled(routerConfig, \"deleteOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"delete\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeDeleteOne) || controller.deleteOne,\n safeCatchAsync(middlewares?.beforeDeleteOne)\n ? controller.deleteOne\n : safeCatchAsync(middlewares?.afterDeleteOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeDeleteOne) &&\n safeCatchAsync(middlewares?.afterDeleteOne)\n ? safeCatchAsync(middlewares?.afterDeleteOne)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n });\n}\n\nexport function isEndpointDisabled(\n routerConfig: RouterConfig,\n endpoint: RouterEndpoint\n): boolean {\n if (!routerConfig?.disable) return false;\n\n if (routerConfig.disable === true) return true;\n\n if (typeof routerConfig.disable === \"object\")\n return routerConfig.disable[endpoint] === true;\n\n return false;\n}\n\nexport function isParentEndpointAllowed(\n routerConfig: any,\n endpoint: string\n): boolean {\n if (!routerConfig?.parent) return false;\n\n const parentEndpoints = routerConfig.parent.endpoints;\n if (parentEndpoints === \"*\") return true;\n if (Array.isArray(parentEndpoints)) return parentEndpoints.includes(endpoint);\n\n return true; // Default to allow if not specified\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.router.helpers.js","sourceRoot":"","sources":["../../../../../../src/modules/base/utils/helpers/base.router.helpers.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,WAAW,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,8BAA8B,EAC9B,4CAA4C,EAC5C,YAAY,GACb,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AAM,CAAC,SAAS,CAAC;IACtD,IAAI,eAAe,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;QAAE,OAAO,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE9E,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { Router } from \"express\";\nimport pluralize from \"pluralize\";\nimport { ArkosConfig, RouterConfig } from \"../../../../exports\";\nimport { kebabCase } from \"../../../../exports/utils\";\nimport { PrismaQueryOptions } from \"../../../../types\";\nimport { RouterEndpoint } from \"../../../../types/router-config\";\nimport { importPrismaModelModules } from \"../../../../utils/helpers/models.helpers\";\nimport authService from \"../../../auth/auth.service\";\nimport { BaseController } from \"../../base.controller\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../../base.middlewares\";\nimport { processMiddleware } from \"../../../../utils/helpers/routers.helpers\";\n\nexport function setupRouters(\n models: string[],\n router: Router,\n arkosConfigs: ArkosConfig\n) {\n return models.map(async (model) => {\n const modelNameInKebab = kebabCase(model);\n const modelModules = await importPrismaModelModules(\n modelNameInKebab,\n arkosConfigs\n );\n const {\n middlewares,\n authConfigs,\n prismaQueryOptions,\n router: customRouterModule,\n dtos,\n schemas,\n } = modelModules;\n\n const routeName = pluralize.plural(modelNameInKebab);\n const controller = new BaseController(model);\n\n const routerConfig: RouterConfig = customRouterModule?.config || {};\n\n // Check if custom implementation exists\n const customRouter = (customRouterModule as Router) || {};\n const hasCustomImplementation = (path: string, method: string) => {\n return customRouter.stack?.some(\n (layer) =>\n (layer.path === `/api/${path}` ||\n layer.path === `api/${path}` ||\n layer.path === `api/${path}/` ||\n layer.path === `/api/${path}/`) &&\n layer.method.toLowerCase() === method.toLowerCase()\n );\n };\n\n // Helper to get the correct schema or DTO based on Arkos Config\n const getValidationSchemaOrDto = (key: string) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n // If the custom router has its own routes, add them\n if (customRouterModule?.default && !routerConfig?.disable)\n router.use(`/${routeName}`, customRouterModule.default);\n\n // POST /{routeName} - Create One\n if (\n !isEndpointDisabled(routerConfig, \"createOne\") &&\n !hasCustomImplementation(`/${routeName}`, \"post\")\n ) {\n router.post(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"create\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createOne\"\n ),\n ...processMiddleware(middlewares?.beforeCreateOne),\n controller.createOne,\n ...processMiddleware(middlewares?.afterCreateOne),\n sendResponse\n );\n }\n\n // GET /{routeName} - Find Many\n if (\n !isEndpointDisabled(routerConfig, \"findMany\") &&\n !hasCustomImplementation(`/${routeName}`, \"get\")\n ) {\n router.get(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findMany\"\n ),\n ...processMiddleware(middlewares?.beforeFindMany),\n controller.findMany,\n ...processMiddleware(middlewares?.afterFindMany),\n sendResponse\n );\n }\n\n // POST /{routeName}/many - Create Many\n if (\n !isEndpointDisabled(routerConfig, \"createMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"post\")\n ) {\n router.post(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"createMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createMany\"\n ),\n ...processMiddleware(middlewares?.beforeCreateMany),\n controller.createMany,\n ...processMiddleware(middlewares?.afterCreateMany),\n sendResponse\n );\n }\n\n // PATCH /{routeName}/many - Update Many\n if (\n !isEndpointDisabled(routerConfig, \"updateMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateMany\"\n ),\n ...processMiddleware(middlewares?.beforeUpdateMany),\n controller.updateMany,\n ...processMiddleware(middlewares?.afterUpdateMany),\n sendResponse\n );\n }\n\n // DELETE /{routeName}/many - Delete Many\n if (\n !isEndpointDisabled(routerConfig, \"deleteMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"deleteMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteMany\"\n ),\n ...processMiddleware(middlewares?.beforeDeleteMany),\n controller.deleteMany,\n ...processMiddleware(middlewares?.afterDeleteMany),\n sendResponse\n );\n }\n\n // GET /{routeName}/:id - Find One\n if (\n !isEndpointDisabled(routerConfig, \"findOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"get\")\n ) {\n router.get(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"findOne\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findOne\"\n ),\n ...processMiddleware(middlewares?.beforeFindOne),\n controller.findOne,\n ...processMiddleware(middlewares?.afterFindOne),\n sendResponse\n );\n }\n\n // PATCH /{routeName}/:id - Update One\n if (\n !isEndpointDisabled(routerConfig, \"updateOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"update\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateOne\"\n ),\n ...processMiddleware(middlewares?.beforeUpdateOne),\n controller.updateOne,\n ...processMiddleware(middlewares?.afterUpdateOne),\n sendResponse\n );\n }\n\n // DELETE /{routeName}/:id - Delete One\n if (\n !isEndpointDisabled(routerConfig, \"deleteOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"delete\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteOne\"\n ),\n ...processMiddleware(middlewares?.beforeDeleteOne),\n controller.deleteOne,\n ...processMiddleware(middlewares?.afterDeleteOne),\n sendResponse\n );\n }\n });\n}\n\nexport function isEndpointDisabled(\n routerConfig: RouterConfig,\n endpoint: RouterEndpoint\n): boolean {\n if (!routerConfig?.disable) return false;\n\n if (routerConfig.disable === true) return true;\n\n if (typeof routerConfig.disable === \"object\")\n return routerConfig.disable[endpoint] === true;\n\n return false;\n}\n\nexport function isParentEndpointAllowed(\n routerConfig: any,\n endpoint: string\n): boolean {\n if (!routerConfig?.parent) return false;\n\n const parentEndpoints = routerConfig.parent.endpoints;\n if (parentEndpoints === \"*\") return true;\n if (Array.isArray(parentEndpoints)) return parentEndpoints.includes(endpoint);\n\n return true; // Default to allow if not specified\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catch-async.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/catch-async.ts"],"names":[],"mappings":"AAwBA,MAAM,UAAU,GACd,CAAC,EAAuB,EAAE,EAAE,CAC5B,KAAK,EACH,GAAiB,EACjB,GAAkB,EAClB,IAAuB,EACR,EAAE;IACjB,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAS,CAAC;IAC5C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"catch-async.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/catch-async.ts"],"names":[],"mappings":"AAwBA,MAAM,UAAU,GACd,CAAC,EAAuB,EAAE,EAAE,CAC5B,KAAK,EACH,GAAiB,EACjB,GAAkB,EAClB,IAAuB,EACR,EAAE;IACjB,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAS,CAAC;IAC5C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAIJ,eAAe,UAAU,CAAC","sourcesContent":["import {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n} from \"../../../types\";\n\n/**\n * Used to wrap request handlers and middleware for automatic catch async errors and throw to next to invoke the global error handler\n *\n * @param {ArkosRequestHandler} fn - an express request handler or middleware that will be called with req, res, next, with catch attached for error handling\n * @returns\n *\n * @example\n * ```typescript\n * import { ArkosRequest, ArkosResponse, ArkosNextFunction } from 'arkos'\n *\n * export const getManyPosts = catchAsync(async\n * (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n * const posts = await getSomePosts()\n * res.status(200).json({ data: posts })\n * })\n * ```\n */\nconst catchAsync =\n (fn: ArkosRequestHandler) =>\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ): Promise<void> => {\n try {\n return (await fn(req, res, next)) as void;\n } catch (err) {\n next(err);\n }\n };\n\nexport type CatchAsyncReturnType = ReturnType<typeof catchAsync>;\n\nexport default catchAsync;\n"]}
|
|
@@ -6,6 +6,8 @@ import path from "path";
|
|
|
6
6
|
import express from "express";
|
|
7
7
|
import deepmerge from "../../utils/helpers/deepmerge.helper.js";
|
|
8
8
|
import { sendResponse } from "../base/base.middlewares.js";
|
|
9
|
+
import { processMiddleware } from "../../utils/helpers/routers.helpers.js";
|
|
10
|
+
import { adjustRequestUrl } from "./utils/helpers/file-upload.helpers.js";
|
|
9
11
|
const router = Router();
|
|
10
12
|
export async function getFileUploadRouter(arkosConfig) {
|
|
11
13
|
const { fileUpload } = arkosConfig;
|
|
@@ -19,10 +21,7 @@ export async function getFileUploadRouter(arkosConfig) {
|
|
|
19
21
|
basePathname = "/" + basePathname;
|
|
20
22
|
if (!basePathname.endsWith("/"))
|
|
21
23
|
basePathname = basePathname + "/";
|
|
22
|
-
router.get(`${basePathname}*`, authService.handleAuthenticationControl("View", authConfigs.authenticationControl), authService.handleAccessControl("View", "file-upload", authConfigs.accessControl), ...(middlewares?.beforeFindFile
|
|
23
|
-
req.url = req.url.replace(basePathname, "/");
|
|
24
|
-
next();
|
|
25
|
-
}, express.static(path.resolve(process.cwd(), fileUpload?.baseUploadDir || "uploads"), deepmerge({
|
|
24
|
+
router.get(`${basePathname}*`, authService.handleAuthenticationControl("View", authConfigs.authenticationControl), authService.handleAccessControl("View", "file-upload", authConfigs.accessControl), ...processMiddleware(middlewares?.beforeFindFile), adjustRequestUrl, express.static(path.resolve(process.cwd(), fileUpload?.baseUploadDir || "uploads"), deepmerge({
|
|
26
25
|
maxAge: "1y",
|
|
27
26
|
etag: true,
|
|
28
27
|
lastModified: true,
|
|
@@ -31,21 +30,9 @@ export async function getFileUploadRouter(arkosConfig) {
|
|
|
31
30
|
index: false,
|
|
32
31
|
cacheControl: true,
|
|
33
32
|
}, fileUpload?.expressStaticOptions || {})));
|
|
34
|
-
router.post(`${basePathname}:fileType`, authService.handleAuthenticationControl("Create", authConfigs.authenticationControl), authService.handleAccessControl("Create", "file-upload", authConfigs.accessControl), middlewares?.beforeUploadFile
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
? middlewares?.afterUploadFile
|
|
38
|
-
: sendResponse, sendResponse);
|
|
39
|
-
router.patch(`${basePathname}:fileType/:fileName`, authService.handleAuthenticationControl("Update", authConfigs.authenticationControl), authService.handleAccessControl("Update", "file-upload", authConfigs.accessControl), middlewares?.beforeUpdateFile || fileUploadController.updateFile, middlewares?.beforeUpdateFile
|
|
40
|
-
? fileUploadController.updateFile
|
|
41
|
-
: middlewares?.afterUpdateFile || sendResponse, middlewares?.beforeUpdateFile && middlewares?.afterUpdateFile
|
|
42
|
-
? middlewares?.afterUpdateFile
|
|
43
|
-
: sendResponse, sendResponse);
|
|
44
|
-
router.delete(`${basePathname}:fileType/:fileName`, authService.handleAuthenticationControl("Delete", authConfigs.authenticationControl), authService.handleAccessControl("Delete", "file-upload", authConfigs.accessControl), middlewares?.beforeDeleteFile || fileUploadController.deleteFile, middlewares?.beforeDeleteFile
|
|
45
|
-
? fileUploadController.deleteFile
|
|
46
|
-
: middlewares?.afterDeleteFile || sendResponse, middlewares?.beforeDeleteFile && middlewares?.afterDeleteFile
|
|
47
|
-
? middlewares?.afterDeleteFile
|
|
48
|
-
: sendResponse, sendResponse);
|
|
33
|
+
router.post(`${basePathname}:fileType`, authService.handleAuthenticationControl("Create", authConfigs.authenticationControl), authService.handleAccessControl("Create", "file-upload", authConfigs.accessControl), ...processMiddleware(middlewares?.beforeUploadFile), fileUploadController.uploadFile, ...processMiddleware(middlewares?.afterUploadFile), sendResponse);
|
|
34
|
+
router.patch(`${basePathname}:fileType/:fileName`, authService.handleAuthenticationControl("Update", authConfigs.authenticationControl), authService.handleAccessControl("Update", "file-upload", authConfigs.accessControl), ...processMiddleware(middlewares?.beforeUpdateFile), fileUploadController.updateFile, ...processMiddleware(middlewares?.afterUpdateFile), sendResponse);
|
|
35
|
+
router.delete(`${basePathname}:fileType/:fileName`, authService.handleAuthenticationControl("Delete", authConfigs.authenticationControl), authService.handleAccessControl("Delete", "file-upload", authConfigs.accessControl), ...processMiddleware(middlewares?.beforeDeleteFile), fileUploadController.deleteFile, ...processMiddleware(middlewares?.afterDeleteFile), sendResponse);
|
|
49
36
|
return router;
|
|
50
37
|
}
|
|
51
38
|
//# sourceMappingURL=file-upload.router.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-upload.router.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,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AAG,iBAAiB,CAAC,WAAW,EAAE,eAAe,CAAC,EAClD,YAAY,CACb,CAAC;IAGF,MAAM,CAAC,KAAK,CACV,GAAG,YAAY,qBAAqB,EACpC,WAAW,CAAC,2BAA2B,CACrC,QAAQ,EACR,WAAW,CAAC,qBAAqB,CAClC,EACD,WAAW,CAAC,mBAAmB,CAC7B,QAAQ,EACR,aAAa,EACb,WAAW,CAAC,aAAa,CAC1B,EACD,GAAG,iBAAiB,CAAC,WAAW,EAAE,gBAAgB,CAAC,EACnD,oBAAoB,CAAC,UAAU,EAC/B,GAAG,iBAAiB,CAAC,WAAW,EAAE,eAAe,CAAC,EAClD,YAAY,CACb,CAAC;IAGF,MAAM,CAAC,MAAM,CACX,GAAG,YAAY,qBAAqB,EACpC,WAAW,CAAC,2BAA2B,CACrC,QAAQ,EACR,WAAW,CAAC,qBAAqB,CAClC,EACD,WAAW,CAAC,mBAAmB,CAC7B,QAAQ,EACR,aAAa,EACb,WAAW,CAAC,aAAa,CAC1B,EACD,GAAG,iBAAiB,CAAC,WAAW,EAAE,gBAAgB,CAAC,EACnD,oBAAoB,CAAC,UAAU,EAC/B,GAAG,iBAAiB,CAAC,WAAW,EAAE,eAAe,CAAC,EAClD,YAAY,CACb,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { importPrismaModelModules } from \"../../utils/helpers/models.helpers\";\nimport authService from \"../auth/auth.service\";\nimport fileUploadController from \"./file-upload.controller\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport path from \"path\";\nimport express from \"express\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthConfigs } from \"../../types/auth\";\nimport { sendResponse } from \"../base/base.middlewares\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\nimport { adjustRequestUrl } from \"./utils/helpers/file-upload.helpers\";\n\nconst router: Router = Router();\n\nexport async function getFileUploadRouter(arkosConfig: ArkosConfig) {\n const { fileUpload } = arkosConfig;\n\n const modelModules = await importPrismaModelModules(\n \"file-upload\",\n arkosConfig\n );\n let { middlewares = {} as any, authConfigs = {} as AuthConfigs } = {};\n\n if (modelModules) {\n ({ middlewares = {}, authConfigs = {} } = modelModules);\n }\n\n let basePathname = fileUpload?.baseRoute || \"/api/uploads/\";\n\n if (!basePathname.startsWith(\"/\")) basePathname = \"/\" + basePathname;\n if (!basePathname.endsWith(\"/\")) basePathname = basePathname + \"/\";\n\n // Static file serving route\n router.get(\n `${basePathname}*`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeFindFile),\n adjustRequestUrl,\n express.static(\n path.resolve(process.cwd(), fileUpload?.baseUploadDir || \"uploads\"),\n deepmerge(\n {\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: true,\n index: false,\n cacheControl: true,\n },\n fileUpload?.expressStaticOptions || {}\n )\n )\n );\n\n // POST /{basePathname}:fileType - Upload File\n router.post(\n `${basePathname}:fileType`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeUploadFile),\n fileUploadController.uploadFile,\n ...processMiddleware(middlewares?.afterUploadFile),\n sendResponse\n );\n\n // PATCH /{basePathname}:fileType/:fileName - Update File\n router.patch(\n `${basePathname}:fileType/:fileName`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeUpdateFile),\n fileUploadController.updateFile,\n ...processMiddleware(middlewares?.afterUpdateFile),\n sendResponse\n );\n\n // DELETE /{basePathname}:fileType/:fileName - Delete File\n router.delete(\n `${basePathname}:fileType/:fileName`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeDeleteFile),\n fileUploadController.deleteFile,\n ...processMiddleware(middlewares?.afterDeleteFile),\n sendResponse\n );\n\n return router;\n}\n"]}
|
|
@@ -5,6 +5,12 @@ import { promisify } from "util";
|
|
|
5
5
|
import { getArkosConfig } from "../../../../server.js";
|
|
6
6
|
import mimetype from "mimetype";
|
|
7
7
|
import { fullCleanCwd } from "../../../../utils/helpers/fs.helpers.js";
|
|
8
|
+
export function adjustRequestUrl(req, _, next) {
|
|
9
|
+
const { fileUpload } = getArkosConfig();
|
|
10
|
+
req.url = req.url.replace(fileUpload?.baseRoute + "/" || "/api/uploads/", "/");
|
|
11
|
+
req.url = req.url.replace(fileUpload?.baseRoute || "/api/uploads/", "/");
|
|
12
|
+
next();
|
|
13
|
+
}
|
|
8
14
|
export function extractRequestInfo(req) {
|
|
9
15
|
const { fileUpload } = getArkosConfig();
|
|
10
16
|
const protocol = req.headers["x-forwarded-proto"] === "https" ? "https" : "http";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-upload.helpers.js","sourceRoot":"","sources":["../../../../../../src/modules/file-upload/utils/helpers/file-upload.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,QAAQ,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"file-upload.helpers.js","sourceRoot":"","sources":["../../../../../../src/modules/file-upload/utils/helpers/file-upload.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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harp from \"sharp\";\nimport { promisify } from \"util\";\nimport { getArkosConfig } from \"../../../../server\";\nimport mimetype from \"mimetype\";\nimport {\n ArkosNextFunction,\n ArkosRequest,\n ArkosResponse,\n} from \"../../../../types\";\nimport { fullCleanCwd } from \"../../../../utils/helpers/fs.helpers\";\n\nexport function adjustRequestUrl(\n req: ArkosRequest,\n _: ArkosResponse,\n next: ArkosNextFunction\n) {\n const { fileUpload } = getArkosConfig();\n req.url = req.url.replace(\n fileUpload?.baseRoute + \"/\" || \"/api/uploads/\",\n \"/\"\n );\n req.url = req.url.replace(fileUpload?.baseRoute || \"/api/uploads/\", \"/\");\n next();\n}\n\nexport function extractRequestInfo(req: ArkosRequest) {\n const { fileUpload } = getArkosConfig();\n\n // Determine the base URL for file access\n const protocol =\n req.headers[\"x-forwarded-proto\"] === \"https\" ? \"https\" : \"http\";\n const baseURL = `${protocol}://${req.get?.(\"host\")}`;\n const baseRoute = fileUpload?.baseRoute || \"/api/uploads\";\n return { baseURL, baseRoute };\n}\n\n/**\n * Generates the correct relative path regardless of upload directory location\n */\nconst generateRelativePath = (filePath: string, fileType: string) => {\n const { fileUpload } = getArkosConfig();\n\n const baseUploadDir = fileUpload?.baseUploadDir || \"/uploads\";\n if (baseUploadDir.startsWith(\"..\")) {\n // For paths outside project directory\n return path.join(fileType, path.basename(filePath));\n } else {\n // For paths within project\n return fullCleanCwd(\n filePath\n .replace(`${baseUploadDir}/`, \"\")\n .replace(`/${baseUploadDir}/`, \"\")\n .replace(`/${baseUploadDir}`, \"\")\n .replace(`${baseUploadDir}`, \"\")\n );\n }\n};\n\n/**\n * Handles basic file processing for non-image files\n */\nexport const processFile = async (\n req: ArkosRequest,\n filePath: string\n): Promise<string> => {\n const { baseURL, baseRoute } = extractRequestInfo(req);\n\n const relativePath = generateRelativePath(filePath, req.params!.fileType);\n return `${baseURL}${baseRoute === \"/\" ? \"\" : baseRoute}/${relativePath}`;\n};\n\n/**\n * Processes image files using Sharp for resizing and format conversion\n */\nexport const processImage = async (\n req: ArkosRequest,\n filePath: string,\n options: Record<string, any>\n): Promise<string | null> => {\n const { baseURL, baseRoute } = extractRequestInfo(req);\n\n const ext = path.extname(filePath).toLowerCase();\n const originalFormat = ext.replace(\".\", \"\");\n const outputFormat = options.format || originalFormat;\n\n if (!mimetype.lookup(ext)?.includes?.(\"image\")) {\n const relativePath = generateRelativePath(filePath, req.params!.fileType);\n return `${baseURL}${baseRoute}/${relativePath}`;\n }\n\n // Create a temp filename with original name + random string\n const tempName = `${path.basename(filePath, ext)}_${Date.now()}${ext}`;\n const tempPath = path.join(path.dirname(filePath), tempName);\n\n try {\n let transformer = sharp(filePath);\n const metadata = await transformer.metadata();\n\n // Apply resize transformations if requested\n if (options.resizeTo && metadata.width && metadata.height) {\n const targetSize = options.resizeTo;\n const scaleFactor =\n targetSize / Math.min(metadata.width, metadata.height);\n const newWidth = Math.round(metadata.width * scaleFactor);\n const newHeight = Math.round(metadata.height * scaleFactor);\n transformer = transformer.resize(newWidth, newHeight);\n } else if (options.width || options.height) {\n transformer = transformer.resize(\n options.width || null,\n options.height || null,\n {\n fit: \"inside\",\n }\n );\n }\n\n // Apply format transformations if requested\n if (outputFormat === \"webp\") {\n transformer = transformer.toFormat(\"webp\");\n } else if (outputFormat === \"jpeg\" || outputFormat === \"jpg\") {\n transformer = transformer.toFormat(\"jpeg\");\n }\n\n // Save to temp file first\n await transformer.toFile(tempPath);\n\n // Rename temp file to original filename\n await promisify(fs.rename)(tempPath, filePath);\n\n // Return the public URL for the file\n const relativePath = generateRelativePath(filePath, req?.params!.fileType);\n\n return `${baseURL}${baseRoute}/${relativePath}`;\n } catch (error) {\n // Clean up temp file if it exists\n try {\n await promisify(fs.stat)(tempPath);\n await promisify(fs.unlink)(tempPath);\n } catch (err) {\n // If temp file doesn't exist, no need to clean up\n }\n throw error;\n }\n};\n"]}
|
package/dist/esm/server.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";import{bootstrap as a}from"./app.js";import p from"./utils/helpers/deepmerge.helper.js";import c from"http";import
|
|
1
|
+
"use strict";import{bootstrap as a}from"./app.js";import p from"./utils/helpers/deepmerge.helper.js";import c from"http";import{initializePrismaModels as l}from"./utils/helpers/models.helpers.js";import t from"./utils/sheu.js";process.on("uncaughtException",o=>{console.error(`
|
|
2
2
|
UNCAUGHT EXCEPTION! SHUTTING DOWN...
|
|
3
3
|
`),console.error(o.name,o.message),console.error(o),process.exit(1)});let r,s,e={welcomeMessage:"Welcome to our RESTful API generated by Arkos, find out more about Arkos at www.arkosjs.com",port:Number(process.env.CLI_PORT)||Number(process.env.PORT)||8e3,host:process.env.CLI_HOST||process.env.HOST||"localhost",fileUpload:{baseUploadDir:"uploads",baseRoute:"/api/uploads"},available:!1};async function u(o={}){l(),e.available=!0,e=p(e,o);const n=process.env.CLI_PORT||e.port||process.env.PORT||"port"in e?e.port:8e3;s=await a(e);const i=new Date().toTimeString().split(" ")[0];return n?(r=c.createServer(s),e?.configureServer&&await e.configureServer(r),r.listen(Number(n),e.host,()=>{t.ready(`${t.gray(i)} server waiting on http://${e.host||"localhost"}:${n}`)})):t.warn(`${t.gray(i)} port set to undefined, hence no internal http server was setup.`),s}process.on("unhandledRejection",o=>{console.error("UNHANDLED REJECTION! SHUTTING DOWN..."),console.error(o.name,o.message),console.error(o),r?.close(()=>{process.exit(1)})});export function terminateApplicationRunningProcessAndServer(){r?.close(()=>{process.exit(1)})}export function getArkosConfig(){return e}export function getExpressApp(){return s}export{r as server,u as initApp};
|