arkos 1.2.31-test → 1.3.0-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 +2 -2
- package/dist/cjs/app.js +1 -1
- package/dist/cjs/app.js.map +1 -1
- package/dist/cjs/exports/auth/index.js +1 -6
- package/dist/cjs/exports/controllers/index.js +1 -11
- package/dist/cjs/exports/error-handler/index.js +1 -11
- package/dist/cjs/exports/index.js +1 -12
- package/dist/cjs/exports/middlewares/index.js +1 -7
- package/dist/cjs/exports/prisma/index.js +1 -6
- package/dist/cjs/exports/prisma/index.js.map +1 -1
- package/dist/cjs/exports/services/index.js +1 -49
- package/dist/cjs/exports/services/index.js.map +1 -1
- package/dist/cjs/exports/utils/index.js +1 -44
- package/dist/cjs/exports/validation/index.js +1 -11
- package/dist/cjs/modules/auth/auth.controller.js +1 -194
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/auth/auth.router.js +1 -50
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/auth/auth.service.js +1 -185
- package/dist/cjs/modules/auth/auth.service.js.map +1 -1
- package/dist/cjs/modules/auth/utils/auth-error-objects.js +1 -0
- package/dist/cjs/modules/auth/utils/auth-error-objects.js.map +1 -0
- package/dist/cjs/modules/auth/utils/helpers/auth.controller.helpers.js +1 -83
- package/dist/cjs/modules/auth/utils/services/auth-action.service.js +1 -0
- package/dist/cjs/modules/auth/utils/services/auth-action.service.js.map +1 -0
- package/dist/cjs/modules/base/base.controller.js +1 -158
- package/dist/cjs/modules/base/base.controller.js.map +1 -1
- package/dist/cjs/modules/base/base.middlewares.js +1 -92
- package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
- package/dist/cjs/modules/base/base.router.js +1 -24
- package/dist/cjs/modules/base/base.router.js.map +1 -1
- package/dist/cjs/modules/base/base.service.js +1 -128
- package/dist/cjs/modules/base/base.service.js.map +1 -1
- package/dist/cjs/modules/base/types/base.service.types.js +1 -0
- package/dist/cjs/modules/base/types/base.service.types.js.map +1 -0
- package/dist/cjs/modules/base/utils/helpers/base.controller.helpers.js +1 -82
- package/dist/cjs/modules/base/utils/helpers/base.controller.helpers.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.middlewares.helpers.js +1 -50
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +1 -97
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js +1 -171
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/cjs/modules/base/utils/router-validator.js +1 -0
- package/dist/cjs/modules/base/utils/router-validator.js.map +1 -0
- package/dist/cjs/modules/base/utils/service-hooks-manager.js +1 -0
- package/dist/cjs/modules/base/utils/service-hooks-manager.js.map +1 -0
- package/dist/cjs/modules/email/email.service.js +1 -104
- package/dist/cjs/modules/error-handler/error-handler.controller.js +4 -146
- package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/app-error.js +1 -17
- package/dist/cjs/modules/error-handler/utils/app-error.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/catch-async.js +1 -12
- package/dist/cjs/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js +3 -201
- package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.controller.js +1 -271
- package/dist/cjs/modules/file-upload/file-upload.controller.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js +1 -44
- package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/cjs/modules/file-upload/file-upload.service.js +1 -322
- package/dist/cjs/modules/file-upload/file-upload.service.js.map +1 -1
- package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js +1 -97
- package/dist/cjs/modules/swagger/swagger.router.js +1 -99
- package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +1 -250
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/get-system-json-schema-paths.js +1 -66
- package/dist/cjs/modules/swagger/utils/helpers/get-system-json-schema-paths.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +1 -41
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +1 -22
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +1 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -0
- package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js +1 -94
- package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/server.js +4 -2
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/types/arkos-config.js +1 -3
- package/dist/cjs/types/arkos-config.js.map +1 -1
- package/dist/cjs/types/auth.js +1 -3
- package/dist/cjs/types/auth.js.map +1 -1
- package/dist/cjs/types/index.js +1 -11
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/router-config.js +1 -3
- package/dist/cjs/types/router-config.js.map +1 -1
- package/dist/cjs/utils/arkos-env.js +1 -9
- package/dist/cjs/utils/cli/build.js +5 -212
- package/dist/cjs/utils/cli/build.js.map +1 -1
- package/dist/cjs/utils/cli/dev.js +3 -256
- package/dist/cjs/utils/cli/dev.js.map +1 -1
- package/dist/cjs/utils/cli/generate.js +1 -189
- package/dist/cjs/utils/cli/generate.js.map +1 -1
- package/dist/cjs/utils/cli/index.js +1 -81
- package/dist/cjs/utils/cli/index.js.map +1 -1
- package/dist/cjs/utils/cli/start.js +1 -93
- package/dist/cjs/utils/cli/start.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -24
- package/dist/cjs/utils/cli/utils/smart-fs-watcher.js +1 -0
- package/dist/cjs/utils/cli/utils/smart-fs-watcher.js.map +1 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js +5 -20
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js +9 -18
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-hooks-template.js +144 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-hooks-template.js.map +1 -0
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js +156 -135
- 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 +9 -37
- 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 +11 -36
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js +6 -32
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js.map +1 -1
- package/dist/cjs/utils/cli/utils/template-generators.js +2 -28
- package/dist/cjs/utils/cli/utils/template-generators.js.map +1 -1
- package/dist/cjs/utils/cli/utils/watermark-stamper.js +3 -0
- package/dist/cjs/utils/cli/utils/watermark-stamper.js.map +1 -0
- package/dist/cjs/utils/dotenv.helpers.js +1 -43
- package/dist/cjs/utils/dynamic-loader.js +9 -0
- package/dist/cjs/utils/dynamic-loader.js.map +1 -0
- package/dist/cjs/utils/features/api.features.js +1 -167
- package/dist/cjs/utils/features/api.features.js.map +1 -1
- package/dist/cjs/utils/features/change-case.features.js +1 -67
- package/dist/cjs/utils/features/port-and-host-allocator.js +1 -0
- package/dist/cjs/utils/features/port-and-host-allocator.js.map +1 -0
- package/dist/cjs/utils/helpers/api.features.helpers.js +1 -106
- package/dist/cjs/utils/helpers/api.features.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/change-case.helpers.js +1 -177
- package/dist/cjs/utils/helpers/deepmerge.helper.js +1 -115
- package/dist/cjs/utils/helpers/dynamic-loader.helpers.js +1 -0
- package/dist/cjs/utils/helpers/dynamic-loader.helpers.js.map +1 -0
- package/dist/cjs/utils/helpers/fs.helpers.js +1 -61
- package/dist/cjs/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/global.helpers.js +1 -92
- package/dist/cjs/utils/helpers/global.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js +1 -52
- package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/query-parser.helpers.js +1 -45
- package/dist/cjs/utils/helpers/routers.helpers.js +1 -21
- package/dist/cjs/utils/helpers/routers.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/text.helpers.js +1 -28
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js +1 -0
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js.map +1 -0
- package/dist/cjs/utils/prisma/prisma-schema-parser.js +4 -0
- package/dist/cjs/utils/prisma/prisma-schema-parser.js.map +1 -0
- package/dist/cjs/utils/prisma/types.js +1 -0
- package/dist/cjs/utils/prisma/types.js.map +1 -0
- package/dist/cjs/utils/sheu.js +1 -119
- package/dist/cjs/utils/sheu.js.map +1 -1
- package/dist/cjs/utils/validate-dto.js +1 -17
- package/dist/cjs/utils/validate-dto.js.map +1 -1
- package/dist/cjs/utils/validate-schema.js +1 -15
- package/dist/cjs/utils/validate-schema.js.map +1 -1
- package/dist/esm/app.js +1 -1
- package/dist/esm/app.js.map +1 -1
- package/dist/esm/exports/auth/index.js +1 -2
- package/dist/esm/exports/controllers/index.js +1 -4
- package/dist/esm/exports/error-handler/index.js +1 -4
- package/dist/esm/exports/index.js +1 -8
- package/dist/esm/exports/middlewares/index.js +1 -2
- package/dist/esm/exports/prisma/index.js +1 -3
- package/dist/esm/exports/prisma/index.js.map +1 -1
- package/dist/esm/exports/services/index.js +1 -9
- package/dist/esm/exports/services/index.js.map +1 -1
- package/dist/esm/exports/utils/index.js +1 -4
- package/dist/esm/exports/validation/index.js +1 -4
- package/dist/esm/modules/auth/auth.controller.js +1 -187
- package/dist/esm/modules/auth/auth.controller.js.map +1 -1
- package/dist/esm/modules/auth/auth.router.js +1 -44
- package/dist/esm/modules/auth/auth.router.js.map +1 -1
- package/dist/esm/modules/auth/auth.service.js +1 -178
- package/dist/esm/modules/auth/auth.service.js.map +1 -1
- package/dist/esm/modules/auth/utils/auth-error-objects.js +1 -0
- package/dist/esm/modules/auth/utils/auth-error-objects.js.map +1 -0
- package/dist/esm/modules/auth/utils/helpers/auth.controller.helpers.js +1 -73
- package/dist/esm/modules/auth/utils/services/auth-action.service.js +1 -0
- package/dist/esm/modules/auth/utils/services/auth-action.service.js.map +1 -0
- package/dist/esm/modules/base/base.controller.js +1 -150
- package/dist/esm/modules/base/base.controller.js.map +1 -1
- package/dist/esm/modules/base/base.middlewares.js +1 -81
- package/dist/esm/modules/base/base.middlewares.js.map +1 -1
- package/dist/esm/modules/base/base.router.js +1 -17
- package/dist/esm/modules/base/base.router.js.map +1 -1
- package/dist/esm/modules/base/base.service.js +1 -120
- package/dist/esm/modules/base/base.service.js.map +1 -1
- package/dist/esm/modules/base/types/base.service.types.js +1 -0
- package/dist/esm/modules/base/types/base.service.types.js.map +1 -0
- package/dist/esm/modules/base/utils/helpers/base.controller.helpers.js +1 -77
- package/dist/esm/modules/base/utils/helpers/base.controller.helpers.js.map +1 -1
- package/dist/esm/modules/base/utils/helpers/base.middlewares.helpers.js +1 -44
- package/dist/esm/modules/base/utils/helpers/base.router.helpers.js +1 -89
- package/dist/esm/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/esm/modules/base/utils/helpers/base.service.helpers.js +1 -165
- package/dist/esm/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/esm/modules/base/utils/router-validator.js +1 -0
- package/dist/esm/modules/base/utils/router-validator.js.map +1 -0
- package/dist/esm/modules/base/utils/service-hooks-manager.js +1 -0
- package/dist/esm/modules/base/utils/service-hooks-manager.js.map +1 -0
- package/dist/esm/modules/email/email.service.js +1 -97
- package/dist/esm/modules/error-handler/error-handler.controller.js +4 -107
- package/dist/esm/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/app-error.js +1 -15
- package/dist/esm/modules/error-handler/utils/app-error.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/catch-async.js +1 -10
- package/dist/esm/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/error-handler.helpers.js +3 -160
- package/dist/esm/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.controller.js +1 -266
- package/dist/esm/modules/file-upload/file-upload.controller.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.router.js +1 -38
- package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.service.js +1 -314
- package/dist/esm/modules/file-upload/file-upload.service.js.map +1 -1
- package/dist/esm/modules/file-upload/utils/helpers/file-upload.helpers.js +1 -87
- package/dist/esm/modules/swagger/swagger.router.js +1 -93
- package/dist/esm/modules/swagger/swagger.router.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +1 -247
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js +1 -0
- package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/get-system-json-schema-paths.js +1 -63
- package/dist/esm/modules/swagger/utils/helpers/get-system-json-schema-paths.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +1 -38
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +1 -19
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js +1 -0
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js +1 -0
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js +1 -84
- package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
- package/dist/esm/package.json +3 -0
- package/dist/esm/server.js +4 -2
- package/dist/esm/server.js.map +1 -1
- package/dist/esm/types/arkos-config.js +1 -2
- package/dist/esm/types/arkos-config.js.map +1 -1
- package/dist/esm/types/auth.js +1 -2
- package/dist/esm/types/auth.js.map +1 -1
- package/dist/esm/types/index.js +1 -8
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/router-config.js +1 -2
- package/dist/esm/types/router-config.js.map +1 -1
- package/dist/esm/utils/arkos-env.js +1 -7
- package/dist/esm/utils/cli/build.js +5 -206
- package/dist/esm/utils/cli/build.js.map +1 -1
- package/dist/esm/utils/cli/dev.js +3 -249
- package/dist/esm/utils/cli/dev.js.map +1 -1
- package/dist/esm/utils/cli/generate.js +1 -183
- package/dist/esm/utils/cli/generate.js.map +1 -1
- package/dist/esm/utils/cli/index.js +1 -74
- package/dist/esm/utils/cli/index.js.map +1 -1
- package/dist/esm/utils/cli/start.js +1 -86
- package/dist/esm/utils/cli/start.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -16
- package/dist/esm/utils/cli/utils/smart-fs-watcher.js +1 -0
- package/dist/esm/utils/cli/utils/smart-fs-watcher.js.map +1 -0
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js +5 -17
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-controller-template.js +9 -15
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-hooks-template.js +144 -0
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-hooks-template.js.map +1 -0
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-middlewares.js +156 -132
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +9 -34
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-router-template.js +11 -30
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-router-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-service-template.js +6 -29
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-service-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generators.js +2 -25
- package/dist/esm/utils/cli/utils/template-generators.js.map +1 -1
- package/dist/esm/utils/cli/utils/watermark-stamper.js +3 -0
- package/dist/esm/utils/cli/utils/watermark-stamper.js.map +1 -0
- package/dist/esm/utils/dotenv.helpers.js +1 -37
- package/dist/esm/utils/dynamic-loader.js +9 -0
- package/dist/esm/utils/dynamic-loader.js.map +1 -0
- package/dist/esm/utils/features/api.features.js +1 -160
- package/dist/esm/utils/features/api.features.js.map +1 -1
- package/dist/esm/utils/features/change-case.features.js +1 -31
- package/dist/esm/utils/features/port-and-host-allocator.js +1 -0
- package/dist/esm/utils/features/port-and-host-allocator.js.map +1 -0
- package/dist/esm/utils/helpers/api.features.helpers.js +1 -103
- package/dist/esm/utils/helpers/api.features.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/change-case.helpers.js +1 -161
- package/dist/esm/utils/helpers/deepmerge.helper.js +1 -113
- package/dist/esm/utils/helpers/dynamic-loader.helpers.js +1 -0
- package/dist/esm/utils/helpers/dynamic-loader.helpers.js.map +1 -0
- package/dist/esm/utils/helpers/fs.helpers.js +1 -52
- package/dist/esm/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/global.helpers.js +1 -50
- package/dist/esm/utils/helpers/global.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/prisma.helpers.js +1 -44
- package/dist/esm/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/query-parser.helpers.js +1 -40
- package/dist/esm/utils/helpers/routers.helpers.js +1 -16
- package/dist/esm/utils/helpers/routers.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/text.helpers.js +1 -22
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js +1 -0
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js.map +1 -0
- package/dist/esm/utils/prisma/prisma-schema-parser.js +4 -0
- package/dist/esm/utils/prisma/prisma-schema-parser.js.map +1 -0
- package/dist/esm/utils/prisma/types.js +1 -0
- package/dist/esm/utils/prisma/types.js.map +1 -0
- package/dist/esm/utils/sheu.js +1 -117
- package/dist/esm/utils/sheu.js.map +1 -1
- package/dist/esm/utils/validate-dto.js +1 -11
- package/dist/esm/utils/validate-dto.js.map +1 -1
- package/dist/esm/utils/validate-schema.js +1 -9
- package/dist/esm/utils/validate-schema.js.map +1 -1
- package/dist/types/exports/prisma/index.d.ts +3 -2
- package/dist/types/exports/services/index.d.ts +3 -2
- package/dist/types/modules/auth/auth.controller.d.ts +10 -9
- package/dist/types/modules/auth/auth.service.d.ts +7 -3
- package/dist/types/modules/auth/utils/auth-error-objects.d.ts +3 -0
- package/dist/types/modules/auth/utils/services/auth-action.service.d.ts +23 -0
- package/dist/types/modules/base/base.controller.d.ts +10 -12
- package/dist/types/modules/base/base.middlewares.d.ts +4 -4
- package/dist/types/modules/base/base.service.d.ts +14 -68
- package/dist/types/modules/base/types/base.service.types.d.ts +215 -0
- package/dist/types/modules/base/utils/helpers/base.controller.helpers.d.ts +0 -2
- package/dist/types/modules/base/utils/helpers/base.router.helpers.d.ts +3 -3
- package/dist/types/modules/base/utils/helpers/base.service.helpers.d.ts +9 -2
- package/dist/types/modules/base/utils/router-validator.d.ts +5 -0
- package/dist/types/modules/base/utils/service-hooks-manager.d.ts +7 -0
- package/dist/types/modules/error-handler/error-handler.controller.d.ts +1 -1
- package/dist/types/modules/error-handler/utils/catch-async.d.ts +4 -2
- package/dist/types/modules/error-handler/utils/error-handler.helpers.d.ts +18 -17
- package/dist/types/modules/file-upload/file-upload.controller.d.ts +4 -6
- package/dist/types/modules/file-upload/file-upload.service.d.ts +4 -5
- package/dist/types/modules/swagger/utils/helpers/get-authentication-json-schema-paths.d.ts +3 -1
- package/dist/types/modules/swagger/utils/helpers/get-swagger-default-configs.d.ts +46 -0
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.d.ts +2 -1
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.d.ts +4 -0
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.d.ts +1 -0
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.d.ts +3 -0
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.d.ts +3 -0
- package/dist/types/modules/swagger/utils/helpers/missing-json-schemas-generator.d.ts +34 -0
- package/dist/types/modules/swagger/utils/helpers/swagger.router.helpers.d.ts +4 -2
- package/dist/types/server.d.ts +4 -1
- package/dist/types/types/arkos-config.d.ts +5 -3
- package/dist/types/types/auth.d.ts +7 -1
- package/dist/types/types/index.d.ts +4 -1
- package/dist/types/types/router-config.d.ts +24 -1
- package/dist/types/utils/cli/generate.d.ts +2 -1
- package/dist/types/utils/cli/utils/smart-fs-watcher.d.ts +11 -0
- package/dist/types/utils/cli/utils/template-generator/templates/generate-hooks-template.d.ts +2 -0
- package/dist/types/utils/cli/utils/watermark-stamper.d.ts +9 -0
- package/dist/types/utils/dynamic-loader.d.ts +104 -0
- package/dist/types/utils/features/port-and-host-allocator.d.ts +21 -0
- package/dist/types/utils/helpers/dynamic-loader.helpers.d.ts +3 -0
- package/dist/types/utils/helpers/fs.helpers.d.ts +0 -4
- package/dist/types/utils/helpers/global.helpers.d.ts +1 -0
- package/dist/types/utils/helpers/prisma.helpers.d.ts +0 -1
- package/dist/types/utils/helpers/routers.helpers.d.ts +6 -2
- package/dist/types/utils/prisma/prisma-json-schema-generator.d.ts +34 -0
- package/dist/types/utils/prisma/prisma-schema-parser.d.ts +28 -0
- package/dist/types/utils/prisma/types.d.ts +49 -0
- package/dist/types/utils/sheu.d.ts +15 -15
- package/package.json +32 -18
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js +0 -30
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js +0 -442
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js +0 -165
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js.map +0 -1
- package/dist/cjs/utils/helpers/models.helpers.js +0 -313
- package/dist/cjs/utils/helpers/models.helpers.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js +0 -24
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js +0 -436
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js +0 -159
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js.map +0 -1
- package/dist/esm/utils/helpers/models.helpers.js +0 -296
- package/dist/esm/utils/helpers/models.helpers.js.map +0 -1
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.d.ts +0 -1
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.d.ts +0 -2
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.d.ts +0 -2
- package/dist/types/utils/helpers/models.helpers.d.ts +0 -107
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-upload.service.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.service.ts"],"names":[],"mappings":"AAAA,OAAO,MAAyB,MAAM,QAAQ,CAAC;AAC/C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,QAAQ,MAAM,kCAAkC,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAMrE,MAAM,OAAO,iBAAiB;IAa5B,YACE,SAAiB,EACjB,gBAAwB,IAAI,GAAG,IAAI,GAAG,CAAC,EACvC,mBAA2B,IAAI,EAC/B,WAAmB,EAAE;QA+Bf,eAAU,GAAG,CAAC,GAA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AC,SAAS,CAAC,OAAO,EAC9B,YAAY,CAAC,SAAS,CAAC,mBAAmB,EAC1C,YAAY,CAAC,SAAS,CAAC,QAAQ,CAChC,CAAC;IAKF,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAC7C,GAAG,aAAa,QAAQ,EACxB,YAAY,CAAC,KAAK,CAAC,OAAO,EAC1B,YAAY,CAAC,KAAK,CAAC,mBAAmB,EACtC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAC5B,CAAC;IAEF,OAAO;QACL,kBAAkB;QAClB,kBAAkB;QAClB,qBAAqB;QACrB,iBAAiB;KAClB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import multer, { StorageEngine } from \"multer\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { NextFunction } from \"express\";\nimport AppError from \"../error-handler/utils/app-error\";\nimport { promisify } from \"util\";\nimport { getArkosConfig } from \"../../server\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { ArkosRequest, ArkosResponse } from \"../../types\";\nimport { processFile, processImage } from \"./utils/helpers/file-upload.helpers\";\nimport { removeBothSlashes } from \"../../utils/helpers/text.helpers\";\n\n/**\n * Service to handle file uploads, including single and multiple file uploads,\n * file validation (type, size), and file deletion.\n */\nexport class FileUploadService {\n public readonly uploadDir: string;\n private fileSizeLimit: number;\n private allowedFileTypes: RegExp;\n private storage: StorageEngine;\n private maxCount: number;\n\n /**\n * Constructor to initialize the file uploader service.\n * @param {string} uploadDir - The directory where files will be uploaded.\n * @param {number} fileSizeLimit - The maximum allowed file size.\n * @param {RegExp} allowedFileTypes - The regular expression for allowed file types.\n */\n constructor(\n uploadDir: string,\n fileSizeLimit: number = 1024 * 1024 * 5,\n allowedFileTypes: RegExp = /.*/,\n maxCount: number = 30\n ) {\n uploadDir = uploadDir.startsWith(\"/\") ? uploadDir.substring(1) : uploadDir;\n uploadDir = uploadDir.endsWith(\"/\") ? uploadDir.slice(0, -1) : uploadDir;\n\n this.uploadDir = path.resolve(process.cwd(), `${uploadDir}/`);\n this.fileSizeLimit = fileSizeLimit;\n this.allowedFileTypes = allowedFileTypes;\n this.maxCount = maxCount;\n\n if (!fs.existsSync(this.uploadDir)) {\n fs.mkdirSync(this.uploadDir, { recursive: true });\n }\n\n this.storage = multer.diskStorage({\n destination: (req, file, cb) => {\n cb(null, this.uploadDir);\n },\n filename: (req, file, cb) => {\n const uniqueSuffix = Date.now() + \"-\" + Math.round(Math.random() * 1e9);\n cb(null, `${uniqueSuffix}${path.extname(file.originalname)}`);\n },\n });\n }\n\n /**\n * Validates the file's type and MIME type.\n * @param {Request} req - The Express request object.\n * @param {Express.Multer.File} file - The uploaded file.\n * @param {Function} cb - The callback function to indicate if file is valid.\n */\n private fileFilter = (req: any, file: any, cb: any) => {\n const extName = this.allowedFileTypes.test(\n path.extname(file.originalname).toLowerCase()\n );\n const mimeType = this.allowedFileTypes.test(file.mimetype);\n\n if (mimeType && extName) {\n cb(null, true);\n } else {\n cb(new AppError(\"Invalid file type\", 400));\n }\n };\n\n /**\n * Returns the multer upload configuration.\n * @returns {multer.Instance} The multer instance configured for file uploads.\n */\n public getUpload() {\n return multer({\n storage: this.storage,\n fileFilter: this.fileFilter,\n limits: { fileSize: this.fileSizeLimit },\n });\n }\n\n /**\n * Middleware to handle single file upload.\n * @param {string} [oldFilePath] - The path to the file to delete before uploading.\n * @returns {Function} Middleware function for handling file upload.\n */\n public handleSingleUpload(oldFilePath?: string) {\n return (req: ArkosRequest, res: ArkosResponse, next: NextFunction) => {\n const upload = this.getUpload().single(this.getFieldName());\n upload(req, res, async (err) => {\n if (err instanceof multer.MulterError) {\n return next(err);\n } else if (err) {\n return next(err);\n }\n\n if (oldFilePath) {\n const { fileUpload: configs } = getArkosConfig();\n\n const filePath = path.resolve(\n process.cwd(),\n removeBothSlashes(configs?.baseUploadDir!),\n removeBothSlashes(oldFilePath)\n );\n try {\n const stats = await promisify(fs.stat)(filePath);\n if (stats) await promisify(fs.unlink)(filePath);\n } catch (err) {\n console.error(err);\n }\n }\n\n next();\n });\n };\n }\n\n /**\n * Middleware to handle multiple file uploads.\n * @param {number} maxCount - The maximum number of files allowed for upload.\n * @returns {Function} Middleware function for handling multiple file uploads.\n */\n public handleMultipleUpload() {\n return (req: ArkosRequest, res: ArkosResponse, next: NextFunction) => {\n const upload = this.getUpload().array(this.getFieldName(), this.maxCount);\n upload(req, res, (err) => {\n if (err instanceof multer.MulterError) return next(err);\n else if (err) return next(err);\n next();\n });\n };\n }\n\n /**\n * Middleware to handle deletion of a single file from the filesystem.\n * @param {string} oldFilePath - The path to the file to be deleted.\n * @returns {Function} Middleware function for handling file deletion.\n */\n public handleDeleteSingleFile(oldFilePath: string) {\n return async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: NextFunction\n ) => {\n const filePath = path.join(oldFilePath);\n try {\n const stats = await promisify(fs.stat)(filePath);\n if (stats) {\n await promisify(fs.unlink)(filePath);\n }\n } catch (err) {\n console.error(err);\n }\n\n next();\n };\n }\n\n /**\n * Deletes a file based on its URL by identifying the appropriate uploader service\n * @param {string} fileUrl - The URL of the file to delete\n * @returns {Promise<boolean>} - True if deletion successful, false otherwise\n */\n public async deleteFileByUrl(fileUrl: string): Promise<boolean> {\n try {\n // Get configuration values\n const { fileUpload } = getArkosConfig();\n const baseRoute = fileUpload?.baseRoute || \"/api/uploads\";\n\n // Parse the URL to get the path\n let urlPath: string;\n if (fileUrl.startsWith(\"http\")) {\n const url = new URL(fileUrl);\n urlPath = url.pathname;\n } else {\n urlPath = fileUrl;\n }\n\n // Extract the path after the base route\n const baseRouteIndex = urlPath.indexOf(baseRoute);\n if (baseRouteIndex === -1) {\n throw new AppError(\"Invalid file URL: base route not found\", 400);\n }\n\n const pathAfterBaseRoute = urlPath.substring(\n baseRouteIndex + baseRoute.length\n );\n const cleanPath = pathAfterBaseRoute.startsWith(\"/\")\n ? pathAfterBaseRoute.substring(1)\n : pathAfterBaseRoute;\n\n // Determine file type and file name\n const fileTypes = [\"images\", \"videos\", \"documents\", \"files\"];\n let fileType: string | null = null;\n let fileName: string | null = null;\n\n for (const type of fileTypes) {\n const typeIndex = cleanPath.indexOf(type + \"/\");\n if (typeIndex !== -1) {\n fileType = type;\n fileName = cleanPath.substring(typeIndex + type.length + 1);\n break;\n }\n }\n\n if (!fileType || !fileName) {\n throw new AppError(\n \"Unable to determine file type or file name from URL\",\n 400\n );\n }\n\n // Get the appropriate uploader service based on file type\n const {\n documentUploadService,\n fileUploadService,\n imageUploadService,\n videoUploadService,\n } = getFileUploadServices();\n\n let filePath: string;\n switch (fileType) {\n case \"images\":\n filePath = path.join(imageUploadService.uploadDir, fileName);\n break;\n case \"videos\":\n filePath = path.join(videoUploadService.uploadDir, fileName);\n break;\n case \"documents\":\n filePath = path.join(documentUploadService.uploadDir, fileName);\n break;\n case \"files\":\n filePath = path.join(fileUploadService.uploadDir, fileName);\n break;\n default:\n throw new AppError(`Unsupported file type: ${fileType}`, 400);\n }\n\n // Delete the file\n\n await promisify(fs.stat)(filePath);\n await promisify(fs.unlink)(filePath);\n\n return true;\n } catch (error: any) {\n if (error instanceof AppError) {\n throw error;\n }\n\n if (error.code === \"ENOENT\") {\n throw new AppError(\"File not found\", 404);\n }\n\n throw new AppError(`Failed to delete file: ${error.message}`, 500);\n }\n }\n\n private getFieldName() {\n let fieldName = \"files\";\n if (this.uploadDir.endsWith(\"images\") || this.uploadDir.endsWith(\"images/\"))\n fieldName = \"images\";\n if (this.uploadDir.endsWith(\"videos\") || this.uploadDir.endsWith(\"videos/\"))\n fieldName = \"videos\";\n if (\n this.uploadDir.endsWith(\"documents\") ||\n this.uploadDir.endsWith(\"documents/\")\n )\n fieldName = \"documents\";\n if (this.uploadDir.endsWith(\"files\") || this.uploadDir.endsWith(\"files/\"))\n fieldName = \"files\";\n return fieldName;\n }\n\n /**\n * Handles the upload process and returns the full URLs of uploaded files\n * @param {ArkosRequest} req - Arkos request object containing the files\n * @param {ArkosResponse} res - Arkos response object\n * @param {object} options - Optional parameters for image processing\n * @returns {Promise<string|string[]>} URL or array of URLs to the uploaded files\n */\n public async upload(\n req: ArkosRequest,\n res: ArkosResponse,\n options: {\n format?: string;\n width?: number;\n height?: number;\n resizeTo?: number;\n } = {}\n ): Promise<string | string[] | null> {\n const { fileUpload } = getArkosConfig();\n const baseRoute = fileUpload?.baseRoute || \"/api/uploads\";\n\n return new Promise((resolve, reject) => {\n // Determine if it's a single or multiple file upload\n const isMultiple = Array.isArray(req.query.multiple)\n ? req.query.multiple[0] == \"true\"\n : req.query.multiple == \"true\";\n\n // Use appropriate upload handler\n const uploadHandler = isMultiple\n ? this.getUpload().array(this.getFieldName(), this.maxCount)\n : this.getUpload().single(this.getFieldName());\n\n uploadHandler(req, res, async (err) => {\n if (err) return reject(err);\n\n try {\n // Determine the base URL for file access\n const protocol = req.get(\"host\")?.includes?.(\"localhost\")\n ? \"http\"\n : \"https\";\n const baseURL = `${protocol}://${req.get(\"host\")}`;\n\n // Get file type from uploadDir path\n const dirParts = this.uploadDir.split(\"/\");\n const fileType =\n (this.uploadDir.endsWith(\"/\")\n ? dirParts[dirParts.length - 2]\n : dirParts[dirParts.length - 1]) || \"files\";\n\n // Process all uploaded files\n let data;\n if (req.files && Array.isArray(req.files) && req.files.length > 0) {\n // Process multiple files\n const isImageUpload = this.uploadDir?.includes?.(\"/images\");\n if (isImageUpload) {\n data = await Promise.all(\n req.files.map((file) => processImage(req, file.path, options))\n );\n } else {\n data = await Promise.all(\n req.files.map((file) => processFile(req, file.path))\n );\n }\n // Filter out any null values from failed processing\n data = data.filter((url) => url !== null);\n } else if (req.file) {\n // Process a single file\n const isImageUpload = this.uploadDir?.includes?.(\"/images\");\n if (isImageUpload) {\n data = await processImage(req, req.file.path, options);\n } else {\n data = await processFile(req, req.file.path);\n }\n } else {\n return reject(new AppError(\"No file uploaded\", 400));\n }\n\n resolve(data);\n } catch (error) {\n reject(error);\n }\n });\n });\n }\n\n /**\n * Deletes a file based on filename and file type from request parameters\n * @param {string} fileName - The name of the file to delete\n * @param {ArkosRequest} req - Arkos request object containing params.fileType\n * @returns {Promise<boolean>} - True if deletion successful, false otherwise\n */\n public async deleteFileByName(\n fileName: string,\n fileType: \"images\" | \"videos\" | \"documents\" | \"files\"\n ): Promise<boolean> {\n try {\n if (!fileType) throw new AppError(\"File type parameter is required\", 400);\n\n // Validate file type\n const validFileTypes = [\"images\", \"videos\", \"documents\", \"files\"];\n if (!validFileTypes.includes(fileType)) {\n throw new AppError(\n `Invalid file type: ${fileType}. Must be one of: ${validFileTypes.join(\n \", \"\n )}`,\n 400\n );\n }\n\n // Get the appropriate uploader service based on file type\n const {\n documentUploadService,\n fileUploadService,\n imageUploadService,\n videoUploadService,\n } = getFileUploadServices();\n\n let targetService: FileUploadService;\n switch (fileType) {\n case \"images\":\n targetService = imageUploadService;\n break;\n case \"videos\":\n targetService = videoUploadService;\n break;\n case \"documents\":\n targetService = documentUploadService;\n break;\n case \"files\":\n targetService = fileUploadService;\n break;\n default:\n throw new AppError(`Unsupported file type: ${fileType}`, 400);\n }\n\n // Construct the full file path\n const filePath = path.join(targetService.uploadDir, fileName);\n\n // Check if file exists and delete it\n await promisify(fs.stat)(filePath);\n await promisify(fs.unlink)(filePath);\n\n return true;\n } catch (error: any) {\n if (error instanceof AppError) {\n throw error;\n }\n\n if (error.code === \"ENOENT\") {\n throw new AppError(\"File not found\", 404);\n }\n\n throw new AppError(`Failed to delete file: ${error.message}`, 500);\n }\n }\n}\n\n/**\n * Creates and returns all file uploader services based on config\n * @returns Object containing all specialized file uploader services\n */\nexport const getFileUploadServices = () => {\n const { fileUpload } = getArkosConfig();\n const baseUploadDir = fileUpload?.baseUploadDir || \"/uploads\";\n\n // Default upload restrictions\n const defaultRestrictions = {\n images: {\n maxCount: 30,\n maxSize: 1024 * 1024 * 15, // 15 MB\n supportedFilesRegex:\n /jpeg|jpg|png|gif|webp|svg|bmp|tiff|heif|heic|ico|jfif|raw|cr2|nef|orf|sr2|arw|dng|pef|raf|rw2|psd|ai|eps|xcf|jxr|wdp|hdp|jp2|j2k|jpf|jpx|jpm|mj2|avif/,\n },\n videos: {\n maxCount: 10,\n maxSize: 1024 * 1024 * 5096, // 5 GB\n supportedFilesRegex:\n /mp4|avi|mov|mkv|flv|wmv|webm|mpg|mpeg|3gp|m4v|ts|rm|rmvb|vob|ogv|dv|qt|asf|m2ts|mts|divx|f4v|swf|mxf|roq|nsv|mvb|svi|mpe|m2v|mp2|mpv|h264|h265|hevc/,\n },\n documents: {\n maxCount: 30,\n maxSize: 1024 * 1024 * 50, // 50 MB\n supportedFilesRegex:\n /pdf|doc|docx|xls|xlsx|ppt|pptx|odt|ods|odg|odp|txt|rtf|csv|epub|md|tex|pages|numbers|key|xml|json|yaml|yml|ini|cfg|conf|log|html|htm|xhtml|djvu|mobi|azw|azw3|fb2|lit|ps|wpd|wps|dot|dotx|xlt|xltx|pot|potx|oft|one|onetoc2|opf|oxps|hwp/,\n },\n files: {\n maxCount: 10,\n maxSize: 1024 * 1024 * 5096, // 5 GB\n supportedFilesRegex: /.*/,\n },\n };\n\n // Merge with user configuration (if any)\n const restrictions = fileUpload?.restrictions\n ? deepmerge(defaultRestrictions, fileUpload.restrictions)\n : defaultRestrictions;\n\n /**\n * Specialized file uploader service for handling image uploads.\n */\n const imageUploadService = new FileUploadService(\n `${baseUploadDir}/images`,\n restrictions.images.maxSize,\n restrictions.images.supportedFilesRegex,\n restrictions.images.maxCount\n );\n\n /**\n * Specialized file uploader service for handling video uploads.\n */\n const videoUploadService = new FileUploadService(\n `${baseUploadDir}/videos`,\n restrictions.videos.maxSize,\n restrictions.videos.supportedFilesRegex,\n restrictions.videos.maxCount\n );\n\n /**\n * Specialized file uploader service for handling document uploads.\n */\n const documentUploadService = new FileUploadService(\n `${baseUploadDir}/documents`,\n restrictions.documents.maxSize,\n restrictions.documents.supportedFilesRegex,\n restrictions.documents.maxCount\n );\n\n /**\n * Generic file uploader service for handling all file uploads.\n */\n const fileUploadService = new FileUploadService(\n `${baseUploadDir}/files`,\n restrictions.files.maxSize,\n restrictions.files.supportedFilesRegex,\n restrictions.files.maxCount\n );\n\n return {\n imageUploadService,\n videoUploadService,\n documentUploadService,\n fileUploadService,\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"file-upload.service.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.service.ts"],"names":[],"mappings":"AAAA,OAAO,MAAyB,MAAM,QAAQ,CAAC;AAC/C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,QAAQ,MAAM,kCAAkC,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAMrE,MAAM,OAAO,iBAAiB;IAa5B,YACE,SAAiB,EACjB,gBAAwB,IAAI,GAAG,IAAI,GAAG,CAAC,EACvC,mBAA2B,IAAI,EAC/B,WAAmB,EAAE;QA8Bf,eAAU,GAAG,CAAC,CAAM,EAAE,IAAS,EAAE,EAAO,EAAE,EAAE;YAClD,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CACxC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAC9C,CAAC;YACF,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAE3D,IAAI,QAAQ,IAAI,OAAO,EAAE,CAAC;gBACxB,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACjB,CAAC;iBAAM,CAAC;gBACN,EAAE,CAAC,IAAI,QAAQ,CAAC,mBAAmB,EAAE,GAAG,CAAC,C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AE,EAAE;YACZ,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI;YAC3B,mBAAmB,EAAE,IAAI;SAC1B;KACF,CAAC;IAGF,MAAM,YAAY,GAAG,UAAU,EAAE,YAAY;QAC3C,CAAC,CAAC,SAAS,CAAC,mBAAmB,EAAE,UAAU,CAAC,YAAY,CAAC;QACzD,CAAC,CAAC,mBAAmB,CAAC;IAKxB,MAAM,kBAAkB,GAAG,IAAI,iBAAiB,CAC9C,GAAG,aAAa,SAAS,EACzB,YAAY,CAAC,MAAM,CAAC,OAAO,EAC3B,YAAY,CAAC,MAAM,CAAC,mBAAmB,EACvC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAC7B,CAAC;IAKF,MAAM,kBAAkB,GAAG,IAAI,iBAAiB,CAC9C,GAAG,aAAa,SAAS,EACzB,YAAY,CAAC,MAAM,CAAC,OAAO,EAC3B,YAAY,CAAC,MAAM,CAAC,mBAAmB,EACvC,YAAY,CAAC,MAAM,CAAC,QAAQ,CAC7B,CAAC;IAKF,MAAM,qBAAqB,GAAG,IAAI,iBAAiB,CACjD,GAAG,aAAa,YAAY,EAC5B,YAAY,CAAC,SAAS,CAAC,OAAO,EAC9B,YAAY,CAAC,SAAS,CAAC,mBAAmB,EAC1C,YAAY,CAAC,SAAS,CAAC,QAAQ,CAChC,CAAC;IAKF,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAC7C,GAAG,aAAa,QAAQ,EACxB,YAAY,CAAC,KAAK,CAAC,OAAO,EAC1B,YAAY,CAAC,KAAK,CAAC,mBAAmB,EACtC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAC5B,CAAC;IAEF,OAAO;QACL,kBAAkB;QAClB,kBAAkB;QAClB,qBAAqB;QACrB,iBAAiB;KAClB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import multer, { StorageEngine } from \"multer\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { NextFunction } from \"express\";\nimport AppError from \"../error-handler/utils/app-error\";\nimport { promisify } from \"util\";\nimport { getArkosConfig } from \"../../server\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { ArkosRequest, ArkosRequestHandler, ArkosResponse } from \"../../types\";\nimport { processFile, processImage } from \"./utils/helpers/file-upload.helpers\";\nimport { removeBothSlashes } from \"../../utils/helpers/text.helpers\";\n\n/**\n * Service to handle file uploads, including single and multiple file uploads,\n * file validation (type, size), and file deletion.\n */\nexport class FileUploadService {\n public readonly uploadDir: string;\n private fileSizeLimit: number;\n private allowedFileTypes: RegExp;\n private storage: StorageEngine;\n private maxCount: number;\n\n /**\n * Constructor to initialize the file uploader service.\n * @param {string} uploadDir - The directory where files will be uploaded.\n * @param {number} fileSizeLimit - The maximum allowed file size.\n * @param {RegExp} allowedFileTypes - The regular expression for allowed file types.\n */\n constructor(\n uploadDir: string,\n fileSizeLimit: number = 1024 * 1024 * 5,\n allowedFileTypes: RegExp = /.*/,\n maxCount: number = 30\n ) {\n uploadDir = uploadDir.startsWith(\"/\") ? uploadDir.substring(1) : uploadDir;\n uploadDir = uploadDir.endsWith(\"/\") ? uploadDir.slice(0, -1) : uploadDir;\n\n this.uploadDir = path.resolve(process.cwd(), `${uploadDir}/`);\n this.fileSizeLimit = fileSizeLimit;\n this.allowedFileTypes = allowedFileTypes;\n this.maxCount = maxCount;\n\n if (!fs.existsSync(this.uploadDir)) {\n fs.mkdirSync(this.uploadDir, { recursive: true });\n }\n\n this.storage = multer.diskStorage({\n destination: (_, _1, cb) => {\n cb(null, this.uploadDir);\n },\n filename: (_, file, cb) => {\n const uniqueSuffix = Date.now() + \"-\" + Math.round(Math.random() * 1e9);\n cb(null, `${uniqueSuffix}${path.extname(file.originalname)}`);\n },\n });\n }\n\n /**\n * Validates the file's type and MIME type.\n * @param {Express.Multer.File} file - The uploaded file.\n * @param {Function} cb - The callback function to indicate if file is valid.\n */\n private fileFilter = (_: any, file: any, cb: any) => {\n const extName = this.allowedFileTypes.test(\n path.extname(file.originalname).toLowerCase()\n );\n const mimeType = this.allowedFileTypes.test(file.mimetype);\n\n if (mimeType && extName) {\n cb(null, true);\n } else {\n cb(new AppError(\"Invalid file type\", 400));\n }\n };\n\n /**\n * Returns the multer upload configuration.\n * @returns {multer.Multer} The multer instance configured for file uploads.\n */\n public getUpload(): multer.Multer {\n return multer({\n storage: this.storage,\n fileFilter: this.fileFilter,\n limits: { fileSize: this.fileSizeLimit },\n });\n }\n\n /**\n * Middleware to handle single file upload.\n * @param {string} [oldFilePath] - The path to the file to delete before uploading.\n * @returns {Function} Middleware function for handling file upload.\n */\n public handleSingleUpload(oldFilePath?: string): ArkosRequestHandler {\n return (req: ArkosRequest, res: ArkosResponse, next: NextFunction) => {\n const upload = this.getUpload().single(this.getFieldName());\n upload(req, res, async (err) => {\n if (err instanceof multer.MulterError) {\n return next(err);\n } else if (err) {\n return next(err);\n }\n\n if (oldFilePath) {\n const { fileUpload: configs } = getArkosConfig();\n\n const filePath = path.resolve(\n process.cwd(),\n removeBothSlashes(configs?.baseUploadDir!),\n removeBothSlashes(oldFilePath)\n );\n try {\n const stats = await promisify(fs.stat)(filePath);\n if (stats) await promisify(fs.unlink)(filePath);\n } catch (err) {\n console.error(err);\n }\n }\n\n next();\n });\n };\n }\n\n /**\n * Middleware to handle multiple file uploads.\n * @returns {Function} Middleware function for handling multiple file uploads.\n */\n public handleMultipleUpload(): ArkosRequestHandler {\n return (req: ArkosRequest, res: ArkosResponse, next: NextFunction) => {\n const upload = this.getUpload().array(this.getFieldName(), this.maxCount);\n upload(req, res, (err) => {\n if (err instanceof multer.MulterError) return next(err);\n else if (err) return next(err);\n next();\n });\n };\n }\n\n /**\n * Middleware to handle deletion of a single file from the filesystem.\n * @param {string} oldFilePath - The path to the file to be deleted.\n * @returns {Function} Middleware function for handling file deletion.\n */\n public handleDeleteSingleFile(oldFilePath: string): ArkosRequestHandler {\n return async (_: ArkosRequest, _1: ArkosResponse, next: NextFunction) => {\n const filePath = path.join(oldFilePath);\n try {\n const stats = await promisify(fs.stat)(filePath);\n if (stats) {\n await promisify(fs.unlink)(filePath);\n }\n } catch (err) {\n console.error(err);\n }\n\n next();\n };\n }\n\n /**\n * Deletes a file based on its URL by identifying the appropriate uploader service\n * @param {string} fileUrl - The URL of the file to delete\n * @returns {Promise<boolean>} - True if deletion successful, false otherwise\n */\n public async deleteFileByUrl(fileUrl: string): Promise<boolean> {\n try {\n // Get configuration values\n const { fileUpload } = getArkosConfig();\n const baseRoute = fileUpload?.baseRoute || \"/api/uploads\";\n\n // Parse the URL to get the path\n let urlPath: string;\n if (fileUrl.startsWith(\"http\")) {\n const url = new URL(fileUrl);\n urlPath = url.pathname;\n } else {\n urlPath = fileUrl;\n }\n\n // Extract the path after the base route\n const baseRouteIndex = urlPath.indexOf(baseRoute);\n if (baseRouteIndex === -1) {\n throw new AppError(\"Invalid file URL: base route not found\", 400);\n }\n\n const pathAfterBaseRoute = urlPath.substring(\n baseRouteIndex + baseRoute.length\n );\n const cleanPath = pathAfterBaseRoute.startsWith(\"/\")\n ? pathAfterBaseRoute.substring(1)\n : pathAfterBaseRoute;\n\n // Determine file type and file name\n const fileTypes = [\"images\", \"videos\", \"documents\", \"files\"];\n let fileType: string | null = null;\n let fileName: string | null = null;\n\n for (const type of fileTypes) {\n const typeIndex = cleanPath.indexOf(type + \"/\");\n if (typeIndex !== -1) {\n fileType = type;\n fileName = cleanPath.substring(typeIndex + type.length + 1);\n break;\n }\n }\n\n if (!fileType || !fileName) {\n throw new AppError(\n \"Unable to determine file type or file name from URL\",\n 400\n );\n }\n\n // Get the appropriate uploader service based on file type\n const {\n documentUploadService,\n fileUploadService,\n imageUploadService,\n videoUploadService,\n } = getFileUploadServices();\n\n let filePath: string;\n switch (fileType) {\n case \"images\":\n filePath = path.join(imageUploadService.uploadDir, fileName);\n break;\n case \"videos\":\n filePath = path.join(videoUploadService.uploadDir, fileName);\n break;\n case \"documents\":\n filePath = path.join(documentUploadService.uploadDir, fileName);\n break;\n case \"files\":\n filePath = path.join(fileUploadService.uploadDir, fileName);\n break;\n default:\n throw new AppError(`Unsupported file type: ${fileType}`, 400);\n }\n\n // Delete the file\n\n await promisify(fs.stat)(filePath);\n await promisify(fs.unlink)(filePath);\n\n return true;\n } catch (error: any) {\n if (error instanceof AppError) {\n throw error;\n }\n\n if (error.code === \"ENOENT\") {\n throw new AppError(\"File not found\", 404);\n }\n\n throw new AppError(`Failed to delete file: ${error.message}`, 500);\n }\n }\n\n private getFieldName() {\n let fieldName = \"files\";\n if (this.uploadDir.endsWith(\"images\") || this.uploadDir.endsWith(\"images/\"))\n fieldName = \"images\";\n if (this.uploadDir.endsWith(\"videos\") || this.uploadDir.endsWith(\"videos/\"))\n fieldName = \"videos\";\n if (\n this.uploadDir.endsWith(\"documents\") ||\n this.uploadDir.endsWith(\"documents/\")\n )\n fieldName = \"documents\";\n if (this.uploadDir.endsWith(\"files\") || this.uploadDir.endsWith(\"files/\"))\n fieldName = \"files\";\n return fieldName;\n }\n\n /**\n * Handles the upload process and returns the full URLs of uploaded files\n * @param {ArkosRequest} req - Arkos request object containing the files\n * @param {ArkosResponse} res - Arkos response object\n * @param {object} options - Optional parameters for image processing\n * @returns {Promise<string|string[]>} URL or array of URLs to the uploaded files\n */\n public async upload(\n req: ArkosRequest,\n res: ArkosResponse,\n options: {\n format?: string;\n width?: number;\n height?: number;\n resizeTo?: number;\n } = {}\n ): Promise<string | string[] | null> {\n const { fileUpload } = getArkosConfig();\n fileUpload?.baseRoute || \"/api/uploads\";\n\n return new Promise((resolve, reject) => {\n // Determine if it's a single or multiple file upload\n const isMultiple = Array.isArray(req.query.multiple)\n ? req.query.multiple[0] == \"true\"\n : req.query.multiple == \"true\";\n\n // Use appropriate upload handler\n const uploadHandler = isMultiple\n ? this.getUpload().array(this.getFieldName(), this.maxCount)\n : this.getUpload().single(this.getFieldName());\n\n uploadHandler(req, res, async (err) => {\n if (err) return reject(err);\n\n try {\n // Determine the base URL for file access\n const protocol = req.get(\"host\")?.includes?.(\"localhost\")\n ? \"http\"\n : \"https\";\n `${protocol}://${req.get(\"host\")}`;\n\n // Get file type from uploadDir path\n const dirParts = this.uploadDir.split(\"/\");\n (this.uploadDir.endsWith(\"/\")\n ? dirParts[dirParts.length - 2]\n : dirParts[dirParts.length - 1]) || \"files\";\n\n // Process all uploaded files\n let data;\n if (req.files && Array.isArray(req.files) && req.files.length > 0) {\n // Process multiple files\n const isImageUpload = this.uploadDir?.includes?.(\"/images\");\n if (isImageUpload) {\n data = await Promise.all(\n req.files.map((file) => processImage(req, file.path, options))\n );\n } else {\n data = await Promise.all(\n req.files.map((file) => processFile(req, file.path))\n );\n }\n // Filter out any null values from failed processing\n data = data.filter((url) => url !== null);\n } else if (req.file) {\n // Process a single file\n const isImageUpload = this.uploadDir?.includes?.(\"/images\");\n if (isImageUpload) {\n data = await processImage(req, req.file.path, options);\n } else {\n data = await processFile(req, req.file.path);\n }\n } else {\n return reject(new AppError(\"No file uploaded\", 400));\n }\n\n resolve(data);\n } catch (error) {\n reject(error);\n }\n });\n });\n }\n\n /**\n * Deletes a file based on filename and file type from request parameters\n * @param {string} fileName - The name of the file to delete\n * @returns {Promise<boolean>} - True if deletion successful, false otherwise\n */\n public async deleteFileByName(\n fileName: string,\n fileType: \"images\" | \"videos\" | \"documents\" | \"files\"\n ): Promise<boolean> {\n try {\n if (!fileType) throw new AppError(\"File type parameter is required\", 400);\n\n // Validate file type\n const validFileTypes = [\"images\", \"videos\", \"documents\", \"files\"];\n if (!validFileTypes.includes(fileType)) {\n throw new AppError(\n `Invalid file type: ${fileType}. Must be one of: ${validFileTypes.join(\n \", \"\n )}`,\n 400\n );\n }\n\n // Get the appropriate uploader service based on file type\n const {\n documentUploadService,\n fileUploadService,\n imageUploadService,\n videoUploadService,\n } = getFileUploadServices();\n\n let targetService: FileUploadService;\n switch (fileType) {\n case \"images\":\n targetService = imageUploadService;\n break;\n case \"videos\":\n targetService = videoUploadService;\n break;\n case \"documents\":\n targetService = documentUploadService;\n break;\n case \"files\":\n targetService = fileUploadService;\n break;\n default:\n throw new AppError(`Unsupported file type: ${fileType}`, 400);\n }\n\n // Construct the full file path\n const filePath = path.join(targetService.uploadDir, fileName);\n\n // Check if file exists and delete it\n await promisify(fs.stat)(filePath);\n await promisify(fs.unlink)(filePath);\n\n return true;\n } catch (error: any) {\n if (error instanceof AppError) {\n throw error;\n }\n\n if (error.code === \"ENOENT\") {\n throw new AppError(\"File not found\", 404);\n }\n\n throw new AppError(`Failed to delete file: ${error.message}`, 500);\n }\n }\n}\n\n/**\n * Creates and returns all file uploader services based on config\n * @returns Object containing all specialized file uploader services\n */\nexport const getFileUploadServices = () => {\n const { fileUpload } = getArkosConfig();\n const baseUploadDir = fileUpload?.baseUploadDir || \"/uploads\";\n\n // Default upload restrictions\n const defaultRestrictions = {\n images: {\n maxCount: 30,\n maxSize: 1024 * 1024 * 15, // 15 MB\n supportedFilesRegex:\n /jpeg|jpg|png|gif|webp|svg|bmp|tiff|heif|heic|ico|jfif|raw|cr2|nef|orf|sr2|arw|dng|pef|raf|rw2|psd|ai|eps|xcf|jxr|wdp|hdp|jp2|j2k|jpf|jpx|jpm|mj2|avif/,\n },\n videos: {\n maxCount: 10,\n maxSize: 1024 * 1024 * 5096, // 5 GB\n supportedFilesRegex:\n /mp4|avi|mov|mkv|flv|wmv|webm|mpg|mpeg|3gp|m4v|ts|rm|rmvb|vob|ogv|dv|qt|asf|m2ts|mts|divx|f4v|swf|mxf|roq|nsv|mvb|svi|mpe|m2v|mp2|mpv|h264|h265|hevc/,\n },\n documents: {\n maxCount: 30,\n maxSize: 1024 * 1024 * 50, // 50 MB\n supportedFilesRegex:\n /pdf|doc|docx|xls|xlsx|ppt|pptx|odt|ods|odg|odp|txt|rtf|csv|epub|md|tex|pages|numbers|key|xml|json|yaml|yml|ini|cfg|conf|log|html|htm|xhtml|djvu|mobi|azw|azw3|fb2|lit|ps|wpd|wps|dot|dotx|xlt|xltx|pot|potx|oft|one|onetoc2|opf|oxps|hwp/,\n },\n files: {\n maxCount: 10,\n maxSize: 1024 * 1024 * 5096, // 5 GB\n supportedFilesRegex: /.*/,\n },\n };\n\n // Merge with user configuration (if any)\n const restrictions = fileUpload?.restrictions\n ? deepmerge(defaultRestrictions, fileUpload.restrictions)\n : defaultRestrictions;\n\n /**\n * Specialized file uploader service for handling image uploads.\n */\n const imageUploadService = new FileUploadService(\n `${baseUploadDir}/images`,\n restrictions.images.maxSize,\n restrictions.images.supportedFilesRegex,\n restrictions.images.maxCount\n );\n\n /**\n * Specialized file uploader service for handling video uploads.\n */\n const videoUploadService = new FileUploadService(\n `${baseUploadDir}/videos`,\n restrictions.videos.maxSize,\n restrictions.videos.supportedFilesRegex,\n restrictions.videos.maxCount\n );\n\n /**\n * Specialized file uploader service for handling document uploads.\n */\n const documentUploadService = new FileUploadService(\n `${baseUploadDir}/documents`,\n restrictions.documents.maxSize,\n restrictions.documents.supportedFilesRegex,\n restrictions.documents.maxCount\n );\n\n /**\n * Generic file uploader service for handling all file uploads.\n */\n const fileUploadService = new FileUploadService(\n `${baseUploadDir}/files`,\n restrictions.files.maxSize,\n restrictions.files.supportedFilesRegex,\n restrictions.files.maxCount\n );\n\n return {\n imageUploadService,\n videoUploadService,\n documentUploadService,\n fileUploadService,\n };\n};\n"]}
|
|
@@ -1,87 +1 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import sharp from "sharp";
|
|
4
|
-
import { promisify } from "util";
|
|
5
|
-
import { getArkosConfig } from "../../../../server.js";
|
|
6
|
-
import mimetype from "mimetype";
|
|
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
|
-
}
|
|
14
|
-
export function extractRequestInfo(req) {
|
|
15
|
-
const { fileUpload } = getArkosConfig();
|
|
16
|
-
const protocol = req.headers["x-forwarded-proto"] === "https" ? "https" : "http";
|
|
17
|
-
const baseURL = `${protocol}://${req.get?.("host")}`;
|
|
18
|
-
const baseRoute = fileUpload?.baseRoute || "/api/uploads";
|
|
19
|
-
return { baseURL, baseRoute };
|
|
20
|
-
}
|
|
21
|
-
const generateRelativePath = (filePath, fileType) => {
|
|
22
|
-
const { fileUpload } = getArkosConfig();
|
|
23
|
-
const baseUploadDir = fileUpload?.baseUploadDir || "/uploads";
|
|
24
|
-
if (baseUploadDir.startsWith("..")) {
|
|
25
|
-
return path.join(fileType, path.basename(filePath));
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return fullCleanCwd(filePath
|
|
29
|
-
.replace(`${baseUploadDir}/`, "")
|
|
30
|
-
.replace(`/${baseUploadDir}/`, "")
|
|
31
|
-
.replace(`/${baseUploadDir}`, "")
|
|
32
|
-
.replace(`${baseUploadDir}`, ""));
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
export const processFile = async (req, filePath) => {
|
|
36
|
-
const { baseURL, baseRoute } = extractRequestInfo(req);
|
|
37
|
-
const relativePath = generateRelativePath(filePath, req.params.fileType);
|
|
38
|
-
return `${baseURL}${baseRoute === "/" ? "" : baseRoute}/${relativePath}`;
|
|
39
|
-
};
|
|
40
|
-
export const processImage = async (req, filePath, options) => {
|
|
41
|
-
const { baseURL, baseRoute } = extractRequestInfo(req);
|
|
42
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
43
|
-
const originalFormat = ext.replace(".", "");
|
|
44
|
-
const outputFormat = options.format || originalFormat;
|
|
45
|
-
if (!mimetype.lookup(ext)?.includes?.("image")) {
|
|
46
|
-
const relativePath = generateRelativePath(filePath, req.params.fileType);
|
|
47
|
-
return `${baseURL}${baseRoute}/${relativePath}`;
|
|
48
|
-
}
|
|
49
|
-
const tempName = `${path.basename(filePath, ext)}_${Date.now()}${ext}`;
|
|
50
|
-
const tempPath = path.join(path.dirname(filePath), tempName);
|
|
51
|
-
try {
|
|
52
|
-
let transformer = sharp(filePath);
|
|
53
|
-
const metadata = await transformer.metadata();
|
|
54
|
-
if (options.resizeTo && metadata.width && metadata.height) {
|
|
55
|
-
const targetSize = options.resizeTo;
|
|
56
|
-
const scaleFactor = targetSize / Math.min(metadata.width, metadata.height);
|
|
57
|
-
const newWidth = Math.round(metadata.width * scaleFactor);
|
|
58
|
-
const newHeight = Math.round(metadata.height * scaleFactor);
|
|
59
|
-
transformer = transformer.resize(newWidth, newHeight);
|
|
60
|
-
}
|
|
61
|
-
else if (options.width || options.height) {
|
|
62
|
-
transformer = transformer.resize(options.width || null, options.height || null, {
|
|
63
|
-
fit: "inside",
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
if (outputFormat === "webp") {
|
|
67
|
-
transformer = transformer.toFormat("webp");
|
|
68
|
-
}
|
|
69
|
-
else if (outputFormat === "jpeg" || outputFormat === "jpg") {
|
|
70
|
-
transformer = transformer.toFormat("jpeg");
|
|
71
|
-
}
|
|
72
|
-
await transformer.toFile(tempPath);
|
|
73
|
-
await promisify(fs.rename)(tempPath, filePath);
|
|
74
|
-
const relativePath = generateRelativePath(filePath, req?.params.fileType);
|
|
75
|
-
return `${baseURL}${baseRoute}/${relativePath}`;
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
try {
|
|
79
|
-
await promisify(fs.stat)(tempPath);
|
|
80
|
-
await promisify(fs.unlink)(tempPath);
|
|
81
|
-
}
|
|
82
|
-
catch (err) {
|
|
83
|
-
}
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=file-upload.helpers.js.map
|
|
1
|
+
"use strict";import m from"fs";import n from"path";import y from"sharp";import{promisify as u}from"util";import{getArkosConfig as h}from"../../../../server.js";import U from"mimetype";import{fullCleanCwd as x}from"../../../../utils/helpers/fs.helpers.js";export function adjustRequestUrl(t,a,o){const{fileUpload:e}=h();t.url=t.url.replace(e?.baseRoute+"/"||"/api/uploads/","/"),t.url=t.url.replace(e?.baseRoute||"/api/uploads/","/"),o()}export function extractRequestInfo(t){const{fileUpload:a}=h(),e=`${t.headers["x-forwarded-proto"]==="https"?"https":"http"}://${t.get?.("host")}`,i=a?.baseRoute||"/api/uploads";return{baseURL:e,baseRoute:i}}const d=(t,a)=>{const{fileUpload:o}=h(),e=o?.baseUploadDir||"/uploads";return e.startsWith("..")?n.join(a,n.basename(t)):x(t.replace(`${e}/`,"").replace(`/${e}/`,"").replace(`/${e}`,"").replace(`${e}`,""))};export const processFile=async(t,a)=>{const{baseURL:o,baseRoute:e}=extractRequestInfo(t),i=d(a,t.params.fileType);return`${o}${e==="/"?"":e}/${i}`},processImage=async(t,a,o)=>{const{baseURL:e,baseRoute:i}=extractRequestInfo(t),p=n.extname(a).toLowerCase(),w=p.replace(".",""),l=o.format||w;if(!U.lookup(p)?.includes?.("image")){const r=d(a,t.params.fileType);return`${e}${i}/${r}`}const g=`${n.basename(a,p)}_${Date.now()}${p}`,c=n.join(n.dirname(a),g);try{let r=y(a);const s=await r.metadata();if(o.resizeTo&&s.width&&s.height){const f=o.resizeTo/Math.min(s.width,s.height),b=Math.round(s.width*f),R=Math.round(s.height*f);r=r.resize(b,R)}else(o.width||o.height)&&(r=r.resize(o.width||null,o.height||null,{fit:"inside"}));l==="webp"?r=r.toFormat("webp"):(l==="jpeg"||l==="jpg")&&(r=r.toFormat("jpeg")),await r.toFile(c),await u(m.rename)(c,a);const $=d(a,t?.params.fileType);return`${e}${i}/${$}`}catch(r){try{await u(m.stat)(c),await u(m.unlink)(c)}catch{}throw r}};
|
|
@@ -1,93 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import swaggerUi from "swagger-ui-express";
|
|
3
|
-
import swaggerJsdoc from "swagger-jsdoc";
|
|
4
|
-
import deepmerge from "../../utils/helpers/deepmerge.helper.js";
|
|
5
|
-
import { generatePathsForModels, getOpenAPIJsonSchemasByConfigMode, } from "./utils/helpers/swagger.router.helpers.js";
|
|
6
|
-
const swaggerRouter = Router();
|
|
7
|
-
export async function getSwaggerRouter(arkosConfig) {
|
|
8
|
-
const defaultJsonSchemas = await getOpenAPIJsonSchemasByConfigMode(arkosConfig.swagger);
|
|
9
|
-
const defaultModelsPaths = await generatePathsForModels(arkosConfig);
|
|
10
|
-
const defaultSwaggerConfig = {
|
|
11
|
-
endpoint: "/api-docs",
|
|
12
|
-
mode: "prisma",
|
|
13
|
-
options: {
|
|
14
|
-
definition: {
|
|
15
|
-
openapi: "3.0.0",
|
|
16
|
-
info: {
|
|
17
|
-
title: "Powered By Arkos.js",
|
|
18
|
-
version: "1.0.0",
|
|
19
|
-
description: "This API was automatically generated by Arkos.js, read more about at www.arkosjs.com",
|
|
20
|
-
},
|
|
21
|
-
servers: [
|
|
22
|
-
{
|
|
23
|
-
url: `http://${arkosConfig.host}:${arkosConfig.port}`,
|
|
24
|
-
description: "Development server",
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
paths: defaultModelsPaths,
|
|
28
|
-
components: {
|
|
29
|
-
schemas: defaultJsonSchemas || {},
|
|
30
|
-
securitySchemes: {
|
|
31
|
-
BearerAuth: {
|
|
32
|
-
type: "http",
|
|
33
|
-
scheme: "bearer",
|
|
34
|
-
bearerFormat: "JWT",
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
security: [],
|
|
39
|
-
},
|
|
40
|
-
apis: [
|
|
41
|
-
"./src/routers/*.router.{ts,js}",
|
|
42
|
-
"./src/modules/**/*.router.{ts,js}",
|
|
43
|
-
],
|
|
44
|
-
swaggerUiOptions: {
|
|
45
|
-
explorer: true,
|
|
46
|
-
swaggerOptions: {
|
|
47
|
-
filter: true,
|
|
48
|
-
displayRequestDuration: true,
|
|
49
|
-
showExtensions: true,
|
|
50
|
-
showCommonExtensions: true,
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
deepLinking: true,
|
|
54
|
-
tryItOutEnabled: true,
|
|
55
|
-
persistAuthorization: false,
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
const swaggerConfigs = deepmerge(defaultSwaggerConfig, arkosConfig.swagger || {});
|
|
59
|
-
if (swaggerConfigs?.options?.definition?.components?.schemas) {
|
|
60
|
-
swaggerConfigs.options.definition.components.schemas = {
|
|
61
|
-
...swaggerConfigs?.options?.definition?.components.schemas,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
const swaggerSpecification = swaggerJsdoc({
|
|
65
|
-
definition: swaggerConfigs.options
|
|
66
|
-
.definition,
|
|
67
|
-
apis: swaggerConfigs.options.apis || [],
|
|
68
|
-
});
|
|
69
|
-
const swaggerUiOptions = {
|
|
70
|
-
explorer: swaggerConfigs.options.swaggerUiOptions?.explorer ?? true,
|
|
71
|
-
customCss: swaggerConfigs.options.swaggerUiOptions?.customCss,
|
|
72
|
-
customSiteTitle: swaggerConfigs.options.swaggerUiOptions?.customSiteTitle ||
|
|
73
|
-
"Arkos.js API Documentation",
|
|
74
|
-
customfavIcon: swaggerConfigs.options.swaggerUiOptions?.customfavIcon,
|
|
75
|
-
swaggerOptions: {
|
|
76
|
-
filter: swaggerConfigs.options.swaggerUiOptions?.swaggerOptions?.filter ?? true,
|
|
77
|
-
displayRequestDuration: swaggerConfigs.options.swaggerUiOptions?.swaggerOptions
|
|
78
|
-
?.displayRequestDuration ?? true,
|
|
79
|
-
deepLinking: swaggerConfigs.options.deepLinking ?? true,
|
|
80
|
-
tryItOutEnabled: swaggerConfigs.options.tryItOutEnabled ?? true,
|
|
81
|
-
persistAuthorization: swaggerConfigs.options.persistAuthorization ?? false,
|
|
82
|
-
showExtensions: swaggerConfigs.options.swaggerUiOptions?.swaggerOptions
|
|
83
|
-
?.showExtensions ?? true,
|
|
84
|
-
showCommonExtensions: swaggerConfigs.options.swaggerUiOptions?.swaggerOptions
|
|
85
|
-
?.showCommonExtensions ?? true,
|
|
86
|
-
...swaggerConfigs.options.swaggerUiOptions?.swaggerOptions,
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
swaggerRouter.use(swaggerConfigs.endpoint, swaggerUi.serve);
|
|
90
|
-
swaggerRouter.get(swaggerConfigs.endpoint, swaggerUi.setup(swaggerSpecification, swaggerUiOptions));
|
|
91
|
-
return swaggerRouter;
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=swagger.router.js.map
|
|
1
|
+
"use strict";import{Router as g}from"express";import c from"swagger-jsdoc";import p from"../../utils/helpers/deepmerge.helper.js";import{generatePathsForModels as f,getOpenAPIJsonSchemasByConfigMode as w}from"./utils/helpers/swagger.router.helpers.js";import d from"./utils/helpers/missing-json-schemas-generator.js";import u from"./utils/helpers/get-swagger-default-configs.js";import{importEsmPreventingTsTransformation as l}from"../../utils/helpers/global.helpers.js";import S from"./utils/helpers/json-schema-generators/generate-system-json-schemas.js";const n=g();export async function getSwaggerRouter(e){let t=await w(e);const r=await f(e);t={...t,...await d.generateMissingJsonSchemas(r,t,e),...S(e)};const o=p(await u(r,t)||{},e.swagger||{}),{definition:a,...s}=o?.options,i=c({definition:a,...s}),m=await l("@scalar/express-api-reference");return n.use(o.endpoint,m.apiReference({content:i,...o?.scalarApiReferenceConfiguration})),n}
|
|
@@ -1 +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,
|
|
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,YAAY,MAAM,eAAe,CAAC;AAEzC,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAC7D,OAAO,EACL,sBAAsB,EACtB,iCAAiC,GAClC,MAAM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";\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\";\nimport missingJsonSchemaGenerator from \"./utils/helpers/missing-json-schemas-generator\";\nimport getSwaggerDefaultConfig from \"./utils/helpers/get-swagger-default-configs\";\nimport { importEsmPreventingTsTransformation } from \"../../utils/helpers/global.helpers\";\nimport generateSystemJsonSchemas from \"./utils/helpers/json-schema-generators/generate-system-json-schemas\";\n\nconst swaggerRouter = Router();\n\nexport async function getSwaggerRouter(\n arkosConfig: ArkosConfig\n): Promise<Router> {\n let defaultJsonSchemas = await getOpenAPIJsonSchemasByConfigMode(arkosConfig);\n const defaultModelsPaths = await generatePathsForModels(arkosConfig);\n\n defaultJsonSchemas = {\n ...defaultJsonSchemas,\n ...(await missingJsonSchemaGenerator.generateMissingJsonSchemas(\n defaultModelsPaths,\n defaultJsonSchemas,\n arkosConfig\n )),\n ...generateSystemJsonSchemas(arkosConfig),\n };\n\n const swaggerConfigs = deepmerge(\n (await getSwaggerDefaultConfig(defaultModelsPaths, defaultJsonSchemas)) ||\n {},\n arkosConfig.swagger || {}\n ) as ArkosConfig[\"swagger\"];\n\n const { definition, ...options } = swaggerConfigs?.options!;\n\n const swaggerSpecification = swaggerJsdoc({\n definition: definition as swaggerJsdoc.SwaggerDefinition,\n ...options,\n });\n\n const scalar = await importEsmPreventingTsTransformation(\n \"@scalar/express-api-reference\"\n );\n\n swaggerRouter.use(\n swaggerConfigs!.endpoint!,\n scalar.apiReference({\n content: swaggerSpecification,\n ...swaggerConfigs?.scalarApiReferenceConfiguration,\n })\n );\n\n return swaggerRouter;\n}\n"]}
|
|
@@ -1,247 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getArkosConfig } from "../../../../server.js";
|
|
3
|
-
export function getAuthenticationJsonSchemaPaths() {
|
|
4
|
-
const mode = getArkosConfig().swagger?.mode;
|
|
5
|
-
const paths = {};
|
|
6
|
-
if (!mode)
|
|
7
|
-
return paths;
|
|
8
|
-
paths["/api/auth/login"] = {
|
|
9
|
-
post: {
|
|
10
|
-
tags: ["Authentication"],
|
|
11
|
-
summary: "Login to the system",
|
|
12
|
-
description: "Authenticates a user and returns an access token",
|
|
13
|
-
operationId: "login",
|
|
14
|
-
requestBody: {
|
|
15
|
-
description: "User credentials",
|
|
16
|
-
required: true,
|
|
17
|
-
content: {
|
|
18
|
-
"application/json": {
|
|
19
|
-
schema: {
|
|
20
|
-
$ref: getSchemaRef("Login", mode),
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
responses: {
|
|
26
|
-
"200": {
|
|
27
|
-
description: "Login successful",
|
|
28
|
-
content: {
|
|
29
|
-
"application/json": {
|
|
30
|
-
schema: {
|
|
31
|
-
type: "object",
|
|
32
|
-
properties: {
|
|
33
|
-
accessToken: {
|
|
34
|
-
type: "string",
|
|
35
|
-
description: "JWT access token",
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
"400": {
|
|
43
|
-
description: "Invalid input data",
|
|
44
|
-
},
|
|
45
|
-
"401": {
|
|
46
|
-
description: "Invalid credentials",
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
paths["/api/auth/logout"] = {
|
|
52
|
-
delete: {
|
|
53
|
-
tags: ["Authentication"],
|
|
54
|
-
summary: "Logout from the system",
|
|
55
|
-
description: "Invalidates the current user's JWT token",
|
|
56
|
-
operationId: "logout",
|
|
57
|
-
security: [{ BearerAuth: [] }],
|
|
58
|
-
responses: {
|
|
59
|
-
"204": {
|
|
60
|
-
description: "Logout successful",
|
|
61
|
-
},
|
|
62
|
-
"401": {
|
|
63
|
-
description: "Authentication required",
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
paths["/api/auth/signup"] = {
|
|
69
|
-
post: {
|
|
70
|
-
tags: ["Authentication"],
|
|
71
|
-
summary: "Register a new user",
|
|
72
|
-
description: "Creates a new user account",
|
|
73
|
-
operationId: "signup",
|
|
74
|
-
requestBody: {
|
|
75
|
-
description: "User registration data",
|
|
76
|
-
required: true,
|
|
77
|
-
content: {
|
|
78
|
-
"application/json": {
|
|
79
|
-
schema: {
|
|
80
|
-
$ref: getSchemaRef("Signup", mode),
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
responses: {
|
|
86
|
-
"201": {
|
|
87
|
-
description: "User created successfully",
|
|
88
|
-
content: {
|
|
89
|
-
"application/json": {
|
|
90
|
-
schema: {
|
|
91
|
-
$ref: getSchemaRef("User", mode),
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
"400": {
|
|
97
|
-
description: "Invalid input data",
|
|
98
|
-
},
|
|
99
|
-
"409": {
|
|
100
|
-
description: "User already exists",
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
paths["/api/auth/update-password"] = {
|
|
106
|
-
post: {
|
|
107
|
-
tags: ["Authentication"],
|
|
108
|
-
summary: "Update user password",
|
|
109
|
-
description: "Changes the password for the authenticated user",
|
|
110
|
-
operationId: "updatePassword",
|
|
111
|
-
security: [{ BearerAuth: [] }],
|
|
112
|
-
requestBody: {
|
|
113
|
-
description: "Current and new password",
|
|
114
|
-
required: true,
|
|
115
|
-
content: {
|
|
116
|
-
"application/json": {
|
|
117
|
-
schema: {
|
|
118
|
-
$ref: getSchemaRef("UpdatePassword", mode),
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
responses: {
|
|
124
|
-
"200": {
|
|
125
|
-
description: "Password updated successfully",
|
|
126
|
-
content: {
|
|
127
|
-
"application/json": {
|
|
128
|
-
schema: {
|
|
129
|
-
type: "object",
|
|
130
|
-
properties: {
|
|
131
|
-
status: {
|
|
132
|
-
type: "string",
|
|
133
|
-
example: "success",
|
|
134
|
-
},
|
|
135
|
-
message: {
|
|
136
|
-
type: "string",
|
|
137
|
-
example: "Password updated successfully!",
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
"400": {
|
|
145
|
-
description: "Invalid input data or current password incorrect",
|
|
146
|
-
},
|
|
147
|
-
"401": {
|
|
148
|
-
description: "Authentication required",
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
paths["/users/me"] = {
|
|
154
|
-
get: {
|
|
155
|
-
tags: ["Users"],
|
|
156
|
-
summary: "Get current user information",
|
|
157
|
-
description: "Retrieves information about the currently authenticated user",
|
|
158
|
-
operationId: "getCurrentUser",
|
|
159
|
-
security: [{ BearerAuth: [] }],
|
|
160
|
-
responses: {
|
|
161
|
-
"200": {
|
|
162
|
-
description: "User information retrieved successfully",
|
|
163
|
-
content: {
|
|
164
|
-
"application/json": {
|
|
165
|
-
schema: {
|
|
166
|
-
$ref: getSchemaRef("FindMe", mode),
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
"401": {
|
|
172
|
-
description: "Authentication required",
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
};
|
|
177
|
-
paths["/users/me"] = {
|
|
178
|
-
patch: {
|
|
179
|
-
tags: ["Users"],
|
|
180
|
-
summary: "Update current user information",
|
|
181
|
-
description: "Updates information for the currently authenticated user",
|
|
182
|
-
operationId: "updateCurrentUser",
|
|
183
|
-
security: [{ BearerAuth: [] }],
|
|
184
|
-
requestBody: {
|
|
185
|
-
description: "User data to update",
|
|
186
|
-
required: true,
|
|
187
|
-
content: {
|
|
188
|
-
"application/json": {
|
|
189
|
-
schema: {
|
|
190
|
-
$ref: getSchemaRef("UpdateMe", mode),
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
responses: {
|
|
196
|
-
"200": {
|
|
197
|
-
description: "User updated successfully",
|
|
198
|
-
content: {
|
|
199
|
-
"application/json": {
|
|
200
|
-
schema: {
|
|
201
|
-
$ref: getSchemaRef("User", mode),
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
"400": {
|
|
207
|
-
description: "Invalid input data",
|
|
208
|
-
},
|
|
209
|
-
"401": {
|
|
210
|
-
description: "Authentication required",
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
paths["/users/me"] = {
|
|
216
|
-
delete: {
|
|
217
|
-
tags: ["Users"],
|
|
218
|
-
summary: "Delete current user account",
|
|
219
|
-
description: "Marks the current user's account as deleted",
|
|
220
|
-
operationId: "deleteCurrentUser",
|
|
221
|
-
security: [{ BearerAuth: [] }],
|
|
222
|
-
responses: {
|
|
223
|
-
"200": {
|
|
224
|
-
description: "Account deleted successfully",
|
|
225
|
-
content: {
|
|
226
|
-
"application/json": {
|
|
227
|
-
schema: {
|
|
228
|
-
type: "object",
|
|
229
|
-
properties: {
|
|
230
|
-
message: {
|
|
231
|
-
type: "string",
|
|
232
|
-
example: "Account deleted successfully",
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
"401": {
|
|
240
|
-
description: "Authentication required",
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
},
|
|
244
|
-
};
|
|
245
|
-
return paths;
|
|
246
|
-
}
|
|
247
|
-
//# sourceMappingURL=get-authentication-json-schema-paths.js.map
|
|
1
|
+
"use strict";import{getSchemaRef as n,localValidatorFileExists as c}from"./swagger.router.helpers.js";import{getModuleComponents as u}from"../../../../utils/dynamic-loader.js";import{isEndpointDisabled as p}from"../../../base/utils/helpers/base.router.helpers.js";export const getSchemaMode=async(s,e)=>{const r=e.swagger?.mode,a=e.swagger?.strict;return r&&(a||await c(s,"user",e))?r:"prisma"};export default async function d(s){const e={};if(!s.swagger?.mode)return e;const a=u("auth")?.router?.config;if(a?.disable===!0)return e;const i=t=>p(a,t);if(!i("login")){const t=await getSchemaMode("login",s);e["/api/auth/login"]={post:{tags:["Authentication"],summary:"Login to the system",description:"Authenticates a user and returns an access token",operationId:"login",requestBody:{description:"User credentials",required:!0,content:{"application/json":{schema:{$ref:n("Login",t)}}}},responses:{200:{description:"Login successful",content:{"application/json":{schema:{type:"object",properties:{accessToken:{type:"string",description:"JWT access token"}}}}}},400:{description:"Invalid input data"},401:{description:"Invalid credentials"}}}}}if(i("logout")||(e["/api/auth/logout"]={delete:{tags:["Authentication"],summary:"Logout from the system",description:"Invalidates the current user's JWT token",operationId:"logout",security:[{BearerAuth:[]}],responses:{204:{description:"Logout successful"},401:{description:"Authentication required"}}}}),!i("signup")){const t=await getSchemaMode("signup",s),o=await getSchemaMode("user",s);e["/api/auth/signup"]={post:{tags:["Authentication"],summary:"Register a new user",description:"Creates a new user account",operationId:"signup",requestBody:{description:"User registration data",required:!0,content:{"application/json":{schema:{$ref:n("Signup",t)}}}},responses:{201:{description:"User created successfully",content:{"application/json":{schema:{$ref:n("User",o)}}}},400:{description:"Invalid input data"},409:{description:"User already exists"}}}}}if(!i("updatePassword")){const t=await getSchemaMode("updatePassword",s);e["/api/auth/update-password"]={post:{tags:["Authentication"],summary:"Update user password",description:"Changes the password for the authenticated user",operationId:"updatePassword",security:[{BearerAuth:[]}],requestBody:{description:"Current and new password",required:!0,content:{"application/json":{schema:{$ref:n("UpdatePassword",t)}}}},responses:{200:{description:"Password updated successfully",content:{"application/json":{schema:{type:"object",properties:{status:{type:"string",example:"success"},message:{type:"string",example:"Password updated successfully!"}}}}}},400:{description:"Invalid input data or current password incorrect"},401:{description:"Authentication required"}}}}}if(!i("getMe")){const t=await getSchemaMode("getMe",s);e["/api/users/me"]={get:{tags:["Authentication"],summary:"Get current user information",description:"Retrieves information about the currently authenticated user",operationId:"getMe",security:[{BearerAuth:[]}],responses:{200:{description:"User information retrieved successfully",content:{"application/json":{schema:{$ref:n("GetMe",t)}}}},401:{description:"Authentication required"}}}}}if(!i("updateMe")){const t=await getSchemaMode("updateMe",s),o=await getSchemaMode("user",s);e["/api/users/me"]||(e["/api/users/me"]={}),e["/api/users/me"].patch={tags:["Authentication"],summary:"Update current user information",description:"Updates information for the currently authenticated user",operationId:"updateMe",security:[{BearerAuth:[]}],requestBody:{description:"User data to update",required:!0,content:{"application/json":{schema:{$ref:n("UpdateMe",t)}}}},responses:{200:{description:"User updated successfully",content:{"application/json":{schema:{$ref:n("User",o)}}}},400:{description:"Invalid input data"},401:{description:"Authentication required"}}}}return i("deleteMe")||(e["/api/users/me"]||(e["/api/users/me"]={}),e["/api/users/me"].delete={tags:["Authentication"],summary:"Delete current user account",description:"Marks the current user's account as deleted",operationId:"deleteMe",security:[{BearerAuth:[]}],responses:{200:{description:"Account deleted successfully",content:{"application/json":{schema:{type:"object",properties:{message:{type:"string",example:"Account deleted successfully"}}}}}},401:{description:"Authentication required"}}}),i("findManyAuthAction")||(e["/api/auth-actions"]={get:{tags:["Authentication"],summary:"Get all authentication actions",description:"Retrieves a list of all available authentication actions and permissions",operationId:"findManyAuthAction",security:[{BearerAuth:[]}],responses:{200:{description:"Auth actions retrieved successfully",content:{"application/json":{schema:{type:"object",properties:{total:{type:"number",description:"Total number of auth actions"},results:{type:"number",description:"Number of auth actions returned"},data:{type:"array",items:{$ref:"#/components/schemas/FindManyAuthActionSystemSchema"}}}}}}},401:{description:"Authentication required"},403:{description:"Insufficient permissions"}}}}),e}
|