arkos 1.2.9-test → 1.2.10-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -14
- package/cli.js +2 -11
- package/dist/cjs/app.js +1 -1
- package/dist/cjs/app.js.map +1 -1
- package/dist/cjs/modules/auth/auth.service.js +0 -7
- package/dist/cjs/modules/auth/auth.service.js.map +1 -1
- package/dist/cjs/modules/base/base.controller.js +11 -12
- package/dist/cjs/modules/base/base.controller.js.map +1 -1
- package/dist/cjs/modules/base/base.router.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +41 -27
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/cjs/modules/swagger/swagger.router.js +14 -56
- package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +250 -0
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/get-system-json-schema-paths.js +66 -0
- package/dist/cjs/modules/swagger/utils/helpers/get-system-json-schema-paths.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +41 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +22 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js +30 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js +442 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js +165 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js +93 -0
- package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -0
- package/dist/cjs/server.js +2 -2
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/types/arkos-config.js.map +1 -1
- package/dist/cjs/utils/cli/build.js +2 -19
- package/dist/cjs/utils/cli/build.js.map +1 -1
- package/dist/cjs/utils/cli/dev.js +8 -33
- package/dist/cjs/utils/cli/dev.js.map +1 -1
- package/dist/cjs/utils/cli/generate.js +6 -6
- package/dist/cjs/utils/cli/generate.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -3
- package/dist/cjs/utils/cli/utils/cli.helpers.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js +33 -66
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +16 -10
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js +5 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js.map +1 -1
- package/dist/cjs/utils/helpers/fs.helpers.js +12 -5
- package/dist/cjs/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/global.helpers.js +69 -2
- package/dist/cjs/utils/helpers/global.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/models.helpers.js +20 -44
- package/dist/cjs/utils/helpers/models.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js +7 -4
- package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/cjs/utils/sheu.js +143 -0
- package/dist/cjs/utils/sheu.js.map +1 -0
- package/dist/esm/app.js +1 -0
- package/dist/esm/app.js.map +1 -0
- package/dist/{es2020 → esm}/exports/auth/index.js +1 -1
- package/dist/{es2020 → esm}/exports/controllers/index.js +2 -2
- package/dist/{es2020 → esm}/exports/error-handler/index.js +2 -2
- package/dist/{es2020 → esm}/exports/index.js +2 -2
- package/dist/{es2020 → esm}/exports/middlewares/index.js +1 -1
- package/dist/esm/exports/prisma/index.js +3 -0
- package/dist/{es2020 → esm}/exports/services/index.js +4 -4
- package/dist/esm/exports/utils/index.js +4 -0
- package/dist/esm/exports/validation/index.js +4 -0
- package/dist/{es2020 → esm}/modules/auth/auth.controller.js +7 -7
- package/dist/{es2020 → esm}/modules/auth/auth.router.js +6 -6
- package/dist/{es2020 → esm}/modules/auth/auth.service.js +6 -13
- package/dist/esm/modules/auth/auth.service.js.map +1 -0
- package/dist/{es2020 → esm}/modules/auth/utils/helpers/auth.controller.helpers.js +2 -2
- package/dist/{es2020 → esm}/modules/base/base.controller.js +18 -19
- package/dist/esm/modules/base/base.controller.js.map +1 -0
- package/dist/{es2020 → esm}/modules/base/base.middlewares.js +6 -6
- package/dist/{es2020 → esm}/modules/base/base.router.js +4 -4
- package/dist/esm/modules/base/base.router.js.map +1 -0
- package/dist/{es2020 → esm}/modules/base/base.service.js +6 -6
- package/dist/{es2020 → esm}/modules/base/utils/helpers/base.controller.helpers.js +1 -1
- package/dist/{es2020 → esm}/modules/base/utils/helpers/base.middlewares.helpers.js +1 -1
- package/dist/{es2020 → esm}/modules/base/utils/helpers/base.router.helpers.js +45 -33
- package/dist/esm/modules/base/utils/helpers/base.router.helpers.js.map +1 -0
- package/dist/{es2020 → esm}/modules/base/utils/helpers/base.service.helpers.js +1 -1
- package/dist/{es2020 → esm}/modules/email/email.service.js +2 -2
- package/dist/{es2020 → esm}/modules/error-handler/error-handler.controller.js +3 -3
- package/dist/{es2020 → esm}/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/{es2020 → esm}/modules/error-handler/utils/error-handler.helpers.js +1 -1
- package/dist/{es2020 → esm}/modules/file-upload/file-upload.controller.js +7 -7
- package/dist/{es2020 → esm}/modules/file-upload/file-upload.router.js +5 -5
- package/dist/{es2020 → esm}/modules/file-upload/file-upload.service.js +5 -5
- package/dist/{es2020 → esm}/modules/file-upload/utils/helpers/file-upload.helpers.js +2 -2
- package/dist/{es2020 → esm}/modules/swagger/swagger.router.js +15 -57
- package/dist/esm/modules/swagger/swagger.router.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +247 -0
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/get-system-json-schema-paths.js +63 -0
- package/dist/esm/modules/swagger/utils/helpers/get-system-json-schema-paths.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +38 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +19 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js +24 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js +436 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js +159 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js +83 -0
- package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -0
- package/dist/esm/server.js +3 -0
- package/dist/esm/server.js.map +1 -0
- package/dist/esm/types/arkos-config.js.map +1 -0
- package/dist/{es2020 → esm}/utils/cli/build.js +4 -21
- package/dist/esm/utils/cli/build.js.map +1 -0
- package/dist/{es2020 → esm}/utils/cli/dev.js +12 -37
- package/dist/esm/utils/cli/dev.js.map +1 -0
- package/dist/{es2020 → esm}/utils/cli/generate.js +10 -10
- package/dist/{es2020 → esm}/utils/cli/generate.js.map +1 -1
- package/dist/{es2020 → esm}/utils/cli/index.js +5 -5
- package/dist/{es2020 → esm}/utils/cli/start.js +4 -4
- package/dist/esm/utils/cli/utils/cli.helpers.js +16 -0
- package/dist/esm/utils/cli/utils/cli.helpers.js.map +1 -0
- package/dist/{es2020 → esm}/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js +1 -1
- package/dist/{es2020 → esm}/utils/cli/utils/template-generator/templates/generate-middlewares.js +34 -67
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +1 -0
- package/dist/{es2020 → esm}/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +18 -12
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +1 -0
- package/dist/{es2020 → esm}/utils/cli/utils/template-generator/templates/generate-router-template.js +6 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-router-template.js.map +1 -0
- package/dist/{es2020 → esm}/utils/cli/utils/template-generator/templates/generate-service-template.js +2 -2
- package/dist/{es2020 → esm}/utils/cli/utils/template-generators.js +6 -6
- package/dist/{es2020 → esm}/utils/features/api.features.js +4 -4
- package/dist/{es2020 → esm}/utils/features/change-case.features.js +1 -1
- package/dist/{es2020 → esm}/utils/helpers/fs.helpers.js +12 -5
- package/dist/esm/utils/helpers/fs.helpers.js.map +1 -0
- package/dist/esm/utils/helpers/global.helpers.js +65 -0
- package/dist/esm/utils/helpers/global.helpers.js.map +1 -0
- package/dist/{es2020 → esm}/utils/helpers/models.helpers.js +21 -12
- package/dist/esm/utils/helpers/models.helpers.js.map +1 -0
- package/dist/{es2020 → esm}/utils/helpers/prisma.helpers.js +11 -8
- package/dist/esm/utils/helpers/prisma.helpers.js.map +1 -0
- package/dist/esm/utils/sheu.js +141 -0
- package/dist/esm/utils/sheu.js.map +1 -0
- package/dist/{es2020 → esm}/utils/validate-dto.js +1 -1
- package/dist/{es2020 → esm}/utils/validate-schema.js +1 -1
- package/dist/types/modules/auth/auth.controller.d.ts +7 -7
- package/dist/types/modules/auth/auth.service.d.ts +1 -1
- package/dist/types/modules/base/base.controller.d.ts +9 -9
- package/dist/types/modules/base/utils/helpers/base.router.helpers.d.ts +4 -1
- package/dist/types/modules/error-handler/utils/catch-async.d.ts +1 -1
- package/dist/types/modules/file-upload/file-upload.controller.d.ts +4 -4
- package/dist/types/modules/swagger/swagger.router.d.ts +1 -1
- package/dist/types/modules/swagger/utils/helpers/get-authentication-json-schema-paths.d.ts +2 -0
- package/dist/types/modules/swagger/utils/helpers/get-system-json-schema-paths.d.ts +2 -0
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.d.ts +1 -0
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.d.ts +1 -0
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.d.ts +1 -0
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.d.ts +2 -0
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.d.ts +2 -0
- package/dist/types/modules/swagger/utils/helpers/swagger.router.helpers.d.ts +7 -0
- package/dist/types/types/arkos-config.d.ts +7 -4
- package/dist/types/utils/cli/utils/cli.helpers.d.ts +1 -1
- package/dist/types/utils/helpers/global.helpers.d.ts +6 -1
- package/dist/types/utils/helpers/models.helpers.d.ts +10 -1
- package/dist/types/utils/helpers/prisma.helpers.d.ts +1 -1
- package/dist/types/utils/sheu.d.ts +25 -0
- package/package.json +23 -29
- package/dist/es2020/app.js +0 -1
- package/dist/es2020/app.js.map +0 -1
- package/dist/es2020/exports/prisma/index.js +0 -3
- package/dist/es2020/exports/utils/index.js +0 -4
- package/dist/es2020/exports/validation/index.js +0 -4
- package/dist/es2020/modules/auth/auth.service.js.map +0 -1
- package/dist/es2020/modules/base/base.controller.js.map +0 -1
- package/dist/es2020/modules/base/base.router.js.map +0 -1
- package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js.map +0 -1
- package/dist/es2020/modules/swagger/swagger.router.js.map +0 -1
- package/dist/es2020/server.js +0 -3
- package/dist/es2020/server.js.map +0 -1
- package/dist/es2020/types/arkos-config.js.map +0 -1
- package/dist/es2020/utils/cli/build.js.map +0 -1
- package/dist/es2020/utils/cli/dev.js.map +0 -1
- package/dist/es2020/utils/cli/utils/cli.helpers.js +0 -18
- package/dist/es2020/utils/cli/utils/cli.helpers.js.map +0 -1
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +0 -1
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +0 -1
- package/dist/es2020/utils/cli/utils/template-generator/templates/generate-router-template.js.map +0 -1
- package/dist/es2020/utils/helpers/fs.helpers.js.map +0 -1
- package/dist/es2020/utils/helpers/global.helpers.js +0 -4
- package/dist/es2020/utils/helpers/global.helpers.js.map +0 -1
- package/dist/es2020/utils/helpers/models.helpers.js.map +0 -1
- package/dist/es2020/utils/helpers/prisma.helpers.js.map +0 -1
- /package/dist/{es2020 → esm}/exports/auth/index.js.map +0 -0
- /package/dist/{es2020 → esm}/exports/controllers/index.js.map +0 -0
- /package/dist/{es2020 → esm}/exports/error-handler/index.js.map +0 -0
- /package/dist/{es2020 → esm}/exports/index.js.map +0 -0
- /package/dist/{es2020 → esm}/exports/middlewares/index.js.map +0 -0
- /package/dist/{es2020 → esm}/exports/prisma/index.js.map +0 -0
- /package/dist/{es2020 → esm}/exports/services/index.js.map +0 -0
- /package/dist/{es2020 → esm}/exports/utils/index.js.map +0 -0
- /package/dist/{es2020 → esm}/exports/validation/index.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/auth/auth.controller.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/auth/auth.router.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/auth/utils/helpers/auth.controller.helpers.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/base/base.middlewares.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/base/base.service.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/base/utils/helpers/base.controller.helpers.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/base/utils/helpers/base.middlewares.helpers.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/base/utils/helpers/base.service.helpers.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/email/email.service.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/error-handler/utils/app-error.js +0 -0
- /package/dist/{es2020 → esm}/modules/error-handler/utils/app-error.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/error-handler/utils/catch-async.js +0 -0
- /package/dist/{es2020 → esm}/modules/error-handler/utils/catch-async.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/error-handler/utils/error-handler.helpers.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/file-upload/file-upload.controller.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/file-upload/file-upload.router.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/file-upload/file-upload.service.js.map +0 -0
- /package/dist/{es2020 → esm}/modules/file-upload/utils/helpers/file-upload.helpers.js.map +0 -0
- /package/dist/{es2020 → esm}/paths.js +0 -0
- /package/dist/{es2020 → esm}/paths.js.map +0 -0
- /package/dist/{es2020 → esm}/types/arkos-config.js +0 -0
- /package/dist/{es2020 → esm}/types/auth.js +0 -0
- /package/dist/{es2020 → esm}/types/auth.js.map +0 -0
- /package/dist/{es2020 → esm}/types/index.js +0 -0
- /package/dist/{es2020 → esm}/types/index.js.map +0 -0
- /package/dist/{es2020 → esm}/types/router-config.js +0 -0
- /package/dist/{es2020 → esm}/types/router-config.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/arkos-env.js +0 -0
- /package/dist/{es2020 → esm}/utils/arkos-env.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/cli/index.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/cli/start.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/cli/utils/template-generator/templates/generate-controller-template.js +0 -0
- /package/dist/{es2020 → esm}/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/cli/utils/template-generator/templates/generate-service-template.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/cli/utils/template-generators.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/dotenv.helpers.js +0 -0
- /package/dist/{es2020 → esm}/utils/dotenv.helpers.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/features/api.features.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/features/change-case.features.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/helpers/api.features.helpers.js +0 -0
- /package/dist/{es2020 → esm}/utils/helpers/api.features.helpers.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/helpers/change-case.helpers.js +0 -0
- /package/dist/{es2020 → esm}/utils/helpers/change-case.helpers.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/helpers/deepmerge.helper.js +0 -0
- /package/dist/{es2020 → esm}/utils/helpers/deepmerge.helper.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/helpers/query-parser.helpers.js +0 -0
- /package/dist/{es2020 → esm}/utils/helpers/query-parser.helpers.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/helpers/text.helpers.js +0 -0
- /package/dist/{es2020 → esm}/utils/helpers/text.helpers.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/validate-dto.js.map +0 -0
- /package/dist/{es2020 → esm}/utils/validate-schema.js.map +0 -0
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { kebabCase } from "../../../../exports/utils";
|
|
3
|
-
import { importPrismaModelModules } from "../../../../utils/helpers/models.helpers";
|
|
4
|
-
import authService from "../../../auth/auth.service";
|
|
5
|
-
import { BaseController } from "../../base.controller";
|
|
6
|
-
import { addPrismaQueryOptionsToRequest, handleRequestBodyValidationAndTransformation, sendResponse, } from "../../base.middlewares";
|
|
7
|
-
import catchAsync from "../../../error-handler/utils/catch-async";
|
|
1
|
+
import pluralize from "pluralize";
|
|
2
|
+
import { kebabCase } from "../../../../exports/utils/index.js";
|
|
3
|
+
import { importPrismaModelModules } from "../../../../utils/helpers/models.helpers.js";
|
|
4
|
+
import authService from "../../../auth/auth.service.js";
|
|
5
|
+
import { BaseController } from "../../base.controller.js";
|
|
6
|
+
import { addPrismaQueryOptionsToRequest, handleRequestBodyValidationAndTransformation, sendResponse, } from "../../base.middlewares.js";
|
|
7
|
+
import catchAsync from "../../../error-handler/utils/catch-async.js";
|
|
8
8
|
export function setupRouters(models, router, arkosConfigs) {
|
|
9
9
|
return models.map(async (model) => {
|
|
10
10
|
const modelNameInKebab = kebabCase(model);
|
|
11
11
|
const modelModules = await importPrismaModelModules(modelNameInKebab);
|
|
12
12
|
const { middlewares, authConfigs, prismaQueryOptions, router: customRouterModule, dtos, schemas, } = modelModules;
|
|
13
|
-
const routeName = plural(modelNameInKebab);
|
|
13
|
+
const routeName = pluralize.plural(modelNameInKebab);
|
|
14
14
|
const controller = new BaseController(model);
|
|
15
|
-
const routerConfig = customRouterModule?.config;
|
|
16
|
-
const disableConfig = routerConfig?.disable || {};
|
|
17
|
-
const isCompletelyDisabled = disableConfig === true;
|
|
15
|
+
const routerConfig = customRouterModule?.config || {};
|
|
18
16
|
const customRouter = customRouterModule || {};
|
|
19
17
|
const hasCustomImplementation = (path, method) => {
|
|
20
18
|
return customRouter.stack?.some((layer) => (layer.path === `/api/${path}` ||
|
|
@@ -23,11 +21,6 @@ export function setupRouters(models, router, arkosConfigs) {
|
|
|
23
21
|
layer.path === `/api/${path}/`) &&
|
|
24
22
|
layer.method.toLowerCase() === method.toLowerCase());
|
|
25
23
|
};
|
|
26
|
-
const isEndpointDisabled = (endpoint) => {
|
|
27
|
-
if (isCompletelyDisabled)
|
|
28
|
-
return true;
|
|
29
|
-
return typeof disableConfig === "object" && !!disableConfig[endpoint];
|
|
30
|
-
};
|
|
31
24
|
const getValidationSchemaOrDto = (key) => {
|
|
32
25
|
const validationConfigs = arkosConfigs?.validation;
|
|
33
26
|
if (validationConfigs?.resolver === "class-validator") {
|
|
@@ -38,14 +31,14 @@ export function setupRouters(models, router, arkosConfigs) {
|
|
|
38
31
|
}
|
|
39
32
|
return undefined;
|
|
40
33
|
};
|
|
41
|
-
if (customRouterModule?.default && !
|
|
34
|
+
if (customRouterModule?.default && !routerConfig?.disable)
|
|
42
35
|
router.use(`/${routeName}`, customRouterModule.default);
|
|
43
36
|
function safeCatchAsync(middleware) {
|
|
44
37
|
return middleware ? catchAsync(middleware) : undefined;
|
|
45
38
|
}
|
|
46
|
-
if (!isEndpointDisabled("createOne") &&
|
|
39
|
+
if (!isEndpointDisabled(routerConfig, "createOne") &&
|
|
47
40
|
!hasCustomImplementation(`/${routeName}`, "post")) {
|
|
48
|
-
router.post(`/${routeName}`, authService.handleAuthenticationControl("Create", authConfigs?.authenticationControl), authService.handleAccessControl("Create", kebabCase(singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("create")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "createOne"), ...[
|
|
41
|
+
router.post(`/${routeName}`, authService.handleAuthenticationControl("Create", authConfigs?.authenticationControl), authService.handleAccessControl("Create", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("create")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "createOne"), ...[
|
|
49
42
|
safeCatchAsync(middlewares?.beforeCreateOne) || controller.createOne,
|
|
50
43
|
safeCatchAsync(middlewares?.beforeCreateOne)
|
|
51
44
|
? controller.createOne
|
|
@@ -56,9 +49,9 @@ export function setupRouters(models, router, arkosConfigs) {
|
|
|
56
49
|
: sendResponse,
|
|
57
50
|
].filter((m) => !!m), sendResponse);
|
|
58
51
|
}
|
|
59
|
-
if (!isEndpointDisabled("findMany") &&
|
|
52
|
+
if (!isEndpointDisabled(routerConfig, "findMany") &&
|
|
60
53
|
!hasCustomImplementation(`/${routeName}`, "get")) {
|
|
61
|
-
router.get(`/${routeName}`, authService.handleAuthenticationControl("View", authConfigs?.authenticationControl), authService.handleAccessControl("View", kebabCase(singular(modelNameInKebab)), authConfigs?.accessControl || {}), addPrismaQueryOptionsToRequest(prismaQueryOptions, "findMany"), ...[
|
|
54
|
+
router.get(`/${routeName}`, authService.handleAuthenticationControl("View", authConfigs?.authenticationControl), authService.handleAccessControl("View", kebabCase(pluralize.singular(modelNameInKebab)), authConfigs?.accessControl || {}), addPrismaQueryOptionsToRequest(prismaQueryOptions, "findMany"), ...[
|
|
62
55
|
safeCatchAsync(middlewares?.beforeFindMany) || controller.findMany,
|
|
63
56
|
safeCatchAsync(middlewares?.beforeFindMany)
|
|
64
57
|
? controller.findMany
|
|
@@ -70,9 +63,9 @@ export function setupRouters(models, router, arkosConfigs) {
|
|
|
70
63
|
sendResponse,
|
|
71
64
|
].filter((m) => !!m));
|
|
72
65
|
}
|
|
73
|
-
if (!isEndpointDisabled("createMany") &&
|
|
66
|
+
if (!isEndpointDisabled(routerConfig, "createMany") &&
|
|
74
67
|
!hasCustomImplementation(`/${routeName}/many`, "post")) {
|
|
75
|
-
router.post(`/${routeName}/many`, authService.handleAuthenticationControl("Create", authConfigs?.authenticationControl), authService.handleAccessControl("Create", kebabCase(singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("createMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "createMany"), ...[
|
|
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"), ...[
|
|
76
69
|
safeCatchAsync(middlewares?.beforeCreateMany) ||
|
|
77
70
|
controller.createMany,
|
|
78
71
|
safeCatchAsync(middlewares?.beforeCreateMany)
|
|
@@ -85,9 +78,9 @@ export function setupRouters(models, router, arkosConfigs) {
|
|
|
85
78
|
sendResponse,
|
|
86
79
|
].filter((m) => !!m));
|
|
87
80
|
}
|
|
88
|
-
if (!isEndpointDisabled("updateMany") &&
|
|
81
|
+
if (!isEndpointDisabled(routerConfig, "updateMany") &&
|
|
89
82
|
!hasCustomImplementation(`/${routeName}/many`, "patch")) {
|
|
90
|
-
router.patch(`/${routeName}/many`, authService.handleAuthenticationControl("Update", authConfigs?.authenticationControl), authService.handleAccessControl("Update", kebabCase(singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("updateMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateMany"), ...[
|
|
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"), ...[
|
|
91
84
|
safeCatchAsync(middlewares?.beforeUpdateMany) ||
|
|
92
85
|
controller.updateMany,
|
|
93
86
|
safeCatchAsync(middlewares?.beforeUpdateMany)
|
|
@@ -100,9 +93,9 @@ export function setupRouters(models, router, arkosConfigs) {
|
|
|
100
93
|
sendResponse,
|
|
101
94
|
].filter((m) => !!m));
|
|
102
95
|
}
|
|
103
|
-
if (!isEndpointDisabled("deleteMany") &&
|
|
96
|
+
if (!isEndpointDisabled(routerConfig, "deleteMany") &&
|
|
104
97
|
!hasCustomImplementation(`/${routeName}/many`, "delete")) {
|
|
105
|
-
router.delete(`/${routeName}/many`, authService.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), authService.handleAccessControl("Delete", kebabCase(singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("deleteMany")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteMany"), ...[
|
|
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"), ...[
|
|
106
99
|
safeCatchAsync(middlewares?.beforeDeleteMany) ||
|
|
107
100
|
controller.deleteMany,
|
|
108
101
|
safeCatchAsync(middlewares?.beforeDeleteMany)
|
|
@@ -115,9 +108,9 @@ export function setupRouters(models, router, arkosConfigs) {
|
|
|
115
108
|
sendResponse,
|
|
116
109
|
].filter((middleware) => !!middleware));
|
|
117
110
|
}
|
|
118
|
-
if (!isEndpointDisabled("findOne") &&
|
|
111
|
+
if (!isEndpointDisabled(routerConfig, "findOne") &&
|
|
119
112
|
!hasCustomImplementation(`/${routeName}/:id`, "get")) {
|
|
120
|
-
router.get(`/${routeName}/:id`, authService.handleAuthenticationControl("View", authConfigs?.authenticationControl), authService.handleAccessControl("View", kebabCase(singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("findOne")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "findOne"), ...[
|
|
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"), ...[
|
|
121
114
|
safeCatchAsync(middlewares?.beforeFindOne) || controller.findOne,
|
|
122
115
|
safeCatchAsync(middlewares?.beforeFindOne)
|
|
123
116
|
? controller.findOne
|
|
@@ -129,9 +122,9 @@ export function setupRouters(models, router, arkosConfigs) {
|
|
|
129
122
|
sendResponse,
|
|
130
123
|
].filter((m) => !!m));
|
|
131
124
|
}
|
|
132
|
-
if (!isEndpointDisabled("updateOne") &&
|
|
125
|
+
if (!isEndpointDisabled(routerConfig, "updateOne") &&
|
|
133
126
|
!hasCustomImplementation(`/${routeName}/:id`, "patch")) {
|
|
134
|
-
router.patch(`/${routeName}/:id`, authService.handleAuthenticationControl("Update", authConfigs?.authenticationControl), authService.handleAccessControl("Update", kebabCase(singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("update")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "updateOne"), ...[
|
|
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"), ...[
|
|
135
128
|
safeCatchAsync(middlewares?.beforeUpdateOne) || controller.updateOne,
|
|
136
129
|
safeCatchAsync(middlewares?.beforeUpdateOne)
|
|
137
130
|
? controller.updateOne
|
|
@@ -142,9 +135,9 @@ export function setupRouters(models, router, arkosConfigs) {
|
|
|
142
135
|
: sendResponse,
|
|
143
136
|
].filter((m) => !!m), sendResponse);
|
|
144
137
|
}
|
|
145
|
-
if (!isEndpointDisabled("deleteOne") &&
|
|
138
|
+
if (!isEndpointDisabled(routerConfig, "deleteOne") &&
|
|
146
139
|
!hasCustomImplementation(`/${routeName}/:id`, "delete")) {
|
|
147
|
-
router.delete(`/${routeName}/:id`, authService.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), authService.handleAccessControl("Delete", kebabCase(singular(modelNameInKebab)), authConfigs?.accessControl || {}), handleRequestBodyValidationAndTransformation(getValidationSchemaOrDto("delete")), addPrismaQueryOptionsToRequest(prismaQueryOptions, "deleteOne"), ...[
|
|
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"), ...[
|
|
148
141
|
safeCatchAsync(middlewares?.beforeDeleteOne) || controller.deleteOne,
|
|
149
142
|
safeCatchAsync(middlewares?.beforeDeleteOne)
|
|
150
143
|
? controller.deleteOne
|
|
@@ -158,4 +151,23 @@ export function setupRouters(models, router, arkosConfigs) {
|
|
|
158
151
|
}
|
|
159
152
|
});
|
|
160
153
|
}
|
|
154
|
+
export function isEndpointDisabled(routerConfig, endpoint) {
|
|
155
|
+
if (!routerConfig?.disable)
|
|
156
|
+
return false;
|
|
157
|
+
if (routerConfig.disable === true)
|
|
158
|
+
return true;
|
|
159
|
+
if (typeof routerConfig.disable === "object")
|
|
160
|
+
return routerConfig.disable[endpoint] === true;
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
export function isParentEndpointAllowed(routerConfig, endpoint) {
|
|
164
|
+
if (!routerConfig?.parent)
|
|
165
|
+
return false;
|
|
166
|
+
const parentEndpoints = routerConfig.parent.endpoints;
|
|
167
|
+
if (parentEndpoints === "*")
|
|
168
|
+
return true;
|
|
169
|
+
if (Array.isArray(parentEndpoints))
|
|
170
|
+
return parentEndpoints.includes(endpoint);
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
161
173
|
//# sourceMappingURL=base.router.helpers.js.map
|
|
@@ -0,0 +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,CAAC,gBAAgB,CAAC,CAAC;QACtE,MAAM,EACJ,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,MAAM,EAAE,kBAAkB,EAC1B,IAAI,EACJ,OAAO,GACR,GAAG,YAAY,CAAC;QAEjB,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACrD,MAAM,UAAU,GAAG,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC;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IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;QAAE,OAAO,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE9E,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { Router } from \"express\";\nimport pluralize from \"pluralize\";\nimport { ArkosConfig, RouterConfig } from \"../../../../exports\";\nimport { kebabCase } from \"../../../../exports/utils\";\nimport { PrismaQueryOptions } from \"../../../../types\";\nimport { RouterEndpoint } from \"../../../../types/router-config\";\nimport { importPrismaModelModules } from \"../../../../utils/helpers/models.helpers\";\nimport authService from \"../../../auth/auth.service\";\nimport { BaseController } from \"../../base.controller\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../../base.middlewares\";\nimport catchAsync from \"../../../error-handler/utils/catch-async\";\n\nexport function setupRouters(\n models: string[],\n router: Router,\n arkosConfigs: ArkosConfig\n) {\n return models.map(async (model) => {\n const modelNameInKebab = kebabCase(model);\n const modelModules = await importPrismaModelModules(modelNameInKebab);\n const {\n middlewares,\n authConfigs,\n prismaQueryOptions,\n router: customRouterModule,\n dtos,\n schemas,\n } = modelModules;\n\n const routeName = pluralize.plural(modelNameInKebab);\n const controller = new BaseController(model);\n\n const routerConfig: RouterConfig = customRouterModule?.config || {};\n\n // Check if custom implementation exists\n const customRouter = (customRouterModule as Router) || {};\n const hasCustomImplementation = (path: string, method: string) => {\n return customRouter.stack?.some(\n (layer) =>\n (layer.path === `/api/${path}` ||\n layer.path === `api/${path}` ||\n layer.path === `api/${path}/` ||\n layer.path === `/api/${path}/`) &&\n layer.method.toLowerCase() === method.toLowerCase()\n );\n };\n\n // Helper to get the correct schema or DTO based on Arkos Config\n const getValidationSchemaOrDto = (\n key: keyof typeof dtos | keyof typeof schemas\n ) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n // If the custom router has its own routes, add them\n if (customRouterModule?.default && !routerConfig?.disable)\n router.use(`/${routeName}`, customRouterModule.default);\n\n function safeCatchAsync(middleware: any) {\n return middleware ? catchAsync(middleware) : undefined;\n }\n\n // POST /{routeName} - Create One\n if (\n !isEndpointDisabled(routerConfig, \"createOne\") &&\n !hasCustomImplementation(`/${routeName}`, \"post\")\n ) {\n router.post(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"create\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeCreateOne) || controller.createOne,\n safeCatchAsync(middlewares?.beforeCreateOne)\n ? controller.createOne\n : safeCatchAsync(middlewares?.afterCreateOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeCreateOne) &&\n safeCatchAsync(middlewares?.afterCreateOne)\n ? safeCatchAsync(middlewares?.afterCreateOne)\n : sendResponse,\n ].filter((m) => !!m),\n sendResponse\n );\n }\n\n // GET /{routeName} - Find Many\n if (\n !isEndpointDisabled(routerConfig, \"findMany\") &&\n !hasCustomImplementation(`/${routeName}`, \"get\")\n ) {\n router.get(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeFindMany) || controller.findMany,\n safeCatchAsync(middlewares?.beforeFindMany)\n ? controller.findMany\n : safeCatchAsync(middlewares?.afterFindMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeFindMany) &&\n safeCatchAsync(middlewares?.afterFindMany)\n ? safeCatchAsync(middlewares?.afterFindMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // POST /{routeName}/many - Create Many\n if (\n !isEndpointDisabled(routerConfig, \"createMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"post\")\n ) {\n router.post(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"createMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeCreateMany) ||\n controller.createMany,\n safeCatchAsync(middlewares?.beforeCreateMany)\n ? controller.createMany\n : safeCatchAsync(middlewares?.afterCreateMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeCreateMany) &&\n safeCatchAsync(middlewares?.afterCreateMany)\n ? safeCatchAsync(middlewares?.afterCreateMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // PATCH /{routeName}/many - Update Many\n if (\n !isEndpointDisabled(routerConfig, \"updateMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdateMany) ||\n controller.updateMany,\n safeCatchAsync(middlewares?.beforeUpdateMany)\n ? controller.updateMany\n : safeCatchAsync(middlewares?.afterUpdateMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdateMany) &&\n safeCatchAsync(middlewares?.afterUpdateMany)\n ? safeCatchAsync(middlewares?.afterUpdateMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // DELETE /{routeName}/many - Delete Many\n if (\n !isEndpointDisabled(routerConfig, \"deleteMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"deleteMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeDeleteMany) ||\n controller.deleteMany,\n safeCatchAsync(middlewares?.beforeDeleteMany)\n ? controller.deleteMany\n : safeCatchAsync(middlewares?.afterDeleteMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeDeleteMany) &&\n safeCatchAsync(middlewares?.afterDeleteMany)\n ? safeCatchAsync(middlewares?.afterDeleteMany)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n }\n\n // GET /{routeName}/:id - Find One\n if (\n !isEndpointDisabled(routerConfig, \"findOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"get\")\n ) {\n router.get(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"findOne\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeFindOne) || controller.findOne,\n safeCatchAsync(middlewares?.beforeFindOne)\n ? controller.findOne\n : safeCatchAsync(middlewares?.afterFindOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeFindOne) &&\n safeCatchAsync(middlewares?.afterFindOne)\n ? safeCatchAsync(middlewares?.afterFindOne)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // PATCH /{routeName}/:id - Update One\n if (\n !isEndpointDisabled(routerConfig, \"updateOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"update\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdateOne) || controller.updateOne,\n safeCatchAsync(middlewares?.beforeUpdateOne)\n ? controller.updateOne\n : safeCatchAsync(middlewares?.afterUpdateOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdateOne) &&\n safeCatchAsync(middlewares?.afterUpdateOne)\n ? safeCatchAsync(middlewares?.afterUpdateOne)\n : sendResponse,\n ].filter((m) => !!m),\n sendResponse\n );\n }\n\n // DELETE /{routeName}/:id - Delete One\n if (\n !isEndpointDisabled(routerConfig, \"deleteOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"delete\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeDeleteOne) || controller.deleteOne,\n safeCatchAsync(middlewares?.beforeDeleteOne)\n ? controller.deleteOne\n : safeCatchAsync(middlewares?.afterDeleteOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeDeleteOne) &&\n safeCatchAsync(middlewares?.afterDeleteOne)\n ? safeCatchAsync(middlewares?.afterDeleteOne)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n });\n}\n\nexport function isEndpointDisabled(\n routerConfig: RouterConfig,\n endpoint: RouterEndpoint\n): boolean {\n if (!routerConfig?.disable) return false;\n\n if (routerConfig.disable === true) return true;\n\n if (typeof routerConfig.disable === \"object\")\n return routerConfig.disable[endpoint] === true;\n\n return false;\n}\n\nexport function isParentEndpointAllowed(\n routerConfig: any,\n endpoint: string\n): boolean {\n if (!routerConfig?.parent) return false;\n\n const parentEndpoints = routerConfig.parent.endpoints;\n if (parentEndpoints === \"*\") return true;\n if (Array.isArray(parentEndpoints)) return parentEndpoints.includes(endpoint);\n\n return true; // Default to allow if not specified\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getPrismaModelRelations, getModelUniqueFields, } from "../../../../utils/helpers/models.helpers";
|
|
1
|
+
import { getPrismaModelRelations, getModelUniqueFields, } from "../../../../utils/helpers/models.helpers.js";
|
|
2
2
|
export function removeApiAction(obj) {
|
|
3
3
|
if (!obj || typeof obj !== "object")
|
|
4
4
|
return obj;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import nodemailer from "nodemailer";
|
|
2
2
|
import { convert } from "html-to-text";
|
|
3
|
-
import { getArkosConfig } from "../../server";
|
|
4
|
-
import AppError from "../error-handler/utils/app-error";
|
|
3
|
+
import { getArkosConfig } from "../../server.js";
|
|
4
|
+
import AppError from "../error-handler/utils/app-error.js";
|
|
5
5
|
export class EmailService {
|
|
6
6
|
constructor(config) {
|
|
7
7
|
this.transporter = null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import AppError from "./utils/app-error";
|
|
2
|
-
import * as errorControllerHelper from "./utils/error-handler.helpers";
|
|
3
|
-
import { server } from "../../server";
|
|
1
|
+
import AppError from "./utils/app-error.js";
|
|
2
|
+
import * as errorControllerHelper from "./utils/error-handler.helpers.js";
|
|
3
|
+
import { server } from "../../server.js";
|
|
4
4
|
export default function errorHandler(err, req, res, next) {
|
|
5
5
|
console.error("[\x1b[31mERROR\x1b[0m]:", err);
|
|
6
6
|
err.statusCode = err.statusCode || 500;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,qBAAqB,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;IACvC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC;IAGnC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACpC,OAAO;IACT,CAAC;IAGD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zB,IACE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,EAClC,CAAC;QACD,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAE3E,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} next - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n next: NextFunction\n): void {\n console.error(\"[\\x1b[31mERROR\\x1b[0m]:\", err);\n // Default error status\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n // If the environment is not production, send detailed error information\n if (process.env.NODE_ENV !== \"production\") {\n sendDevelopmentError(err, req, res);\n return;\n }\n\n // Prepare error object for response, copying the original error's properties\n let error = { ...err, message: err.message };\n\n // Handle specific error cases (JWT errors, Prisma validation errors, etc.)\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n // Handle specific Prisma client validation errors\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n\n // Handle Prisma database-specific error codes (P1000 to P3005)\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n // Handle general error types (e.g., syntax errors, type errors, etc.)\n // if (err.name === \"SyntaxError\")\n // error = errorControllerHelper.handleSchemaSyntaxError(err);\n // if (err.name === \"TypeError\")\n // error = errorControllerHelper.handleClientTypeError(err);\n // if (err.name === \"BinaryError\")\n // error = errorControllerHelper.handleBinaryError(err);\n if (err.name === \"NetworkError\")\n error = errorControllerHelper.handleNetworkError(err);\n // if (err.name === \"UnhandledPromiseRejection\")\n // error = errorControllerHelper.handleUnhandledPromiseError(err);\n if (!error.isOperational) error = new AppError(\"Something went wrong!\", 500);\n\n // Send the error response for production environment\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(\n err: AppError,\n req: Request,\n res: Response\n): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n ...err,\n message: err.message.split(\"\\n\")[err.message.split(\"\\n\").length - 1],\n stack: err.stack?.split(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Something went wrong!\",\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: \"Please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (\n process.env.NODE_ENV !== \"production\" &&\n process.env.NODE_ENV !== \"staging\"\n ) {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n process.exit();\n });\n }\n});\n"]}
|
|
1
|
+
{"version":3,"file":"error-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IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,SAAS;aAC5B,CAAC,CAAC;;YAEH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,uBAAuB;aACjC,CAAC,CAAC;QAEL,OAAO;IACT,CAAC;IAED,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;QACtB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;YAC9B,KAAK,EAAE,uBAAuB;YAC9B,OAAO,EAAE,GAAG,CAAC,OAAO;SACrB,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QAC9B,KAAK,EAAE,uBAAuB;QAC9B,OAAO,EAAE,yBAAyB;KACnC,CAAC,CAAC;AACL,CAAC;AAWD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACzB,IACE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,EAClC,CAAC;QACD,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAE3E,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} next - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n next: NextFunction\n): void {\n console.error(\"[\\x1b[31mERROR\\x1b[0m]:\", err);\n // Default error status\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n // If the environment is not production, send detailed error information\n if (process.env.NODE_ENV !== \"production\") {\n sendDevelopmentError(err, req, res);\n return;\n }\n\n // Prepare error object for response, copying the original error's properties\n let error = { ...err, message: err.message };\n\n // Handle specific error cases (JWT errors, Prisma validation errors, etc.)\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n // Handle specific Prisma client validation errors\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n\n // Handle Prisma database-specific error codes (P1000 to P3005)\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n if (err.name === \"NetworkError\")\n error = errorControllerHelper.handleNetworkError(err);\n if (!error.isOperational) error = new AppError(\"Something went wrong!\", 500);\n\n // Send the error response for production environment\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(\n err: AppError,\n req: Request,\n res: Response\n): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n ...err,\n message: err.message.split(\"\\n\")[err.message.split(\"\\n\").length - 1],\n stack: err.stack?.split(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Something went wrong!\",\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: \"Please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (\n process.env.NODE_ENV !== \"production\" &&\n process.env.NODE_ENV !== \"staging\"\n ) {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n process.exit();\n });\n }\n});\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import AppError from "../error-handler/utils/app-error";
|
|
2
|
-
import { getFileUploadServices, } from "./file-upload.service";
|
|
1
|
+
import AppError from "../error-handler/utils/app-error.js";
|
|
2
|
+
import { getFileUploadServices, } from "./file-upload.service.js";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import fs from "fs";
|
|
5
|
-
import catchAsync from "../error-handler/utils/catch-async";
|
|
6
|
-
import { getArkosConfig } from "../../server";
|
|
7
|
-
import { processFile, processImage } from "./utils/helpers/file-upload.helpers";
|
|
8
|
-
import { accessAsync, mkdirAsync, statAsync, } from "../../utils/helpers/fs.helpers";
|
|
9
|
-
import { getModelModules } from "../../utils/helpers/models.helpers";
|
|
5
|
+
import catchAsync from "../error-handler/utils/catch-async.js";
|
|
6
|
+
import { getArkosConfig } from "../../server.js";
|
|
7
|
+
import { processFile, processImage } from "./utils/helpers/file-upload.helpers.js";
|
|
8
|
+
import { accessAsync, mkdirAsync, statAsync, } from "../../utils/helpers/fs.helpers.js";
|
|
9
|
+
import { getModelModules } from "../../utils/helpers/models.helpers.js";
|
|
10
10
|
class FileUploadController {
|
|
11
11
|
constructor() {
|
|
12
12
|
this.uploadFile = catchAsync(async (req, res, next) => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Router } from "express";
|
|
2
|
-
import { importPrismaModelModules } from "../../utils/helpers/models.helpers";
|
|
3
|
-
import authService from "../auth/auth.service";
|
|
4
|
-
import fileUploadController from "./file-upload.controller";
|
|
2
|
+
import { importPrismaModelModules } from "../../utils/helpers/models.helpers.js";
|
|
3
|
+
import authService from "../auth/auth.service.js";
|
|
4
|
+
import fileUploadController from "./file-upload.controller.js";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import express from "express";
|
|
7
|
-
import deepmerge from "../../utils/helpers/deepmerge.helper";
|
|
8
|
-
import { sendResponse } from "../base/base.middlewares";
|
|
7
|
+
import deepmerge from "../../utils/helpers/deepmerge.helper.js";
|
|
8
|
+
import { sendResponse } from "../base/base.middlewares.js";
|
|
9
9
|
const router = Router();
|
|
10
10
|
export async function getFileUploadRouter({ fileUpload }) {
|
|
11
11
|
const modelModules = await importPrismaModelModules("file-upload");
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import multer from "multer";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import fs from "fs";
|
|
4
|
-
import AppError from "../error-handler/utils/app-error";
|
|
4
|
+
import AppError from "../error-handler/utils/app-error.js";
|
|
5
5
|
import { promisify } from "util";
|
|
6
|
-
import { getArkosConfig } from "../../server";
|
|
7
|
-
import deepmerge from "../../utils/helpers/deepmerge.helper";
|
|
8
|
-
import { processFile, processImage } from "./utils/helpers/file-upload.helpers";
|
|
9
|
-
import { removeBothSlashes } from "../../utils/helpers/text.helpers";
|
|
6
|
+
import { getArkosConfig } from "../../server.js";
|
|
7
|
+
import deepmerge from "../../utils/helpers/deepmerge.helper.js";
|
|
8
|
+
import { processFile, processImage } from "./utils/helpers/file-upload.helpers.js";
|
|
9
|
+
import { removeBothSlashes } from "../../utils/helpers/text.helpers.js";
|
|
10
10
|
export class FileUploadService {
|
|
11
11
|
constructor(uploadDir, fileSizeLimit = 1024 * 1024 * 5, allowedFileTypes = /.*/, maxCount = 30) {
|
|
12
12
|
this.fileFilter = (req, file, cb) => {
|
|
@@ -2,9 +2,9 @@ import fs from "fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import sharp from "sharp";
|
|
4
4
|
import { promisify } from "util";
|
|
5
|
-
import { getArkosConfig } from "../../../../server";
|
|
5
|
+
import { getArkosConfig } from "../../../../server.js";
|
|
6
6
|
import mimetype from "mimetype";
|
|
7
|
-
import { fullCleanCwd } from "../../../../utils/helpers/fs.helpers";
|
|
7
|
+
import { fullCleanCwd } from "../../../../utils/helpers/fs.helpers.js";
|
|
8
8
|
export function extractRequestInfo(req) {
|
|
9
9
|
const { fileUpload } = getArkosConfig();
|
|
10
10
|
const protocol = req.headers["x-forwarded-proto"] === "https" ? "https" : "http";
|
|
@@ -1,54 +1,38 @@
|
|
|
1
1
|
import { Router } from "express";
|
|
2
2
|
import swaggerUi from "swagger-ui-express";
|
|
3
3
|
import swaggerJsdoc from "swagger-jsdoc";
|
|
4
|
-
import deepmerge from "../../utils/helpers/deepmerge.helper";
|
|
4
|
+
import deepmerge from "../../utils/helpers/deepmerge.helper.js";
|
|
5
|
+
import { generatePathsForModels, getOpenAPIJsonSchemasByConfigMode, } from "./utils/helpers/swagger.router.helpers.js";
|
|
5
6
|
const swaggerRouter = Router();
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
case "prisma":
|
|
10
|
-
break;
|
|
11
|
-
case "class-validator":
|
|
12
|
-
break;
|
|
13
|
-
case "zod":
|
|
14
|
-
break;
|
|
15
|
-
case "json-schema":
|
|
16
|
-
default:
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
19
|
-
return schemas;
|
|
20
|
-
}
|
|
21
|
-
export function getSwaggerRouter(arkosConfig) {
|
|
7
|
+
export async function getSwaggerRouter(arkosConfig) {
|
|
8
|
+
const defaultJsonSchemas = await getOpenAPIJsonSchemasByConfigMode(arkosConfig.swagger);
|
|
9
|
+
const defaultModelsPaths = await generatePathsForModels(arkosConfig.swagger);
|
|
22
10
|
const defaultSwaggerConfig = {
|
|
23
|
-
endpoint: "/docs",
|
|
24
|
-
mode: "
|
|
11
|
+
endpoint: "/api-docs",
|
|
12
|
+
mode: "prisma",
|
|
25
13
|
options: {
|
|
26
14
|
definition: {
|
|
27
15
|
openapi: "3.0.0",
|
|
28
16
|
info: {
|
|
29
|
-
title: "
|
|
17
|
+
title: "Powered By Arkos.js",
|
|
30
18
|
version: "1.0.0",
|
|
31
|
-
description: "This API was automatically generated by Arkos.js read more about at www.arkosjs.com",
|
|
19
|
+
description: "This API was automatically generated by Arkos.js, read more about at www.arkosjs.com",
|
|
32
20
|
},
|
|
33
21
|
servers: [
|
|
34
22
|
{
|
|
35
23
|
url: `http://${arkosConfig.host}:${arkosConfig.port}`,
|
|
36
|
-
description: "
|
|
24
|
+
description: "Development server",
|
|
37
25
|
},
|
|
38
26
|
],
|
|
27
|
+
paths: defaultModelsPaths,
|
|
39
28
|
components: {
|
|
40
|
-
schemas: {},
|
|
29
|
+
schemas: defaultJsonSchemas || {},
|
|
41
30
|
securitySchemes: {
|
|
42
31
|
BearerAuth: {
|
|
43
32
|
type: "http",
|
|
44
33
|
scheme: "bearer",
|
|
45
34
|
bearerFormat: "JWT",
|
|
46
35
|
},
|
|
47
|
-
ApiKeyAuth: {
|
|
48
|
-
type: "apiKey",
|
|
49
|
-
in: "header",
|
|
50
|
-
name: "X-API-Key",
|
|
51
|
-
},
|
|
52
36
|
},
|
|
53
37
|
},
|
|
54
38
|
security: [],
|
|
@@ -59,10 +43,6 @@ export function getSwaggerRouter(arkosConfig) {
|
|
|
59
43
|
],
|
|
60
44
|
swaggerUiOptions: {
|
|
61
45
|
explorer: true,
|
|
62
|
-
customCss: `
|
|
63
|
-
.swagger-ui .topbar { display: none; }
|
|
64
|
-
.swagger-ui .info { margin: 20px 0; }
|
|
65
|
-
`,
|
|
66
46
|
swaggerOptions: {
|
|
67
47
|
filter: true,
|
|
68
48
|
displayRequestDuration: true,
|
|
@@ -76,11 +56,9 @@ export function getSwaggerRouter(arkosConfig) {
|
|
|
76
56
|
},
|
|
77
57
|
};
|
|
78
58
|
const swaggerConfigs = deepmerge(defaultSwaggerConfig, arkosConfig.swagger || {});
|
|
79
|
-
|
|
80
|
-
if (swaggerConfigs.options.definition.components?.schemas) {
|
|
59
|
+
if (swaggerConfigs?.options?.definition?.components?.schemas) {
|
|
81
60
|
swaggerConfigs.options.definition.components.schemas = {
|
|
82
|
-
...swaggerConfigs
|
|
83
|
-
...modeSchemas,
|
|
61
|
+
...swaggerConfigs?.options?.definition?.components.schemas,
|
|
84
62
|
};
|
|
85
63
|
}
|
|
86
64
|
const swaggerSpecification = swaggerJsdoc({
|
|
@@ -92,7 +70,7 @@ export function getSwaggerRouter(arkosConfig) {
|
|
|
92
70
|
explorer: swaggerConfigs.options.swaggerUiOptions?.explorer ?? true,
|
|
93
71
|
customCss: swaggerConfigs.options.swaggerUiOptions?.customCss,
|
|
94
72
|
customSiteTitle: swaggerConfigs.options.swaggerUiOptions?.customSiteTitle ||
|
|
95
|
-
"API Documentation",
|
|
73
|
+
"Arkos.js API Documentation",
|
|
96
74
|
customfavIcon: swaggerConfigs.options.swaggerUiOptions?.customfavIcon,
|
|
97
75
|
swaggerOptions: {
|
|
98
76
|
filter: swaggerConfigs.options.swaggerUiOptions?.swaggerOptions?.filter ?? true,
|
|
@@ -110,26 +88,6 @@ export function getSwaggerRouter(arkosConfig) {
|
|
|
110
88
|
};
|
|
111
89
|
swaggerRouter.use(swaggerConfigs.endpoint, swaggerUi.serve);
|
|
112
90
|
swaggerRouter.get(swaggerConfigs.endpoint, swaggerUi.setup(swaggerSpecification, swaggerUiOptions));
|
|
113
|
-
swaggerRouter.get(`${swaggerConfigs.endpoint}/json`, (req, res) => {
|
|
114
|
-
res.setHeader("Content-Type", "application/json");
|
|
115
|
-
res.json(swaggerSpecification);
|
|
116
|
-
});
|
|
117
|
-
swaggerRouter.get(`${swaggerConfigs.endpoint}/yaml`, (req, res) => {
|
|
118
|
-
const yaml = require("js-yaml");
|
|
119
|
-
res.setHeader("Content-Type", "text/yaml");
|
|
120
|
-
res.send(yaml.dump(swaggerSpecification));
|
|
121
|
-
});
|
|
122
|
-
swaggerRouter.get(`${swaggerConfigs.endpoint}/health`, (req, res) => {
|
|
123
|
-
res.json({
|
|
124
|
-
status: "ok",
|
|
125
|
-
swagger: {
|
|
126
|
-
version: swaggerConfigs.options.definition.openapi,
|
|
127
|
-
title: swaggerConfigs.options.definition.info?.title,
|
|
128
|
-
endpoint: swaggerConfigs.endpoint,
|
|
129
|
-
mode: swaggerConfigs.mode,
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
91
|
return swaggerRouter;
|
|
134
92
|
}
|
|
135
93
|
//# sourceMappingURL=swagger.router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger.router.js","sourceRoot":"","sources":["../../../../src/modules/swagger/swagger.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAC7D,OAAO,EACL,sBAAsB,EACtB,iCAAiC,GAClC,MAAM,wCAAwC,CAAC;AAEhD,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAE/B,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,WAAwB;IAExB,MAAM,kBAAkB,GAAG,MAAM,iCAAiC,CAChE,WAAW,CAAC,OAAO,CACpB,CAAC;IACF,MAAM,kBAAkB,GAAG,MAAM,sBAAsB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAE7E,MAAM,oBAAoB,GAA2B;QACnD,QAAQ,EAAE,WAAW;QACrB,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE;YACP,UAAU,EAAE;gBACV,OAAO,EAAE,OAAO;gBAChB,IAAI,EAAE;oBACJ,KAAK,EAAE,qBAAqB;oBAC5B,OAAO,EAAE,OAAO;oBAChB,WAAW,EACT,sFAAsF;iB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-ui-express\";\nimport swaggerJsdoc from \"swagger-jsdoc\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport {\n generatePathsForModels,\n getOpenAPIJsonSchemasByConfigMode,\n} from \"./utils/helpers/swagger.router.helpers\";\n\nconst swaggerRouter = Router();\n\nexport async function getSwaggerRouter(\n arkosConfig: ArkosConfig\n): Promise<Router> {\n const defaultJsonSchemas = await getOpenAPIJsonSchemasByConfigMode(\n arkosConfig.swagger\n );\n const defaultModelsPaths = await generatePathsForModels(arkosConfig.swagger);\n\n const defaultSwaggerConfig: ArkosConfig[\"swagger\"] = {\n endpoint: \"/api-docs\",\n mode: \"prisma\",\n options: {\n definition: {\n openapi: \"3.0.0\",\n info: {\n title: \"Powered By Arkos.js\",\n version: \"1.0.0\",\n description:\n \"This API was automatically generated by Arkos.js, read more about at www.arkosjs.com\",\n },\n servers: [\n {\n url: `http://${arkosConfig.host}:${arkosConfig.port}`,\n description: \"Development server\",\n },\n ],\n paths: defaultModelsPaths,\n components: {\n schemas: defaultJsonSchemas || {},\n securitySchemes: {\n BearerAuth: {\n type: \"http\",\n scheme: \"bearer\",\n bearerFormat: \"JWT\",\n },\n },\n },\n security: [],\n },\n apis: [\n \"./src/routers/*.router.{ts,js}\",\n \"./src/modules/**/*.router.{ts,js}\",\n ],\n swaggerUiOptions: {\n explorer: true,\n swaggerOptions: {\n filter: true,\n displayRequestDuration: true,\n showExtensions: true,\n showCommonExtensions: true,\n },\n },\n deepLinking: true,\n tryItOutEnabled: true,\n persistAuthorization: false,\n },\n };\n\n // Merge default config with user config\n const swaggerConfigs = deepmerge(\n defaultSwaggerConfig,\n arkosConfig.swagger || {}\n );\n\n // Merge mode-generated schemas with existing schemas\n if (swaggerConfigs?.options?.definition?.components?.schemas) {\n swaggerConfigs.options.definition.components.schemas = {\n ...swaggerConfigs?.options?.definition?.components.schemas,\n };\n }\n\n // Generate OpenAPI specification using swagger-jsdoc\n const swaggerSpecification = swaggerJsdoc({\n definition: swaggerConfigs.options\n .definition as swaggerJsdoc.SwaggerDefinition,\n apis: swaggerConfigs.options.apis || [],\n });\n\n // Setup Swagger UI options\n const swaggerUiOptions = {\n explorer: swaggerConfigs.options.swaggerUiOptions?.explorer ?? true,\n customCss: swaggerConfigs.options.swaggerUiOptions?.customCss,\n customSiteTitle:\n swaggerConfigs.options.swaggerUiOptions?.customSiteTitle ||\n \"Arkos.js API Documentation\",\n customfavIcon: swaggerConfigs.options.swaggerUiOptions?.customfavIcon,\n swaggerOptions: {\n filter:\n swaggerConfigs.options.swaggerUiOptions?.swaggerOptions?.filter ?? true,\n displayRequestDuration:\n swaggerConfigs.options.swaggerUiOptions?.swaggerOptions\n ?.displayRequestDuration ?? true,\n deepLinking: swaggerConfigs.options.deepLinking ?? true,\n tryItOutEnabled: swaggerConfigs.options.tryItOutEnabled ?? true,\n persistAuthorization:\n swaggerConfigs.options.persistAuthorization ?? false,\n showExtensions:\n swaggerConfigs.options.swaggerUiOptions?.swaggerOptions\n ?.showExtensions ?? true,\n showCommonExtensions:\n swaggerConfigs.options.swaggerUiOptions?.swaggerOptions\n ?.showCommonExtensions ?? true,\n ...swaggerConfigs.options.swaggerUiOptions?.swaggerOptions,\n },\n };\n\n // Serve Swagger UI static assets\n swaggerRouter.use(swaggerConfigs.endpoint!, swaggerUi.serve);\n\n // Serve Swagger documentation\n swaggerRouter.get(\n swaggerConfigs.endpoint!,\n swaggerUi.setup(swaggerSpecification, swaggerUiOptions)\n );\n\n // Serve raw OpenAPI spec as JSON\n // swaggerRouter.get(`${swaggerConfigs.endpoint}/json`, (req, res) => {\n // res.setHeader(\"Content-Type\", \"application/json\");\n // res.json(swaggerSpecification);\n // });\n\n // // Serve raw OpenAPI spec as YAML (optional)\n // swaggerRouter.get(`${swaggerConfigs.endpoint}/yaml`, (req, res) => {\n // const yaml = require(\"js-yaml\");\n // res.setHeader(\"Content-Type\", \"text/yaml\");\n // res.send(yaml.dump(swaggerSpecification));\n // });\n\n // // Health check endpoint for Swagger itself\n // swaggerRouter.get(`${swaggerConfigs.endpoint}/health`, (req, res) => {\n // res.json({\n // status: \"ok\",\n // swagger: {\n // version: swaggerConfigs?.options?.definition?.openapi,\n // title: swaggerConfigs?.options?.definition?.info?.title,\n // endpoint: swaggerConfigs.endpoint,\n // mode: swaggerConfigs.mode,\n // },\n // });\n // });\n\n return swaggerRouter;\n}\n"]}
|