arkos 2.0.0-next.2 → 2.0.0-next.20
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 +146 -145
- package/cli.js +11 -13
- package/dist/esm/app.js +17 -16
- package/dist/esm/app.js.map +1 -1
- package/dist/esm/components/arkos-gateway/arkos-gateway.js +338 -0
- package/dist/esm/components/arkos-gateway/arkos-gateway.js.map +1 -0
- package/dist/esm/components/arkos-gateway/socket-extensions.js +168 -0
- package/dist/esm/components/arkos-gateway/socket-extensions.js.map +1 -0
- package/dist/esm/components/arkos-gateway/types.js +3 -0
- package/dist/esm/components/arkos-gateway/types.js.map +1 -0
- package/dist/esm/components/arkos-gateway/utils/helpers.js +105 -0
- package/dist/esm/components/arkos-gateway/utils/helpers.js.map +1 -0
- package/dist/esm/components/arkos-gateway/utils/memory-gateway-store.js +45 -0
- package/dist/esm/components/arkos-gateway/utils/memory-gateway-store.js.map +1 -0
- package/dist/esm/components/arkos-gateway/utils/multi-tier-arkos-gateway-store.js +40 -0
- package/dist/esm/components/arkos-gateway/utils/multi-tier-arkos-gateway-store.js.map +1 -0
- package/dist/esm/components/arkos-gateway/utils/rate-limiter.js +13 -0
- package/dist/esm/components/arkos-gateway/utils/rate-limiter.js.map +1 -0
- package/dist/esm/components/arkos-loadable-registry/index.js +1 -3
- package/dist/esm/components/arkos-loadable-registry/index.js.map +1 -1
- package/dist/esm/components/arkos-policy/index.js +3 -1
- package/dist/esm/components/arkos-policy/index.js.map +1 -1
- package/dist/esm/components/arkos-route-hook/index.js +2 -1
- package/dist/esm/components/arkos-route-hook/index.js.map +1 -1
- package/dist/esm/components/arkos-route-hook/reader.js.map +1 -1
- package/dist/esm/components/arkos-route-hook/types.js.map +1 -1
- package/dist/esm/exports/error-handler/index.js +1 -0
- package/dist/esm/exports/error-handler/index.js.map +1 -1
- package/dist/esm/exports/index.js +3 -3
- package/dist/esm/exports/index.js.map +1 -1
- package/dist/esm/exports/middlewares/index.js +1 -1
- package/dist/esm/exports/middlewares/index.js.map +1 -1
- package/dist/esm/exports/services/index.js +2 -2
- package/dist/esm/exports/services/index.js.map +1 -1
- package/dist/esm/exports/websockets.js +5 -0
- package/dist/esm/exports/websockets.js.map +1 -0
- package/dist/esm/generated.js.map +1 -1
- package/dist/esm/modules/auth/auth.controller.js +214 -222
- package/dist/esm/modules/auth/auth.controller.js.map +1 -1
- package/dist/esm/modules/auth/auth.router.js +26 -9
- package/dist/esm/modules/auth/auth.router.js.map +1 -1
- package/dist/esm/modules/auth/auth.service.js +90 -102
- package/dist/esm/modules/auth/auth.service.js.map +1 -1
- package/dist/esm/modules/auth/utils/auth-error-objects.js +2 -2
- package/dist/esm/modules/auth/utils/auth-error-objects.js.map +1 -1
- package/dist/esm/modules/auth/utils/auth-hooks-manager.js +148 -0
- package/dist/esm/modules/auth/utils/auth-hooks-manager.js.map +1 -0
- package/dist/esm/modules/auth/utils/auth-openapi-generator.js +367 -0
- package/dist/esm/modules/auth/utils/auth-openapi-generator.js.map +1 -0
- package/dist/esm/modules/auth/utils/auth-prisma-json-schema-generator.js +97 -0
- package/dist/esm/modules/auth/utils/auth-prisma-json-schema-generator.js.map +1 -0
- package/dist/esm/modules/auth/utils/docs-links.js +6 -0
- package/dist/esm/modules/auth/utils/docs-links.js.map +1 -0
- package/dist/esm/modules/auth/utils/services/auth-action.service.js +20 -16
- package/dist/esm/modules/auth/utils/services/auth-action.service.js.map +1 -1
- package/dist/esm/modules/base/base.controller.js +182 -162
- package/dist/esm/modules/base/base.controller.js.map +1 -1
- package/dist/esm/modules/base/base.middlewares.js +31 -48
- package/dist/esm/modules/base/base.middlewares.js.map +1 -1
- package/dist/esm/modules/base/base.router.js +23 -9
- package/dist/esm/modules/base/base.router.js.map +1 -1
- package/dist/esm/modules/base/base.service.js +33 -138
- package/dist/esm/modules/base/base.service.js.map +1 -1
- package/dist/esm/modules/base/types/base.service.types.js.map +1 -1
- package/dist/esm/modules/base/utils/error-prettifier.js +26 -30
- package/dist/esm/modules/base/utils/error-prettifier.js.map +1 -1
- package/dist/esm/modules/base/utils/helpers/base.service.helpers.js +26 -5
- package/dist/esm/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
- package/dist/esm/modules/base/utils/model-openapi-generator.js +438 -0
- package/dist/esm/modules/base/utils/model-openapi-generator.js.map +1 -0
- package/dist/esm/modules/email/email.service.js +17 -10
- package/dist/esm/modules/email/email.service.js.map +1 -1
- package/dist/esm/modules/error-handler/error-handler.controller.js +24 -113
- package/dist/esm/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/app-error.js +5 -2
- package/dist/esm/modules/error-handler/utils/app-error.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/catch-async.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/error-handler.helpers.js +9 -103
- package/dist/esm/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
- package/dist/esm/modules/error-handler/utils/errors.js +127 -0
- package/dist/esm/modules/error-handler/utils/errors.js.map +1 -0
- package/dist/esm/modules/error-handler/utils/get-handled-error.js +68 -0
- package/dist/esm/modules/error-handler/utils/get-handled-error.js.map +1 -0
- package/dist/esm/modules/error-handler/utils/multer-error-handler.js +34 -0
- package/dist/esm/modules/error-handler/utils/multer-error-handler.js.map +1 -0
- package/dist/esm/modules/file-upload/file-upload.controller.js +208 -214
- package/dist/esm/modules/file-upload/file-upload.controller.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.router.js +35 -12
- package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
- package/dist/esm/modules/file-upload/file-upload.service.js +13 -8
- package/dist/esm/modules/file-upload/file-upload.service.js.map +1 -1
- package/dist/esm/modules/file-upload/utils/file-upload-json-schema-generator.js +346 -0
- package/dist/esm/modules/file-upload/utils/file-upload-json-schema-generator.js.map +1 -0
- package/dist/esm/modules/swagger/swagger.router.js +39 -22
- package/dist/esm/modules/swagger/swagger.router.js.map +1 -1
- package/dist/esm/modules/swagger/utils/get-open-api-login-html.js +305 -0
- package/dist/esm/modules/swagger/utils/get-open-api-login-html.js.map +1 -0
- package/dist/esm/modules/swagger/utils/helpers/class-validator-to-json-schema.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js +6 -7
- package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +1 -1
- package/dist/esm/modules/swagger/utils/helpers/openapi-schema-converter.js +6 -3
- package/dist/esm/modules/swagger/utils/helpers/openapi-schema-converter.js.map +1 -1
- package/dist/esm/server.js +1 -1
- package/dist/esm/server.js.map +1 -1
- package/dist/esm/types/arkos-config/utils.js +2 -0
- package/dist/esm/types/arkos-config/utils.js.map +1 -0
- package/dist/esm/types/arkos-prisma-input.js.map +1 -1
- package/dist/esm/types/arkos.js.map +1 -1
- package/dist/esm/types/auth.js.map +1 -1
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/new-arkos-config.js.map +1 -1
- package/dist/esm/types/router-config.js.map +1 -1
- package/dist/esm/types/upload.js +2 -0
- package/dist/esm/types/upload.js.map +1 -0
- package/dist/esm/types/validation/validation-manager.js +49 -0
- package/dist/esm/types/validation/validation-manager.js.map +1 -0
- package/dist/esm/types/validation/validator.js +2 -0
- package/dist/esm/types/validation/validator.js.map +1 -0
- package/dist/esm/utils/arkos-router/arkos-router-openapi-manager.js +68 -34
- package/dist/esm/utils/arkos-router/arkos-router-openapi-manager.js.map +1 -1
- package/dist/esm/utils/arkos-router/index.js +37 -130
- package/dist/esm/utils/arkos-router/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/route-config-registry.js +2 -3
- package/dist/esm/utils/arkos-router/route-config-registry.js.map +1 -1
- package/dist/esm/utils/arkos-router/types/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/types/openapi-config.js.map +1 -1
- package/dist/esm/utils/arkos-router/types/upload-config.js.map +1 -1
- package/dist/esm/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js +188 -0
- package/dist/esm/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js.map +1 -0
- package/dist/esm/utils/arkos-router/utils/helpers/index.js +88 -29
- package/dist/esm/utils/arkos-router/utils/helpers/index.js.map +1 -1
- package/dist/esm/utils/arkos-router/utils/helpers/upload-manager.js +364 -89
- package/dist/esm/utils/arkos-router/utils/helpers/upload-manager.js.map +1 -1
- package/dist/esm/utils/bundler.js +6 -6
- package/dist/esm/utils/bundler.js.map +1 -1
- package/dist/esm/utils/cli/build.js +16 -7
- package/dist/esm/utils/cli/build.js.map +1 -1
- package/dist/esm/utils/cli/dev.js +18 -28
- package/dist/esm/utils/cli/dev.js.map +1 -1
- package/dist/esm/utils/cli/export-auth-action.js +5 -4
- package/dist/esm/utils/cli/export-auth-action.js.map +1 -1
- package/dist/esm/utils/cli/generate.js +70 -56
- package/dist/esm/utils/cli/generate.js.map +1 -1
- package/dist/esm/utils/cli/index.js +54 -50
- package/dist/esm/utils/cli/index.js.map +1 -1
- package/dist/esm/utils/cli/prisma-generate.js +8 -37
- package/dist/esm/utils/cli/prisma-generate.js.map +1 -1
- package/dist/esm/utils/cli/start.js +25 -14
- package/dist/esm/utils/cli/start.js.map +1 -1
- package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
- package/dist/esm/utils/cli/utils/runtime-cli-commander.js +7 -4
- package/dist/esm/utils/cli/utils/runtime-cli-commander.js.map +1 -1
- package/dist/esm/utils/cli/utils/smart-fs-watcher.js +3 -0
- package/dist/esm/utils/cli/utils/smart-fs-watcher.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js +307 -11
- package/dist/esm/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-controller-template.js +16 -7
- 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-multiple-components.js +117 -65
- package/dist/esm/utils/cli/utils/template-generator/templates/generate-multiple-components.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/policy-template.js +6 -8
- package/dist/esm/utils/cli/utils/template-generator/templates/policy-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js +13 -2
- package/dist/esm/utils/cli/utils/template-generator/templates/router-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/service-template.js +2 -2
- package/dist/esm/utils/cli/utils/template-generator/templates/service-template.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/zod-schema-generator.js +213 -19
- package/dist/esm/utils/cli/utils/template-generator/templates/zod-schema-generator.js.map +1 -1
- package/dist/esm/utils/cli/utils/template-generators.js +31 -18
- package/dist/esm/utils/cli/utils/template-generators.js.map +1 -1
- package/dist/esm/utils/define-config.js +14 -0
- package/dist/esm/utils/define-config.js.map +1 -1
- package/dist/esm/utils/docs-links.js +2 -0
- package/dist/esm/utils/docs-links.js.map +1 -0
- package/dist/esm/utils/dotenv.helpers.js +0 -6
- package/dist/esm/utils/dotenv.helpers.js.map +1 -1
- package/dist/esm/utils/dynamic-loader.js +2 -1
- package/dist/esm/utils/dynamic-loader.js.map +1 -1
- package/dist/esm/utils/features/api.features.js +46 -27
- package/dist/esm/utils/features/api.features.js.map +1 -1
- package/dist/esm/utils/features/port-and-host-allocator.js +4 -3
- package/dist/esm/utils/features/port-and-host-allocator.js.map +1 -1
- package/dist/esm/utils/helpers/api.features.helpers.js +20 -0
- package/dist/esm/utils/helpers/api.features.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/arkos-config.helpers.js +20 -2
- package/dist/esm/utils/helpers/arkos-config.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/exit-error.js +1 -0
- package/dist/esm/utils/helpers/exit-error.js.map +1 -1
- package/dist/esm/utils/helpers/fs.helpers.js +26 -33
- package/dist/esm/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/global.helpers.js +1 -1
- package/dist/esm/utils/helpers/global.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/prisma.helpers.js +10 -7
- package/dist/esm/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/query-parser.helpers.js +7 -22
- package/dist/esm/utils/helpers/query-parser.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/routers.helpers.js +2 -2
- package/dist/esm/utils/helpers/routers.helpers.js.map +1 -1
- package/dist/esm/utils/helpers/url-helpers.js +11 -0
- package/dist/esm/utils/helpers/url-helpers.js.map +1 -0
- package/dist/esm/utils/initialize-app.js +41 -17
- package/dist/esm/utils/initialize-app.js.map +1 -1
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js +154 -226
- package/dist/esm/utils/prisma/prisma-json-schema-generator.js.map +1 -1
- package/dist/esm/utils/prisma/prisma-schema-parser.js +37 -11
- package/dist/esm/utils/prisma/prisma-schema-parser.js.map +1 -1
- package/dist/esm/utils/prisma/types.js.map +1 -1
- package/dist/esm/utils/remove-dir.js +1 -1
- package/dist/esm/utils/remove-dir.js.map +1 -1
- package/dist/esm/utils/setup-app.js +59 -42
- package/dist/esm/utils/setup-app.js.map +1 -1
- package/dist/esm/utils/validate-schema.js +23 -21
- package/dist/esm/utils/validate-schema.js.map +1 -1
- package/dist/types/app.d.ts +10 -7
- package/dist/types/components/arkos-gateway/arkos-gateway.d.ts +121 -0
- package/dist/types/components/arkos-gateway/socket-extensions.d.ts +79 -0
- package/dist/types/components/arkos-gateway/types.d.ts +364 -0
- package/dist/types/components/arkos-gateway/utils/helpers.d.ts +9 -0
- package/dist/types/components/arkos-gateway/utils/memory-gateway-store.d.ts +14 -0
- package/dist/types/components/arkos-gateway/utils/multi-tier-arkos-gateway-store.d.ts +20 -0
- package/dist/types/components/arkos-gateway/utils/rate-limiter.d.ts +11 -0
- package/dist/types/components/arkos-route-hook/index.d.ts +11 -5
- package/dist/types/components/arkos-route-hook/reader.d.ts +4 -7
- package/dist/types/components/arkos-route-hook/types.d.ts +9 -5
- package/dist/types/exports/error-handler/index.d.ts +1 -0
- package/dist/types/exports/index.d.ts +5 -5
- package/dist/types/exports/middlewares/index.d.ts +1 -1
- package/dist/types/exports/services/index.d.ts +3 -3
- package/dist/types/exports/websockets.d.ts +5 -0
- package/dist/types/modules/auth/auth.service.d.ts +80 -51
- package/dist/types/modules/auth/utils/auth-hooks-manager.d.ts +63 -0
- package/dist/types/modules/auth/utils/auth-openapi-generator.d.ts +9 -0
- package/dist/types/modules/auth/utils/auth-prisma-json-schema-generator.d.ts +13 -0
- package/dist/types/modules/auth/utils/docs-links.d.ts +3 -0
- package/dist/types/modules/auth/utils/services/auth-action.service.d.ts +2 -2
- package/dist/types/modules/base/base.controller.d.ts +4 -4
- package/dist/types/modules/base/base.middlewares.d.ts +1 -7
- package/dist/types/modules/base/base.service.d.ts +8 -17
- package/dist/types/modules/base/types/base.service.types.d.ts +11 -0
- package/dist/types/modules/base/utils/helpers/base.service.helpers.d.ts +1 -1
- package/dist/types/modules/base/utils/model-openapi-generator.d.ts +12 -0
- package/dist/types/modules/email/email.service.d.ts +1 -1
- package/dist/types/modules/error-handler/utils/app-error.d.ts +0 -2
- package/dist/types/modules/error-handler/utils/catch-async.d.ts +2 -2
- package/dist/types/modules/error-handler/utils/error-handler.helpers.d.ts +1 -27
- package/dist/types/modules/error-handler/utils/errors.d.ts +176 -0
- package/dist/types/modules/error-handler/utils/get-handled-error.d.ts +1 -0
- package/dist/types/modules/error-handler/utils/multer-error-handler.d.ts +7 -0
- package/dist/types/modules/file-upload/file-upload.controller.d.ts +7 -2
- package/dist/types/modules/file-upload/utils/file-upload-json-schema-generator.d.ts +12 -0
- package/dist/types/modules/swagger/swagger.router.d.ts +1 -2
- package/dist/types/modules/swagger/utils/get-open-api-login-html.d.ts +1 -0
- package/dist/types/modules/swagger/utils/helpers/get-swagger-default-configs.d.ts +48 -3
- package/dist/types/modules/swagger/utils/helpers/openapi-schema-converter.d.ts +6 -1
- package/dist/types/types/arkos-config/utils.d.ts +68 -0
- package/dist/types/types/arkos-prisma-input.d.ts +4 -3
- package/dist/types/types/arkos.d.ts +5 -15
- package/dist/types/types/auth.d.ts +4 -4
- package/dist/types/types/index.d.ts +10 -58
- package/dist/types/types/new-arkos-config.d.ts +326 -36
- package/dist/types/types/router-config.d.ts +0 -63
- package/dist/types/types/upload.d.ts +10 -0
- package/dist/types/types/validation/validation-manager.d.ts +27 -0
- package/dist/types/types/validation/validator.d.ts +2 -0
- package/dist/types/utils/arkos-router/arkos-router-openapi-manager.d.ts +14 -1
- package/dist/types/utils/arkos-router/index.d.ts +83 -8
- package/dist/types/utils/arkos-router/types/index.d.ts +74 -23
- package/dist/types/utils/arkos-router/types/openapi-config.d.ts +3 -2
- package/dist/types/utils/arkos-router/types/upload-config.d.ts +65 -8
- package/dist/types/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.d.ts +6 -0
- package/dist/types/utils/arkos-router/utils/helpers/index.d.ts +4 -6
- package/dist/types/utils/arkos-router/utils/helpers/upload-manager.d.ts +1 -36
- package/dist/types/utils/bundler.d.ts +1 -1
- package/dist/types/utils/cli/build.d.ts +1 -1
- package/dist/types/utils/cli/generate.d.ts +15 -6
- package/dist/types/utils/cli/start.d.ts +3 -1
- package/dist/types/utils/cli/utils/template-generator/templates/class-validator-dto-generator.d.ts +11 -0
- package/dist/types/utils/cli/utils/template-generator/templates/zod-schema-generator.d.ts +4 -0
- package/dist/types/utils/define-config.d.ts +1 -1
- package/dist/types/utils/docs-links.d.ts +1 -0
- package/dist/types/utils/dynamic-loader.d.ts +2 -2
- package/dist/types/utils/features/api.features.d.ts +1 -2
- package/dist/types/utils/helpers/arkos-config.helpers.d.ts +7 -0
- package/dist/types/utils/helpers/fs.helpers.d.ts +1 -16
- package/dist/types/utils/helpers/global.helpers.d.ts +1 -0
- package/dist/types/utils/helpers/prisma.helpers.d.ts +1 -1
- package/dist/types/utils/helpers/query-parser.helpers.d.ts +1 -1
- package/dist/types/utils/helpers/url-helpers.d.ts +1 -0
- package/dist/types/utils/initialize-app.d.ts +1 -0
- package/dist/types/utils/prisma/prisma-json-schema-generator.d.ts +12 -30
- package/dist/types/utils/prisma/prisma-schema-parser.d.ts +4 -0
- package/dist/types/utils/prisma/types.d.ts +3 -2
- package/package.json +117 -84
- package/dist/cjs/app.js +0 -79
- package/dist/cjs/app.js.map +0 -1
- package/dist/cjs/components/arkos-loadable-registry/index.js +0 -28
- package/dist/cjs/components/arkos-loadable-registry/index.js.map +0 -1
- package/dist/cjs/components/arkos-loadable-translator/index.js +0 -144
- package/dist/cjs/components/arkos-loadable-translator/index.js.map +0 -1
- package/dist/cjs/components/arkos-policy/index.js +0 -36
- package/dist/cjs/components/arkos-policy/index.js.map +0 -1
- package/dist/cjs/components/arkos-policy/types.js +0 -3
- package/dist/cjs/components/arkos-policy/types.js.map +0 -1
- package/dist/cjs/components/arkos-route-hook/index.js +0 -50
- package/dist/cjs/components/arkos-route-hook/index.js.map +0 -1
- package/dist/cjs/components/arkos-route-hook/reader.js +0 -47
- package/dist/cjs/components/arkos-route-hook/reader.js.map +0 -1
- package/dist/cjs/components/arkos-route-hook/types.js +0 -3
- package/dist/cjs/components/arkos-route-hook/types.js.map +0 -1
- package/dist/cjs/components/arkos-service-hook/index.js +0 -35
- package/dist/cjs/components/arkos-service-hook/index.js.map +0 -1
- package/dist/cjs/components/arkos-service-hook/reader.js +0 -30
- package/dist/cjs/components/arkos-service-hook/reader.js.map +0 -1
- package/dist/cjs/components/arkos-service-hook/types.js +0 -3
- package/dist/cjs/components/arkos-service-hook/types.js.map +0 -1
- package/dist/cjs/exports/auth/index.js +0 -6
- package/dist/cjs/exports/auth/index.js.map +0 -1
- package/dist/cjs/exports/config.js +0 -6
- package/dist/cjs/exports/config.js.map +0 -1
- package/dist/cjs/exports/controllers/index.js +0 -42
- package/dist/cjs/exports/controllers/index.js.map +0 -1
- package/dist/cjs/exports/error-handler/index.js +0 -11
- package/dist/cjs/exports/error-handler/index.js.map +0 -1
- package/dist/cjs/exports/index.js +0 -23
- package/dist/cjs/exports/index.js.map +0 -1
- package/dist/cjs/exports/middlewares/index.js +0 -7
- package/dist/cjs/exports/middlewares/index.js.map +0 -1
- package/dist/cjs/exports/prisma/index.js +0 -13
- package/dist/cjs/exports/prisma/index.js.map +0 -1
- package/dist/cjs/exports/services/index.js +0 -53
- package/dist/cjs/exports/services/index.js.map +0 -1
- package/dist/cjs/exports/utils/index.js +0 -26
- package/dist/cjs/exports/utils/index.js.map +0 -1
- package/dist/cjs/exports/validation/index.js +0 -11
- package/dist/cjs/exports/validation/index.js.map +0 -1
- package/dist/cjs/generated.js +0 -7
- package/dist/cjs/generated.js.map +0 -1
- package/dist/cjs/modules/auth/auth.controller.js +0 -254
- package/dist/cjs/modules/auth/auth.controller.js.map +0 -1
- package/dist/cjs/modules/auth/auth.router.js +0 -113
- package/dist/cjs/modules/auth/auth.router.js.map +0 -1
- package/dist/cjs/modules/auth/auth.service.js +0 -277
- package/dist/cjs/modules/auth/auth.service.js.map +0 -1
- package/dist/cjs/modules/auth/utils/auth-error-objects.js +0 -10
- package/dist/cjs/modules/auth/utils/auth-error-objects.js.map +0 -1
- package/dist/cjs/modules/auth/utils/helpers/auth.controller.helpers.js +0 -83
- package/dist/cjs/modules/auth/utils/helpers/auth.controller.helpers.js.map +0 -1
- package/dist/cjs/modules/auth/utils/services/auth-action.service.js +0 -150
- package/dist/cjs/modules/auth/utils/services/auth-action.service.js.map +0 -1
- package/dist/cjs/modules/base/base.controller.js +0 -275
- package/dist/cjs/modules/base/base.controller.js.map +0 -1
- package/dist/cjs/modules/base/base.middlewares.js +0 -231
- package/dist/cjs/modules/base/base.middlewares.js.map +0 -1
- package/dist/cjs/modules/base/base.router.js +0 -112
- package/dist/cjs/modules/base/base.router.js.map +0 -1
- package/dist/cjs/modules/base/base.service.js +0 -432
- package/dist/cjs/modules/base/base.service.js.map +0 -1
- package/dist/cjs/modules/base/types/base.service.types.js +0 -3
- package/dist/cjs/modules/base/types/base.service.types.js.map +0 -1
- package/dist/cjs/modules/base/utils/error-prettifier.js +0 -188
- package/dist/cjs/modules/base/utils/error-prettifier.js.map +0 -1
- package/dist/cjs/modules/base/utils/helpers/base.middlewares.helpers.js +0 -49
- package/dist/cjs/modules/base/utils/helpers/base.middlewares.helpers.js.map +0 -1
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +0 -13
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +0 -1
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js +0 -222
- package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js.map +0 -1
- package/dist/cjs/modules/base/utils/router-validator.js +0 -13
- package/dist/cjs/modules/base/utils/router-validator.js.map +0 -1
- package/dist/cjs/modules/base/utils/service-hooks-manager.js +0 -19
- package/dist/cjs/modules/base/utils/service-hooks-manager.js.map +0 -1
- package/dist/cjs/modules/debugger/debugger.service.js +0 -59
- package/dist/cjs/modules/debugger/debugger.service.js.map +0 -1
- package/dist/cjs/modules/email/email.service.js +0 -106
- package/dist/cjs/modules/email/email.service.js.map +0 -1
- package/dist/cjs/modules/error-handler/error-handler.controller.js +0 -192
- package/dist/cjs/modules/error-handler/error-handler.controller.js.map +0 -1
- package/dist/cjs/modules/error-handler/utils/app-error.js +0 -28
- package/dist/cjs/modules/error-handler/utils/app-error.js.map +0 -1
- package/dist/cjs/modules/error-handler/utils/catch-async.js +0 -21
- package/dist/cjs/modules/error-handler/utils/catch-async.js.map +0 -1
- package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js +0 -218
- package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js.map +0 -1
- package/dist/cjs/modules/file-upload/file-upload.controller.js +0 -256
- package/dist/cjs/modules/file-upload/file-upload.controller.js.map +0 -1
- package/dist/cjs/modules/file-upload/file-upload.router.js +0 -80
- package/dist/cjs/modules/file-upload/file-upload.router.js.map +0 -1
- package/dist/cjs/modules/file-upload/file-upload.service.js +0 -343
- package/dist/cjs/modules/file-upload/file-upload.service.js.map +0 -1
- package/dist/cjs/modules/file-upload/utils/helpers/file-extensions.js +0 -134
- package/dist/cjs/modules/file-upload/utils/helpers/file-extensions.js.map +0 -1
- package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js +0 -100
- package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js.map +0 -1
- package/dist/cjs/modules/swagger/swagger.router.js +0 -65
- package/dist/cjs/modules/swagger/swagger.router.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/built-in-route-path-object-manager.js +0 -7
- package/dist/cjs/modules/swagger/utils/built-in-route-path-object-manager.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/class-validator-to-json-schema.js +0 -53
- package/dist/cjs/modules/swagger/utils/helpers/class-validator-to-json-schema.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +0 -473
- package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js +0 -491
- package/dist/cjs/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js +0 -73
- package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/get-system-json-schema-paths.js +0 -37
- package/dist/cjs/modules/swagger/utils/helpers/get-system-json-schema-paths.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +0 -61
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +0 -31
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js +0 -49
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js +0 -39
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +0 -468
- package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js +0 -260
- package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/openapi-schema-converter.js +0 -331
- package/dist/cjs/modules/swagger/utils/helpers/openapi-schema-converter.js.map +0 -1
- package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js +0 -109
- package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js.map +0 -1
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/server.js +0 -60
- package/dist/cjs/server.js.map +0 -1
- package/dist/cjs/types/arkos-prisma-input.js +0 -3
- package/dist/cjs/types/arkos-prisma-input.js.map +0 -1
- package/dist/cjs/types/arkos.js +0 -3
- package/dist/cjs/types/arkos.js.map +0 -1
- package/dist/cjs/types/auth.js +0 -3
- package/dist/cjs/types/auth.js.map +0 -1
- package/dist/cjs/types/index.js +0 -3
- package/dist/cjs/types/index.js.map +0 -1
- package/dist/cjs/types/new-arkos-config.js +0 -3
- package/dist/cjs/types/new-arkos-config.js.map +0 -1
- package/dist/cjs/types/router-config.js +0 -3
- package/dist/cjs/types/router-config.js.map +0 -1
- package/dist/cjs/utils/arkos-env.js +0 -9
- package/dist/cjs/utils/arkos-env.js.map +0 -1
- package/dist/cjs/utils/arkos-router/arkos-router-openapi-manager.js +0 -126
- package/dist/cjs/utils/arkos-router/arkos-router-openapi-manager.js.map +0 -1
- package/dist/cjs/utils/arkos-router/index.js +0 -253
- package/dist/cjs/utils/arkos-router/index.js.map +0 -1
- package/dist/cjs/utils/arkos-router/route-config-registry.js +0 -16
- package/dist/cjs/utils/arkos-router/route-config-registry.js.map +0 -1
- package/dist/cjs/utils/arkos-router/route-config-validator.js +0 -56
- package/dist/cjs/utils/arkos-router/route-config-validator.js.map +0 -1
- package/dist/cjs/utils/arkos-router/types/body-parser-config.js +0 -3
- package/dist/cjs/utils/arkos-router/types/body-parser-config.js.map +0 -1
- package/dist/cjs/utils/arkos-router/types/index.js +0 -3
- package/dist/cjs/utils/arkos-router/types/index.js.map +0 -1
- package/dist/cjs/utils/arkos-router/types/openapi-config.js +0 -3
- package/dist/cjs/utils/arkos-router/types/openapi-config.js.map +0 -1
- package/dist/cjs/utils/arkos-router/types/upload-config.js +0 -3
- package/dist/cjs/utils/arkos-router/types/upload-config.js.map +0 -1
- package/dist/cjs/utils/arkos-router/utils/helpers/index.js +0 -163
- package/dist/cjs/utils/arkos-router/utils/helpers/index.js.map +0 -1
- package/dist/cjs/utils/arkos-router/utils/helpers/upload-manager.js +0 -283
- package/dist/cjs/utils/arkos-router/utils/helpers/upload-manager.js.map +0 -1
- package/dist/cjs/utils/bundler.js +0 -163
- package/dist/cjs/utils/bundler.js.map +0 -1
- package/dist/cjs/utils/cli/build.js +0 -199
- package/dist/cjs/utils/cli/build.js.map +0 -1
- package/dist/cjs/utils/cli/dev.js +0 -128
- package/dist/cjs/utils/cli/dev.js.map +0 -1
- package/dist/cjs/utils/cli/export-auth-action.js +0 -79
- package/dist/cjs/utils/cli/export-auth-action.js.map +0 -1
- package/dist/cjs/utils/cli/generate.js +0 -229
- package/dist/cjs/utils/cli/generate.js.map +0 -1
- package/dist/cjs/utils/cli/index.js +0 -191
- package/dist/cjs/utils/cli/index.js.map +0 -1
- package/dist/cjs/utils/cli/prisma-generate.js +0 -112
- package/dist/cjs/utils/cli/prisma-generate.js.map +0 -1
- package/dist/cjs/utils/cli/start.js +0 -72
- package/dist/cjs/utils/cli/start.js.map +0 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +0 -24
- package/dist/cjs/utils/cli/utils/cli.helpers.js.map +0 -1
- package/dist/cjs/utils/cli/utils/runtime-cli-commander.js +0 -115
- package/dist/cjs/utils/cli/utils/runtime-cli-commander.js.map +0 -1
- package/dist/cjs/utils/cli/utils/smart-fs-watcher.js +0 -73
- package/dist/cjs/utils/cli/utils/smart-fs-watcher.js.map +0 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js +0 -550
- package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js.map +0 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js +0 -52
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +0 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-multiple-components.js +0 -139
- package/dist/cjs/utils/cli/utils/template-generator/templates/generate-multiple-components.js.map +0 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/policy-template.js +0 -53
- package/dist/cjs/utils/cli/utils/template-generator/templates/policy-template.js.map +0 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/route-hook.template.js +0 -39
- package/dist/cjs/utils/cli/utils/template-generator/templates/route-hook.template.js.map +0 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js +0 -19
- package/dist/cjs/utils/cli/utils/template-generator/templates/router-template.js.map +0 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/service-hook.template.js +0 -32
- package/dist/cjs/utils/cli/utils/template-generator/templates/service-hook.template.js.map +0 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/service-template.js +0 -50
- package/dist/cjs/utils/cli/utils/template-generator/templates/service-template.js.map +0 -1
- package/dist/cjs/utils/cli/utils/template-generator/templates/zod-schema-generator.js +0 -351
- package/dist/cjs/utils/cli/utils/template-generator/templates/zod-schema-generator.js.map +0 -1
- package/dist/cjs/utils/cli/utils/template-generators.js +0 -52
- package/dist/cjs/utils/cli/utils/template-generators.js.map +0 -1
- package/dist/cjs/utils/cli/utils/watermark-stamper.js +0 -26
- package/dist/cjs/utils/cli/utils/watermark-stamper.js.map +0 -1
- package/dist/cjs/utils/define-config.js +0 -46
- package/dist/cjs/utils/define-config.js.map +0 -1
- package/dist/cjs/utils/dotenv.helpers.js +0 -52
- package/dist/cjs/utils/dotenv.helpers.js.map +0 -1
- package/dist/cjs/utils/dynamic-loader.js +0 -22
- package/dist/cjs/utils/dynamic-loader.js.map +0 -1
- package/dist/cjs/utils/expand-env.js +0 -72
- package/dist/cjs/utils/expand-env.js.map +0 -1
- package/dist/cjs/utils/features/api.features.js +0 -201
- package/dist/cjs/utils/features/api.features.js.map +0 -1
- package/dist/cjs/utils/features/port-and-host-allocator.js +0 -129
- package/dist/cjs/utils/features/port-and-host-allocator.js.map +0 -1
- package/dist/cjs/utils/helpers/api.features.helpers.js +0 -327
- package/dist/cjs/utils/helpers/api.features.helpers.js.map +0 -1
- package/dist/cjs/utils/helpers/arkos-config.helpers.js +0 -86
- package/dist/cjs/utils/helpers/arkos-config.helpers.js.map +0 -1
- package/dist/cjs/utils/helpers/change-case.helpers.js +0 -177
- package/dist/cjs/utils/helpers/change-case.helpers.js.map +0 -1
- package/dist/cjs/utils/helpers/deepmerge.helper.js +0 -115
- package/dist/cjs/utils/helpers/deepmerge.helper.js.map +0 -1
- package/dist/cjs/utils/helpers/exit-error.js +0 -12
- package/dist/cjs/utils/helpers/exit-error.js.map +0 -1
- package/dist/cjs/utils/helpers/fs.helpers.js +0 -60
- package/dist/cjs/utils/helpers/fs.helpers.js.map +0 -1
- package/dist/cjs/utils/helpers/global.helpers.js +0 -105
- package/dist/cjs/utils/helpers/global.helpers.js.map +0 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js +0 -53
- package/dist/cjs/utils/helpers/prisma.helpers.js.map +0 -1
- package/dist/cjs/utils/helpers/query-parser.helpers.js +0 -69
- package/dist/cjs/utils/helpers/query-parser.helpers.js.map +0 -1
- package/dist/cjs/utils/helpers/routers.helpers.js +0 -36
- package/dist/cjs/utils/helpers/routers.helpers.js.map +0 -1
- package/dist/cjs/utils/helpers/text.helpers.js +0 -28
- package/dist/cjs/utils/helpers/text.helpers.js.map +0 -1
- package/dist/cjs/utils/initialize-app.js +0 -55
- package/dist/cjs/utils/initialize-app.js.map +0 -1
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js +0 -437
- package/dist/cjs/utils/prisma/prisma-json-schema-generator.js.map +0 -1
- package/dist/cjs/utils/prisma/prisma-schema-parser.js +0 -360
- package/dist/cjs/utils/prisma/prisma-schema-parser.js.map +0 -1
- package/dist/cjs/utils/prisma/types.js +0 -3
- package/dist/cjs/utils/prisma/types.js.map +0 -1
- package/dist/cjs/utils/remove-dir.js +0 -14
- package/dist/cjs/utils/remove-dir.js.map +0 -1
- package/dist/cjs/utils/setup-app.js +0 -119
- package/dist/cjs/utils/setup-app.js.map +0 -1
- package/dist/cjs/utils/sheu.js +0 -131
- package/dist/cjs/utils/sheu.js.map +0 -1
- package/dist/cjs/utils/validate-dto.js +0 -19
- package/dist/cjs/utils/validate-dto.js.map +0 -1
- package/dist/cjs/utils/validate-schema.js +0 -75
- package/dist/cjs/utils/validate-schema.js.map +0 -1
- package/dist/esm/components/arkos-loadable-translator/index.js +0 -138
- package/dist/esm/components/arkos-loadable-translator/index.js.map +0 -1
- package/dist/esm/components/arkos-service-hook/index.js +0 -32
- package/dist/esm/components/arkos-service-hook/index.js.map +0 -1
- package/dist/esm/components/arkos-service-hook/reader.js +0 -24
- package/dist/esm/components/arkos-service-hook/reader.js.map +0 -1
- package/dist/esm/components/arkos-service-hook/types.js +0 -2
- package/dist/esm/components/arkos-service-hook/types.js.map +0 -1
- package/dist/esm/modules/base/utils/helpers/base.router.helpers.js +0 -10
- package/dist/esm/modules/base/utils/helpers/base.router.helpers.js.map +0 -1
- package/dist/esm/modules/base/utils/service-hooks-manager.js +0 -17
- package/dist/esm/modules/base/utils/service-hooks-manager.js.map +0 -1
- package/dist/esm/modules/swagger/utils/built-in-route-path-object-manager.js +0 -5
- package/dist/esm/modules/swagger/utils/built-in-route-path-object-manager.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +0 -469
- package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js +0 -485
- package/dist/esm/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/get-system-json-schema-paths.js +0 -34
- package/dist/esm/modules/swagger/utils/helpers/get-system-json-schema-paths.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +0 -55
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +0 -25
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js +0 -46
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js +0 -33
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +0 -462
- package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js +0 -255
- package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +0 -1
- package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js +0 -98
- package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js.map +0 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/route-hook.template.js +0 -36
- package/dist/esm/utils/cli/utils/template-generator/templates/route-hook.template.js.map +0 -1
- package/dist/esm/utils/cli/utils/template-generator/templates/service-hook.template.js +0 -29
- package/dist/esm/utils/cli/utils/template-generator/templates/service-hook.template.js.map +0 -1
- package/dist/types/components/arkos-loadable-translator/index.d.ts +0 -53
- package/dist/types/components/arkos-service-hook/index.d.ts +0 -41
- package/dist/types/components/arkos-service-hook/reader.d.ts +0 -35
- package/dist/types/components/arkos-service-hook/types.d.ts +0 -240
- package/dist/types/modules/base/utils/helpers/base.router.helpers.d.ts +0 -3
- package/dist/types/modules/base/utils/service-hooks-manager.d.ts +0 -10
- package/dist/types/modules/swagger/utils/built-in-route-path-object-manager.d.ts +0 -4
- package/dist/types/modules/swagger/utils/helpers/get-authentication-json-schema-paths.d.ts +0 -5
- package/dist/types/modules/swagger/utils/helpers/get-file-upload-json-schema-paths.d.ts +0 -3
- package/dist/types/modules/swagger/utils/helpers/get-system-json-schema-paths.d.ts +0 -2
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.d.ts +0 -1
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.d.ts +0 -1
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.d.ts +0 -4
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.d.ts +0 -1
- package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.d.ts +0 -2
- package/dist/types/modules/swagger/utils/helpers/missing-json-schemas-generator.d.ts +0 -76
- package/dist/types/modules/swagger/utils/helpers/swagger.router.helpers.d.ts +0 -19
- package/dist/types/utils/cli/utils/template-generator/templates/route-hook.template.d.ts +0 -2
- package/dist/types/utils/cli/utils/template-generator/templates/service-hook.template.d.ts +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-upload.router.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.router.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAC5D,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"file-upload.router.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.router.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,0BAA0B,CAAC;AAC5D,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,SAAS,MAAM,sCAAsC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAEvE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,gBAAgB,MAAM,0CAA0C,CAAC;AACxE,OAAO,EAEL,eAAe,GAChB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,6BAA6B,MAAM,2CAA2C,CAAC;AACtF,OAAO,QAAQ,MAAM,kCAAkC,CAAC;AAExD,MAAM,UAAU,mBAAmB;IACjC,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,cAAc,EAAE,CAAC;IAEtD,IAAI,CAAC,UAAU,EAAE,OAAO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G,iBAAiB,CAAC,MAAM,CAAC,EAC5B,oBAAoB,CAAC,UAAU,EAC/B,GAAG,iBAAiB,CAAC,KAAK,CAAC,EAC3B,YAAY,EACZ,GAAG,iBAAiB,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CACjD,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import fileUploadController from \"./file-upload.controller\";\nimport express from \"express\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { sendResponse } from \"../base/base.middlewares\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\nimport { adjustRequestUrl } from \"./utils/helpers/file-upload.helpers\";\nimport { ArkosNextFunction, ArkosRequest, ArkosResponse } from \"../../exports\";\nimport path from \"path\";\nimport ArkosRouter from \"../../utils/arkos-router\";\nimport loadableRegistry from \"../../components/arkos-loadable-registry\";\nimport {\n OperationByModule,\n routeHookReader,\n} from \"../../components/arkos-route-hook/reader\";\nimport { getArkosConfig } from \"../../server\";\nimport fileUploadJsonSchemaGenerator from \"./utils/file-upload-json-schema-generator\";\nimport AppError from \"../error-handler/utils/app-error\";\n\nexport function getFileUploadRouter() {\n const router = ArkosRouter();\n const { fileUpload, globalPrefix } = getArkosConfig();\n\n if (!fileUpload?.enabled === false) return router;\n\n const routeHook = loadableRegistry.getItem(\"ArkosRouteHook\", \"file-upload\");\n\n const op = (operation: OperationByModule<\"file-upload\">) => {\n let components = routeHook\n ? routeHookReader.forOperation(\"file-upload\", operation)\n : {\n before: [],\n after: [],\n onError: [],\n routeConfig: {},\n };\n\n let endpointConfig = components.routeConfig || {};\n if (endpointConfig?.experimental?.openapi !== false)\n endpointConfig = {\n ...(endpointConfig || {}),\n experimental: {\n ...(endpointConfig?.experimental || {}),\n openapi: fileUploadJsonSchemaGenerator.getOpenApiConfig(\n endpointConfig,\n operation\n ),\n },\n };\n\n components.routeConfig = endpointConfig;\n return components;\n };\n\n let basePathname = fileUpload?.baseRoute || \"/api/uploads/\";\n if (!basePathname.startsWith(\"/\")) basePathname = \"/\" + basePathname;\n if (!basePathname.endsWith(\"/\")) basePathname = basePathname + \"/\";\n\n // FIND FILE\n {\n const { before, onError, routeConfig } = op(\"findFile\");\n const baseUploadDirFullPath = path.resolve(\n path\n .join(process.cwd(), fileUpload?.baseUploadDir || \"uploads\")\n .replaceAll(\"//\", \"/\")\n );\n router.get(\n {\n authentication: { action: \"View\", resource: \"file-upload\" },\n ...routeConfig,\n path: `${basePathname}*slug`,\n },\n ...processMiddleware(before),\n adjustRequestUrl,\n express.static(\n baseUploadDirFullPath,\n deepmerge(\n {\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: false,\n index: false,\n cacheControl: true,\n },\n fileUpload?.expressStatic || {}\n )\n ),\n (\n err: any,\n req: ArkosRequest,\n _res: ArkosResponse,\n next: ArkosNextFunction\n ) => {\n if (err.code === \"ENOENT\") {\n const filepath = req.path.replace(\n `${globalPrefix}/${fileUpload?.baseRoute}`.replace(\"//\", \"/\"),\n \"\"\n );\n throw new AppError(\n `File ${filepath} was not found`,\n 404,\n \"FileNotFound\",\n { filepath }\n );\n }\n\n next(err);\n },\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // UPLOAD FILE\n {\n const { before, after, onError, routeConfig } = op(\"uploadFile\");\n router.post(\n {\n authentication: { action: \"Create\", resource: \"file-upload\" },\n ...routeConfig,\n path: `${basePathname}:fileType`,\n },\n ...processMiddleware(before),\n fileUploadController.uploadFile,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // UPDATE FILE\n {\n const { before, after, onError, routeConfig } = op(\"updateFile\");\n router.patch(\n {\n authentication: { action: \"Update\", resource: \"file-upload\" },\n ...routeConfig,\n path: `${basePathname}:fileType/:fileName`,\n },\n ...processMiddleware(before),\n fileUploadController.updateFile,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n // DELETE FILE\n {\n const { before, after, onError, routeConfig } = op(\"deleteFile\");\n router.delete(\n {\n authentication: { action: \"Delete\", resource: \"file-upload\" },\n ...routeConfig,\n path: `${basePathname}:fileType/:fileName`,\n },\n ...processMiddleware(before),\n fileUploadController.deleteFile,\n ...processMiddleware(after),\n sendResponse,\n ...processMiddleware(onError, { type: \"error\" })\n );\n }\n\n return router;\n}\n"]}
|
|
@@ -9,6 +9,11 @@ import { processFile, processImage } from "./utils/helpers/file-upload.helpers.j
|
|
|
9
9
|
import { removeBothSlashes } from "../../utils/helpers/text.helpers.js";
|
|
10
10
|
import { pascalCase } from "../../exports/utils/index.js";
|
|
11
11
|
export class FileUploadService {
|
|
12
|
+
uploadDir;
|
|
13
|
+
fileSizeLimit;
|
|
14
|
+
allowedFileTypes;
|
|
15
|
+
storage;
|
|
16
|
+
maxCount;
|
|
12
17
|
handleUploadError(err, next) {
|
|
13
18
|
if (err instanceof MulterError)
|
|
14
19
|
return next(new AppError(err.message, 400, pascalCase(err.code || "FileUploadError")));
|
|
@@ -16,13 +21,6 @@ export class FileUploadService {
|
|
|
16
21
|
return next(err);
|
|
17
22
|
}
|
|
18
23
|
constructor(uploadDir, fileSizeLimit = 1024 * 1024 * 5, allowedFileTypes = /.*/, maxCount = 30) {
|
|
19
|
-
this.fileFilter = (_, file, cb) => {
|
|
20
|
-
const extName = this.allowedFileTypes.test(path.extname(file.originalname).toLowerCase());
|
|
21
|
-
if (extName)
|
|
22
|
-
cb(null, true);
|
|
23
|
-
else
|
|
24
|
-
cb(new AppError(`File type not allowed, allowed files are ${String(this.allowedFileTypes).replaceAll("/", "").split("|").join(", ")}`, 400, "FileTypeNotAllowed", { filename: file.originalname }));
|
|
25
|
-
};
|
|
26
24
|
uploadDir = uploadDir.startsWith("/") ? uploadDir.substring(1) : uploadDir;
|
|
27
25
|
uploadDir = uploadDir.endsWith("/") ? uploadDir.slice(0, -1) : uploadDir;
|
|
28
26
|
this.uploadDir = path.resolve(process.cwd(), `${uploadDir}/`);
|
|
@@ -42,6 +40,13 @@ export class FileUploadService {
|
|
|
42
40
|
},
|
|
43
41
|
});
|
|
44
42
|
}
|
|
43
|
+
fileFilter = (_, file, cb) => {
|
|
44
|
+
const extName = this.allowedFileTypes.test(path.extname(file.originalname).toLowerCase());
|
|
45
|
+
if (extName)
|
|
46
|
+
cb(null, true);
|
|
47
|
+
else
|
|
48
|
+
cb(new AppError(`File type not allowed, allowed files are ${String(this.allowedFileTypes).replaceAll("/", "").split("|").join(", ")}`, 400, "FileTypeNotAllowed", { filename: file.originalname }));
|
|
49
|
+
};
|
|
45
50
|
getUpload() {
|
|
46
51
|
return multer({
|
|
47
52
|
storage: this.storage,
|
|
@@ -205,7 +210,7 @@ export class FileUploadService {
|
|
|
205
210
|
data = await processImage(req, next, req.file.path, options);
|
|
206
211
|
}
|
|
207
212
|
else {
|
|
208
|
-
data =
|
|
213
|
+
data = processFile(req, req.file.path);
|
|
209
214
|
}
|
|
210
215
|
}
|
|
211
216
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-upload.service.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.service.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,WAAW,EAAiB,MAAM,QAAQ,CAAC;AAC5D,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;AAO7D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,qBA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5B,CAAC;IAEF,OAAO;QACL,kBAAkB;QAClB,kBAAkB;QAClB,qBAAqB;QACrB,iBAAiB;KAClB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,MAAM,EAAE;QACN,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,EAAE;QACzB,mBAAmB,EACjB,uJAAuJ;KAC1J;IACD,MAAM,EAAE;QACN,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI;QAC3B,mBAAmB,EACjB,qJAAqJ;KACxJ;IACD,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,EAAE;QACzB,mBAAmB,EACjB,0OAA0O;KAC7O;IACD,KAAK,EAAE;QACL,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI;QAC3B,mBAAmB,EAAE,IAAI;KAC1B;CACF,CAAC","sourcesContent":["import multer, { MulterError, 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 {\n ArkosNextFunction,\n ArkosRequest,\n ArkosRequestHandler,\n ArkosResponse,\n} from \"../../types\";\nimport { processFile, processImage } from \"./utils/helpers/file-upload.helpers\";\nimport { removeBothSlashes } from \"../../utils/helpers/text.helpers\";\nimport { pascalCase } from \"../../exports/utils\";\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 private handleUploadError(err: any, next: ArkosNextFunction) {\n if (err instanceof MulterError)\n return next(\n new AppError(\n err.message,\n 400,\n pascalCase(err.code || \"FileUploadError\")\n )\n );\n else return next(err);\n }\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 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 const ext = path.extname(file.originalname);\n cb(null, `${file.originalname.replace(ext, \"\")}-${uniqueSuffix}${ext}`);\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\n if (extName) cb(null, true);\n else\n cb(\n new AppError(\n `File type not allowed, allowed files are ${String(this.allowedFileTypes).replaceAll(\"/\", \"\").split(\"|\").join(\", \")}`,\n 400,\n \"FileTypeNotAllowed\",\n { filename: file.originalname }\n )\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) return this.handleUploadError(err, next);\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, next);\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 const { fileUpload } = getArkosConfig();\n const baseRoute = fileUpload?.baseRoute || \"/api/uploads\";\n\n let urlPath: string;\n if (fileUrl.startsWith(\"http\")) {\n const url = new URL(fileUrl);\n urlPath = url.pathname;\n } else urlPath = fileUrl;\n\n const baseRouteIndex = urlPath.indexOf(baseRoute);\n if (baseRouteIndex === -1)\n throw new AppError(\n \"Invalid file URL: base route not found\",\n 400,\n \"InvalidFileUrl\"\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 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 \"UnableToProcessFileURL\"\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(\n `Unsupported file type: ${fileType}`,\n 400,\n \"UnsupportedFileType\"\n );\n }\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, \"FileNotFound\");\n\n throw new AppError(\n `Failed to delete file: ${error.message}`,\n 500,\n \"UnableToDeleteFile\"\n );\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 next: ArkosNextFunction,\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 const isMultiple = Array.isArray(req.query.multiple)\n ? req.query.multiple[0] == \"true\"\n : req.query.multiple == \"true\";\n\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 && err instanceof MulterError)\n return reject(\n new AppError(\n err.message,\n 400,\n pascalCase(err.code || \"FileUploadError\")\n )\n );\n else if (err) reject(err);\n\n try {\n const dirParts = this.uploadDir.split(\"/\");\n (this.uploadDir.endsWith(\"/\")\n ? dirParts[dirParts.length - 2]\n : dirParts[dirParts.length - 1]) || \"files\";\n\n let data;\n if (req.files && Array.isArray(req.files) && req.files.length > 0) {\n const isImageUpload = this.uploadDir?.includes?.(\"/images\");\n if (isImageUpload) {\n data = await Promise.all(\n req.files.map((file) =>\n processImage(req, next, file.path, options)\n )\n );\n } else {\n data = await Promise.all(\n req.files.map((file) => processFile(req, file.path))\n );\n }\n\n data = data.filter((url) => url !== null);\n } else if (req.file) {\n const isImageUpload = this.uploadDir?.includes?.(\"/images\");\n if (isImageUpload) {\n data = await processImage(req, next, req.file.path, options);\n } else {\n data = await processFile(req, req.file.path);\n }\n } else {\n return reject(\n new AppError(\n `No file or files were attached on field ${req.params.fileType} on the request body as form data.`,\n 400,\n \"NoFileOrFilesAttached\"\n )\n );\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)\n throw new AppError(\n \"File type parameter is required\",\n 400,\n \"MissingFileType\"\n );\n\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 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, \"FileNotFound\");\n\n throw new AppError(\n `Failed to delete file: ${error.message}`,\n 500,\n \"UnableToDeleteFile\"\n );\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 const restrictions = fileUpload?.restrictions\n ? deepmerge(fileUploadDefaultRestrictions, fileUpload.restrictions)\n : fileUploadDefaultRestrictions;\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\nexport const fileUploadDefaultRestrictions = {\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"]}
|
|
1
|
+
{"version":3,"file":"file-upload.service.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.service.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,WAAW,EAAiB,MAAM,QAAQ,CAAC;AAC5D,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;AAO7D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAMjD,MAAM,OAAO,iBAAiB;IACZ,SAAS,CAAS;IAC1B,aAAa,CAAS;IACtB,gBAAgB,CAAS;IACzB,OAAO,CAAgB;IACvB,QAAQ,CAAS;IAEjB,iBAAiB,C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iBAAiB;KAClB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,MAAM,EAAE;QACN,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,EAAE;QACzB,mBAAmB,EACjB,uJAAuJ;KAC1J;IACD,MAAM,EAAE;QACN,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI;QAC3B,mBAAmB,EACjB,qJAAqJ;KACxJ;IACD,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,EAAE;QACzB,mBAAmB,EACjB,0OAA0O;KAC7O;IACD,KAAK,EAAE;QACL,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI;QAC3B,mBAAmB,EAAE,IAAI;KAC1B;CACF,CAAC","sourcesContent":["import multer, { MulterError, 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 {\n ArkosNextFunction,\n ArkosRequest,\n ArkosRequestHandler,\n ArkosResponse,\n} from \"../../types\";\nimport { processFile, processImage } from \"./utils/helpers/file-upload.helpers\";\nimport { removeBothSlashes } from \"../../utils/helpers/text.helpers\";\nimport { pascalCase } from \"../../exports/utils\";\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 private handleUploadError(err: any, next: ArkosNextFunction) {\n if (err instanceof MulterError)\n return next(\n new AppError(\n err.message,\n 400,\n pascalCase(err.code || \"FileUploadError\")\n )\n );\n else return next(err);\n }\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 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 const ext = path.extname(file.originalname);\n cb(null, `${file.originalname.replace(ext, \"\")}-${uniqueSuffix}${ext}`);\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\n if (extName) cb(null, true);\n else\n cb(\n new AppError(\n `File type not allowed, allowed files are ${String(this.allowedFileTypes).replaceAll(\"/\", \"\").split(\"|\").join(\", \")}`,\n 400,\n \"FileTypeNotAllowed\",\n { filename: file.originalname }\n )\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) return this.handleUploadError(err, next);\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, next);\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 const { fileUpload } = getArkosConfig();\n const baseRoute = fileUpload?.baseRoute || \"/api/uploads\";\n\n let urlPath: string;\n if (fileUrl.startsWith(\"http\")) {\n const url = new URL(fileUrl);\n urlPath = url.pathname;\n } else urlPath = fileUrl;\n\n const baseRouteIndex = urlPath.indexOf(baseRoute);\n if (baseRouteIndex === -1)\n throw new AppError(\n \"Invalid file URL: base route not found\",\n 400,\n \"InvalidFileUrl\"\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 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 \"UnableToProcessFileURL\"\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(\n `Unsupported file type: ${fileType}`,\n 400,\n \"UnsupportedFileType\"\n );\n }\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, \"FileNotFound\");\n\n throw new AppError(\n `Failed to delete file: ${error.message}`,\n 500,\n \"UnableToDeleteFile\"\n );\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 next: ArkosNextFunction,\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 const isMultiple = Array.isArray(req.query.multiple)\n ? req.query.multiple[0] == \"true\"\n : req.query.multiple == \"true\";\n\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 && err instanceof MulterError)\n return reject(\n new AppError(\n err.message,\n 400,\n pascalCase(err.code || \"FileUploadError\")\n )\n );\n else if (err) reject(err);\n\n try {\n const dirParts = this.uploadDir.split(\"/\");\n (this.uploadDir.endsWith(\"/\")\n ? dirParts[dirParts.length - 2]\n : dirParts[dirParts.length - 1]) || \"files\";\n\n let data;\n if (req.files && Array.isArray(req.files) && req.files.length > 0) {\n const isImageUpload = this.uploadDir?.includes?.(\"/images\");\n if (isImageUpload) {\n data = await Promise.all(\n req.files.map((file) =>\n processImage(req, next, file.path, options)\n )\n );\n } else {\n data = await Promise.all(\n req.files.map((file) => processFile(req, file.path))\n );\n }\n\n data = data.filter((url) => url !== null);\n } else if (req.file) {\n const isImageUpload = this.uploadDir?.includes?.(\"/images\");\n if (isImageUpload) {\n data = await processImage(req, next, req.file.path, options);\n } else {\n data = processFile(req, req.file.path);\n }\n } else {\n return reject(\n new AppError(\n `No file or files were attached on field ${req.params.fileType} on the request body as form data.`,\n 400,\n \"NoFileOrFilesAttached\"\n )\n );\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)\n throw new AppError(\n \"File type parameter is required\",\n 400,\n \"MissingFileType\"\n );\n\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 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, \"FileNotFound\");\n\n throw new AppError(\n `Failed to delete file: ${error.message}`,\n 500,\n \"UnableToDeleteFile\"\n );\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 const restrictions = fileUpload?.restrictions\n ? deepmerge(fileUploadDefaultRestrictions, fileUpload.restrictions)\n : fileUploadDefaultRestrictions;\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\nexport const fileUploadDefaultRestrictions = {\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"]}
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { getArkosConfig } from "../../../utils/helpers/arkos-config.helpers.js";
|
|
2
|
+
import deepmerge from "../../../utils/helpers/deepmerge.helper.js";
|
|
3
|
+
import { fileUploadDefaultRestrictions } from "../file-upload.service.js";
|
|
4
|
+
class FileUploadJsonSchemaGenerator {
|
|
5
|
+
formatBytes(bytes) {
|
|
6
|
+
if (bytes === 0)
|
|
7
|
+
return "0 Bytes";
|
|
8
|
+
const k = 1024;
|
|
9
|
+
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
10
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
11
|
+
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + " " + sizes[i];
|
|
12
|
+
}
|
|
13
|
+
getFileTypeDescription(fileType) {
|
|
14
|
+
const arkosConfig = getArkosConfig();
|
|
15
|
+
const restrictions = deepmerge(fileUploadDefaultRestrictions, arkosConfig.fileUpload?.restrictions || {});
|
|
16
|
+
const restriction = restrictions[fileType];
|
|
17
|
+
if (!restriction)
|
|
18
|
+
return "";
|
|
19
|
+
const maxSize = this.formatBytes(restriction.maxSize);
|
|
20
|
+
const maxCount = restriction.maxCount;
|
|
21
|
+
const formats = restriction.supportedFilesRegex
|
|
22
|
+
?.toString()
|
|
23
|
+
.replace(/\|/g, ", ")
|
|
24
|
+
.replace(/\//g, "")
|
|
25
|
+
.replace(/\.\*/g, "any format");
|
|
26
|
+
return `Maximum file size: ${maxSize}. Maximum files per upload: ${maxCount}. Supported formats: ${formats}`;
|
|
27
|
+
}
|
|
28
|
+
getMultipartRequestBody() {
|
|
29
|
+
return {
|
|
30
|
+
required: true,
|
|
31
|
+
content: {
|
|
32
|
+
"multipart/form-data": {
|
|
33
|
+
schema: {
|
|
34
|
+
type: "object",
|
|
35
|
+
properties: {
|
|
36
|
+
images: {
|
|
37
|
+
type: "array",
|
|
38
|
+
items: { type: "string", format: "binary" },
|
|
39
|
+
description: this.getFileTypeDescription("images"),
|
|
40
|
+
},
|
|
41
|
+
videos: {
|
|
42
|
+
type: "array",
|
|
43
|
+
items: { type: "string", format: "binary" },
|
|
44
|
+
description: this.getFileTypeDescription("videos"),
|
|
45
|
+
},
|
|
46
|
+
documents: {
|
|
47
|
+
type: "array",
|
|
48
|
+
items: { type: "string", format: "binary" },
|
|
49
|
+
description: this.getFileTypeDescription("documents"),
|
|
50
|
+
},
|
|
51
|
+
files: {
|
|
52
|
+
type: "array",
|
|
53
|
+
items: { type: "string", format: "binary" },
|
|
54
|
+
description: this.getFileTypeDescription("files"),
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
getImageQueryParameters() {
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
name: "format",
|
|
66
|
+
in: "query",
|
|
67
|
+
required: false,
|
|
68
|
+
schema: {
|
|
69
|
+
type: "string",
|
|
70
|
+
enum: ["jpeg", "jpg", "png", "webp", "gif", "avif"],
|
|
71
|
+
},
|
|
72
|
+
description: "Image format for conversion (only applicable for fileType=images)",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "width",
|
|
76
|
+
in: "query",
|
|
77
|
+
required: false,
|
|
78
|
+
schema: { type: "integer", minimum: 1 },
|
|
79
|
+
description: "Target width for image resize (only applicable for fileType=images)",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "height",
|
|
83
|
+
in: "query",
|
|
84
|
+
required: false,
|
|
85
|
+
schema: { type: "integer", minimum: 1 },
|
|
86
|
+
description: "Target height for image resize (only applicable for fileType=images)",
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "resizeTo",
|
|
90
|
+
in: "query",
|
|
91
|
+
required: false,
|
|
92
|
+
schema: {
|
|
93
|
+
type: "string",
|
|
94
|
+
enum: ["cover", "contain", "fill", "inside", "outside"],
|
|
95
|
+
},
|
|
96
|
+
description: "Resize strategy (only applicable for fileType=images)",
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
getOpenApiConfig(endpointRouterConfig = {}, endpoint) {
|
|
101
|
+
const arkosConfig = getArkosConfig();
|
|
102
|
+
const basePathname = arkosConfig.fileUpload?.baseRoute || "/api/uploads/";
|
|
103
|
+
const cleanBasePath = basePathname.endsWith("/")
|
|
104
|
+
? basePathname.slice(0, -1)
|
|
105
|
+
: basePathname;
|
|
106
|
+
const existingOpenApi = endpointRouterConfig?.experimental?.openapi || {};
|
|
107
|
+
switch (endpoint) {
|
|
108
|
+
case "findFile": {
|
|
109
|
+
const pathname = `${cleanBasePath}/*`;
|
|
110
|
+
return {
|
|
111
|
+
...existingOpenApi,
|
|
112
|
+
tags: ["File Upload", ...(existingOpenApi?.tags || [])].filter((tag) => tag !== "Defaults"),
|
|
113
|
+
summary: existingOpenApi?.summary === pathname || !existingOpenApi?.summary
|
|
114
|
+
? "Retrieve uploaded file"
|
|
115
|
+
: existingOpenApi.summary,
|
|
116
|
+
description: existingOpenApi?.description ||
|
|
117
|
+
`Serves static files from the upload directory (${arkosConfig.fileUpload?.baseUploadDir || "uploads"}). Uses wildcard path matching to serve files from any subdirectory.`,
|
|
118
|
+
operationId: existingOpenApi?.operationId?.includes(pathname) ||
|
|
119
|
+
!existingOpenApi?.operationId
|
|
120
|
+
? "findFile"
|
|
121
|
+
: existingOpenApi.operationId,
|
|
122
|
+
parameters: [
|
|
123
|
+
...(existingOpenApi?.parameters || []),
|
|
124
|
+
...[
|
|
125
|
+
{
|
|
126
|
+
name: "slug",
|
|
127
|
+
in: "path",
|
|
128
|
+
required: true,
|
|
129
|
+
schema: { type: "string" },
|
|
130
|
+
description: "Path to the file including file type directory (e.g., images/photo.jpg)",
|
|
131
|
+
},
|
|
132
|
+
].filter((p) => !(existingOpenApi?.parameters || []).find((ep) => ep.name === p.name && ep.in === p.in)),
|
|
133
|
+
],
|
|
134
|
+
responses: {
|
|
135
|
+
...(existingOpenApi?.responses || {}),
|
|
136
|
+
"200": existingOpenApi?.responses?.["200"] || {
|
|
137
|
+
description: "File retrieved successfully",
|
|
138
|
+
content: {
|
|
139
|
+
"application/octet-stream": {
|
|
140
|
+
schema: { type: "string", format: "binary" },
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
"404": existingOpenApi?.responses?.["404"] || {
|
|
145
|
+
description: "File not found",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
case "uploadFile": {
|
|
151
|
+
const pathname = `${cleanBasePath}/:fileType`;
|
|
152
|
+
return {
|
|
153
|
+
...existingOpenApi,
|
|
154
|
+
tags: ["File Upload", ...(existingOpenApi?.tags || [])].filter((tag) => tag !== "Defaults"),
|
|
155
|
+
summary: existingOpenApi?.summary === pathname || !existingOpenApi?.summary
|
|
156
|
+
? "Upload file(s)"
|
|
157
|
+
: existingOpenApi.summary,
|
|
158
|
+
description: existingOpenApi?.description ||
|
|
159
|
+
"Upload one or multiple files. Supports image processing options for image uploads.",
|
|
160
|
+
operationId: existingOpenApi?.operationId?.includes(pathname) ||
|
|
161
|
+
!existingOpenApi?.operationId
|
|
162
|
+
? "uploadFile"
|
|
163
|
+
: existingOpenApi.operationId,
|
|
164
|
+
parameters: [
|
|
165
|
+
...(existingOpenApi?.parameters || []),
|
|
166
|
+
...[
|
|
167
|
+
{
|
|
168
|
+
name: "fileType",
|
|
169
|
+
in: "path",
|
|
170
|
+
required: true,
|
|
171
|
+
schema: {
|
|
172
|
+
type: "string",
|
|
173
|
+
enum: ["images", "videos", "documents", "files"],
|
|
174
|
+
},
|
|
175
|
+
description: "Type of file being uploaded",
|
|
176
|
+
},
|
|
177
|
+
...this.getImageQueryParameters(),
|
|
178
|
+
].filter((p) => !(existingOpenApi?.parameters || []).find((ep) => ep.name === p.name && ep.in === p.in)),
|
|
179
|
+
],
|
|
180
|
+
requestBody: existingOpenApi?.requestBody || this.getMultipartRequestBody(),
|
|
181
|
+
responses: {
|
|
182
|
+
...(existingOpenApi?.responses || {}),
|
|
183
|
+
"200": existingOpenApi?.responses?.["200"] || {
|
|
184
|
+
description: "File(s) uploaded successfully",
|
|
185
|
+
content: {
|
|
186
|
+
"application/json": {
|
|
187
|
+
schema: {
|
|
188
|
+
type: "object",
|
|
189
|
+
properties: {
|
|
190
|
+
success: { type: "boolean", example: true },
|
|
191
|
+
data: {
|
|
192
|
+
oneOf: [
|
|
193
|
+
{
|
|
194
|
+
type: "string",
|
|
195
|
+
description: "URL of uploaded file",
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
type: "array",
|
|
199
|
+
items: { type: "string" },
|
|
200
|
+
description: "URLs of uploaded files",
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
},
|
|
204
|
+
message: { type: "string" },
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
"400": existingOpenApi?.responses?.["400"] || {
|
|
211
|
+
description: "Invalid file type, size limit exceeded, or no file uploaded",
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
case "updateFile": {
|
|
217
|
+
const pathname = `${cleanBasePath}/:fileType/:fileName`;
|
|
218
|
+
return {
|
|
219
|
+
...existingOpenApi,
|
|
220
|
+
tags: ["File Upload", ...(existingOpenApi?.tags || [])].filter((tag) => tag !== "Defaults"),
|
|
221
|
+
summary: existingOpenApi?.summary === pathname || !existingOpenApi?.summary
|
|
222
|
+
? "Update existing file"
|
|
223
|
+
: existingOpenApi.summary,
|
|
224
|
+
description: existingOpenApi?.description ||
|
|
225
|
+
"Replace an existing file with a new one. Deletes the old file and uploads the new one.",
|
|
226
|
+
operationId: existingOpenApi?.operationId?.includes(pathname) ||
|
|
227
|
+
!existingOpenApi?.operationId
|
|
228
|
+
? "updateFile"
|
|
229
|
+
: existingOpenApi.operationId,
|
|
230
|
+
parameters: [
|
|
231
|
+
...(existingOpenApi?.parameters || []),
|
|
232
|
+
...[
|
|
233
|
+
{
|
|
234
|
+
name: "fileType",
|
|
235
|
+
in: "path",
|
|
236
|
+
required: true,
|
|
237
|
+
schema: {
|
|
238
|
+
type: "string",
|
|
239
|
+
enum: ["images", "videos", "documents", "files"],
|
|
240
|
+
},
|
|
241
|
+
description: "Type of file being updated",
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
name: "fileName",
|
|
245
|
+
in: "path",
|
|
246
|
+
required: true,
|
|
247
|
+
schema: { type: "string" },
|
|
248
|
+
description: "Name of the file to update",
|
|
249
|
+
},
|
|
250
|
+
...this.getImageQueryParameters(),
|
|
251
|
+
].filter((p) => !(existingOpenApi?.parameters || []).find((ep) => ep.name === p.name && ep.in === p.in)),
|
|
252
|
+
],
|
|
253
|
+
requestBody: existingOpenApi?.requestBody || this.getMultipartRequestBody(),
|
|
254
|
+
responses: {
|
|
255
|
+
...(existingOpenApi?.responses || {}),
|
|
256
|
+
"200": existingOpenApi?.responses?.["200"] || {
|
|
257
|
+
description: "File updated successfully",
|
|
258
|
+
content: {
|
|
259
|
+
"application/json": {
|
|
260
|
+
schema: {
|
|
261
|
+
type: "object",
|
|
262
|
+
properties: {
|
|
263
|
+
success: { type: "boolean", example: true },
|
|
264
|
+
data: {
|
|
265
|
+
oneOf: [
|
|
266
|
+
{
|
|
267
|
+
type: "string",
|
|
268
|
+
description: "URL of updated file",
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
type: "array",
|
|
272
|
+
items: { type: "string" },
|
|
273
|
+
description: "URLs of updated files",
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
},
|
|
277
|
+
message: { type: "string" },
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
"400": existingOpenApi?.responses?.["400"] || {
|
|
284
|
+
description: "Invalid file type, size limit exceeded, or no file uploaded",
|
|
285
|
+
},
|
|
286
|
+
"404": existingOpenApi?.responses?.["404"] || {
|
|
287
|
+
description: "Original file not found",
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
case "deleteFile": {
|
|
293
|
+
const pathname = `${cleanBasePath}/:fileType/:fileName`;
|
|
294
|
+
return {
|
|
295
|
+
...existingOpenApi,
|
|
296
|
+
tags: ["File Upload", ...(existingOpenApi?.tags || [])].filter((tag) => tag !== "Defaults"),
|
|
297
|
+
summary: existingOpenApi?.summary === pathname || !existingOpenApi?.summary
|
|
298
|
+
? "Delete file"
|
|
299
|
+
: existingOpenApi.summary,
|
|
300
|
+
description: existingOpenApi?.description ||
|
|
301
|
+
"Delete an uploaded file from the server",
|
|
302
|
+
operationId: existingOpenApi?.operationId?.includes(pathname) ||
|
|
303
|
+
!existingOpenApi?.operationId
|
|
304
|
+
? "deleteFile"
|
|
305
|
+
: existingOpenApi.operationId,
|
|
306
|
+
parameters: [
|
|
307
|
+
...(existingOpenApi?.parameters || []),
|
|
308
|
+
...[
|
|
309
|
+
{
|
|
310
|
+
name: "fileType",
|
|
311
|
+
in: "path",
|
|
312
|
+
required: true,
|
|
313
|
+
schema: {
|
|
314
|
+
type: "string",
|
|
315
|
+
enum: ["images", "videos", "documents", "files"],
|
|
316
|
+
},
|
|
317
|
+
description: "Type of file being deleted",
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: "fileName",
|
|
321
|
+
in: "path",
|
|
322
|
+
required: true,
|
|
323
|
+
schema: { type: "string" },
|
|
324
|
+
description: "Name of the file to delete",
|
|
325
|
+
},
|
|
326
|
+
].filter((p) => !(existingOpenApi?.parameters || []).find((ep) => ep.name === p.name && ep.in === p.in)),
|
|
327
|
+
],
|
|
328
|
+
responses: {
|
|
329
|
+
...(existingOpenApi?.responses || {}),
|
|
330
|
+
"204": existingOpenApi?.responses?.["204"] || {
|
|
331
|
+
description: "File deleted successfully",
|
|
332
|
+
},
|
|
333
|
+
"404": existingOpenApi?.responses?.["404"] || {
|
|
334
|
+
description: "File not found",
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
default:
|
|
340
|
+
return {};
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const fileUploadJsonSchemaGenerator = new FileUploadJsonSchemaGenerator();
|
|
345
|
+
export default fileUploadJsonSchemaGenerator;
|
|
346
|
+
//# sourceMappingURL=file-upload-json-schema-generator.js.map
|