arkos 2.0.0-next.2 → 2.0.0-next.21
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
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { getArkosConfig } from "../../../utils/helpers/arkos-config.helpers.js";
|
|
2
|
+
import { prismaSchemaParser, } from "../../../exports/prisma/index.js";
|
|
3
|
+
import prismaJsonSchemaGenerator from "../../../utils/prisma/prisma-json-schema-generator.js";
|
|
4
|
+
import { routeHookReader } from "../../../components/arkos-route-hook/reader.js";
|
|
5
|
+
class AuthPrismaJsonSchemaGenerator {
|
|
6
|
+
userModel;
|
|
7
|
+
getUserModel() {
|
|
8
|
+
if (!this.userModel)
|
|
9
|
+
this.userModel = prismaSchemaParser.models.find((m) => m.name.toLowerCase() === "user");
|
|
10
|
+
return this.userModel;
|
|
11
|
+
}
|
|
12
|
+
getPrismaArgs(endpoint) {
|
|
13
|
+
return routeHookReader.getPrismaArgs("auth", endpoint) || {};
|
|
14
|
+
}
|
|
15
|
+
generateGetMeResponse() {
|
|
16
|
+
return prismaJsonSchemaGenerator.generateResponseSchema(this.getUserModel(), this.getPrismaArgs("getMe"));
|
|
17
|
+
}
|
|
18
|
+
generateUpdatePasswordSchema() {
|
|
19
|
+
return {
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
currentPassword: { type: "string" },
|
|
23
|
+
newPassword: { type: "string", minLength: 8 },
|
|
24
|
+
},
|
|
25
|
+
required: ["currentPassword", "newPassword"],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
generateUpdateMeSchema() {
|
|
29
|
+
const updateSchema = prismaJsonSchemaGenerator.generateUpdateSchema(this.getUserModel());
|
|
30
|
+
const restrictedFields = [
|
|
31
|
+
"roles",
|
|
32
|
+
"role",
|
|
33
|
+
"isActive",
|
|
34
|
+
"isStaff",
|
|
35
|
+
"isSuperUser",
|
|
36
|
+
"passwordChangedAt",
|
|
37
|
+
"deletedSelfAccountAt",
|
|
38
|
+
"password",
|
|
39
|
+
"lastLoginAt",
|
|
40
|
+
];
|
|
41
|
+
restrictedFields.forEach((field) => {
|
|
42
|
+
delete updateSchema?.properties?.[field];
|
|
43
|
+
});
|
|
44
|
+
return updateSchema;
|
|
45
|
+
}
|
|
46
|
+
generateSignupSchema() {
|
|
47
|
+
const singupSchema = prismaJsonSchemaGenerator.generateCreateSchema(this.getUserModel());
|
|
48
|
+
const restrictedFields = [
|
|
49
|
+
"roles",
|
|
50
|
+
"role",
|
|
51
|
+
"isActive",
|
|
52
|
+
"isStaff",
|
|
53
|
+
"isSuperUser",
|
|
54
|
+
"passwordChangedAt",
|
|
55
|
+
"deletedSelfAccountAt",
|
|
56
|
+
"lastLoginAt",
|
|
57
|
+
];
|
|
58
|
+
restrictedFields.forEach((field) => {
|
|
59
|
+
delete singupSchema?.properties?.[field];
|
|
60
|
+
});
|
|
61
|
+
return singupSchema;
|
|
62
|
+
}
|
|
63
|
+
generateLoginSchema() {
|
|
64
|
+
const allowedUsernames = getArkosConfig()?.authentication?.login
|
|
65
|
+
?.allowedUsernames || ["username"];
|
|
66
|
+
const usernameProperties = {};
|
|
67
|
+
allowedUsernames.forEach((field) => {
|
|
68
|
+
const displayName = field.includes(".") ? field.split(".").pop() : field;
|
|
69
|
+
usernameProperties[displayName] = {
|
|
70
|
+
type: "string",
|
|
71
|
+
description: `Username field: ${field}`,
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
const baseSchema = {
|
|
75
|
+
type: "object",
|
|
76
|
+
properties: {
|
|
77
|
+
...usernameProperties,
|
|
78
|
+
password: {
|
|
79
|
+
type: "string",
|
|
80
|
+
minLength: 8,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
required: ["password"],
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
...baseSchema,
|
|
87
|
+
...(allowedUsernames.length > 0 && {
|
|
88
|
+
anyOf: allowedUsernames.map((field) => ({
|
|
89
|
+
required: [field.includes(".") ? field.split(".").pop() : field],
|
|
90
|
+
})),
|
|
91
|
+
}),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const authPrismaJsonSchemaGenerator = new AuthPrismaJsonSchemaGenerator();
|
|
96
|
+
export default authPrismaJsonSchemaGenerator;
|
|
97
|
+
//# sourceMappingURL=auth-prisma-json-schema-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-prisma-json-schema-generator.js","sourceRoot":"","sources":["../../../../../src/modules/auth/utils/auth-prisma-json-schema-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAM7E,OAAO,EAEL,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,yBAAyB,MAAM,oDAAoD,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAE9E,MAAM,6BAA6B;IACzB,SAAS,CAAe;IAExB,YAAY;QAClB,IAAI,CAAC,IAAI,CAAC,SAAS;YACjB,IAAI,CAAC,SAAS,GAAG,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAC7C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,MAAM,CACvC,CAAC;QAEJ,OAAO,IAAI,CAAC,SAAU,CAAC;IACzB,CAAC;IAEO,aAAa,CAAC,QAA2C;QAC/D,OAAO,eAAe,CAAC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC/D,CAAC;IAED,qBAAqB;QACnB,OAAO,yBAAyB,CAAC,sBAAsB,CACrD,IAAI,CAAC,YAAY,EAAE,EACnB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAC5B,CAAC;IACJ,CAAC;IAED,4BAA4B;QAC1B,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,eAAe,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACnC,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE;aAC9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K,CAAC,GAAG,CAAC,CAAC,GAAG,EAAG,CAAC,CAAC,CAAC,KAAK,CAAC;YAC1E,kBAAkB,CAAC,WAAW,CAAC,GAAG;gBAChC,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,mBAAmB,KAAK,EAAE;aACxC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,MAAM,UAAU,GAAuB;YACrC,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,GAAG,kBAAkB;gBACrB,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,SAAS,EAAE,CAAC;iBACb;aACF;YACD,QAAQ,EAAE,CAAC,UAAU,CAAC;SACvB,CAAC;QAEF,OAAO;YACL,GAAG,UAAU;YACb,GAAG,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,IAAI;gBACjC,KAAK,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC;oBAC9C,QAAQ,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAG,CAAC,CAAC,CAAC,KAAK,CAAC;iBAClE,CAAC,CAAC;aACJ,CAAC;SACH,CAAC;IACJ,CAAC;CACF;AAED,MAAM,6BAA6B,GAAG,IAAI,6BAA6B,EAAE,CAAC;AAE1E,eAAe,6BAA6B,CAAC","sourcesContent":["import { OpenAPIV3 } from \"openapi-types\";\nimport { getArkosConfig } from \"../../../utils/helpers/arkos-config.helpers\";\nimport {\n JsonSchema,\n JsonSchemaProperty,\n PrismaModel,\n} from \"../../../utils/prisma/types\";\nimport {\n AuthPrismaQueryOptions,\n prismaSchemaParser,\n} from \"../../../exports/prisma\";\nimport prismaJsonSchemaGenerator from \"../../../utils/prisma/prisma-json-schema-generator\";\nimport { routeHookReader } from \"../../../components/arkos-route-hook/reader\";\n\nclass AuthPrismaJsonSchemaGenerator {\n private userModel?: PrismaModel;\n\n private getUserModel() {\n if (!this.userModel)\n this.userModel = prismaSchemaParser.models.find(\n (m) => m.name.toLowerCase() === \"user\"\n );\n\n return this.userModel!;\n }\n\n private getPrismaArgs(endpoint: keyof AuthPrismaQueryOptions<any>) {\n return routeHookReader.getPrismaArgs(\"auth\", endpoint) || {};\n }\n\n generateGetMeResponse(): JsonSchema {\n return prismaJsonSchemaGenerator.generateResponseSchema(\n this.getUserModel(),\n this.getPrismaArgs(\"getMe\")\n );\n }\n\n generateUpdatePasswordSchema(): JsonSchema {\n return {\n type: \"object\",\n properties: {\n currentPassword: { type: \"string\" },\n newPassword: { type: \"string\", minLength: 8 },\n },\n required: [\"currentPassword\", \"newPassword\"],\n };\n }\n\n generateUpdateMeSchema(): JsonSchema {\n const updateSchema = prismaJsonSchemaGenerator.generateUpdateSchema(\n this.getUserModel()\n );\n\n // Remove sensitive fields that users shouldn't update themselves\n const restrictedFields = [\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"password\",\n \"lastLoginAt\",\n ];\n restrictedFields.forEach((field) => {\n delete updateSchema?.properties?.[field];\n });\n\n return updateSchema;\n }\n\n generateSignupSchema(): JsonSchema {\n const singupSchema = prismaJsonSchemaGenerator.generateCreateSchema(\n this.getUserModel()\n );\n\n const restrictedFields = [\n \"roles\",\n \"role\",\n \"isActive\",\n \"isStaff\",\n \"isSuperUser\",\n \"passwordChangedAt\",\n \"deletedSelfAccountAt\",\n \"lastLoginAt\",\n ];\n restrictedFields.forEach((field) => {\n delete singupSchema?.properties?.[field];\n });\n\n return singupSchema;\n }\n\n generateLoginSchema(): JsonSchema {\n const allowedUsernames = getArkosConfig()?.authentication?.login\n ?.allowedUsernames || [\"username\"];\n\n const usernameProperties: Record<string, OpenAPIV3.SchemaObject> = {};\n\n allowedUsernames.forEach((field: string) => {\n const displayName = field.includes(\".\") ? field.split(\".\").pop()! : field;\n usernameProperties[displayName] = {\n type: \"string\",\n description: `Username field: ${field}`,\n };\n });\n\n const baseSchema: JsonSchemaProperty = {\n type: \"object\",\n properties: {\n ...usernameProperties,\n password: {\n type: \"string\",\n minLength: 8,\n },\n },\n required: [\"password\"],\n };\n\n return {\n ...baseSchema,\n ...(allowedUsernames.length > 0 && {\n anyOf: allowedUsernames.map((field: string) => ({\n required: [field.includes(\".\") ? field.split(\".\").pop()! : field],\n })),\n }),\n };\n }\n}\n\nconst authPrismaJsonSchemaGenerator = new AuthPrismaJsonSchemaGenerator();\n\nexport default authPrismaJsonSchemaGenerator;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs-links.js","sourceRoot":"","sources":["../../../../../src/modules/auth/utils/docs-links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,MAAM,IAAI,GAAG,GAAG,YAAY,+BAA+B,CAAC;AAE5D,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,KAAK,EAAE,GAAG,IAAI,QAAQ;CACvB,CAAC","sourcesContent":["import { baseDocsLink } from \"../../../utils/docs-links\";\n\nconst base = `${baseDocsLink}/core-concepts/authentication`;\n\nexport const authenticationDocsLinks = {\n setup: `${base}/setup`,\n};\n"]}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { kebabCase } from "../../../../exports/utils/index.js";
|
|
1
|
+
import { kebabCase, sentenceCase } from "../../../../exports/utils/index.js";
|
|
2
2
|
import { getArkosConfig } from "../../../../utils/helpers/arkos-config.helpers.js";
|
|
3
3
|
import { capitalize } from "../../../../utils/helpers/text.helpers.js";
|
|
4
4
|
class AuthActionService {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
];
|
|
16
|
-
}
|
|
5
|
+
authActions = [
|
|
6
|
+
{
|
|
7
|
+
roles: [],
|
|
8
|
+
action: "View",
|
|
9
|
+
resource: "auth-action",
|
|
10
|
+
name: "View auth action",
|
|
11
|
+
description: "View an auth action",
|
|
12
|
+
errorMessage: "You cannot perform view for auth action",
|
|
13
|
+
},
|
|
14
|
+
];
|
|
17
15
|
add(action, resource, accessControl) {
|
|
18
16
|
const transformedAction = this.transformAccessControlToValidAuthAction(action, resource, accessControl);
|
|
19
17
|
const existingAuthAction = this.getOne(action, resource);
|
|
@@ -21,7 +19,7 @@ class AuthActionService {
|
|
|
21
19
|
const inconsistencies = [];
|
|
22
20
|
const defaultName = `${capitalize(kebabCase(action).replace(/-/g, " "))} ${capitalize(kebabCase(resource).replace(/-/g, " "))}`;
|
|
23
21
|
const defaultDescription = `${capitalize(kebabCase(action).replace(/-/g, " "))} ${capitalize(kebabCase(resource).replace(/-/g, " "))}`;
|
|
24
|
-
const defaultErrorMessage =
|
|
22
|
+
const defaultErrorMessage = `You cannot perform ${sentenceCase(action).toLowerCase()} for ${sentenceCase(resource).toLowerCase()}`;
|
|
25
23
|
const isNonDefault = (value, defaultValue) => {
|
|
26
24
|
return value !== undefined && value !== defaultValue;
|
|
27
25
|
};
|
|
@@ -65,12 +63,14 @@ class AuthActionService {
|
|
|
65
63
|
};
|
|
66
64
|
this.remove(action, resource);
|
|
67
65
|
this.authActions.push(merged);
|
|
66
|
+
return merged;
|
|
68
67
|
}
|
|
69
68
|
else {
|
|
70
69
|
if (transformedAction.roles) {
|
|
71
70
|
transformedAction.roles = [...transformedAction.roles].sort();
|
|
72
71
|
}
|
|
73
72
|
this.authActions.push(transformedAction);
|
|
73
|
+
return transformedAction;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
remove(action, resource) {
|
|
@@ -98,7 +98,7 @@ class AuthActionService {
|
|
|
98
98
|
resource,
|
|
99
99
|
name: `${capitalize(kebabCase(action).replace(/-/g, " "))} ${capitalize(kebabCase(resource).replace(/-/g, " "))}`,
|
|
100
100
|
description: `${capitalize(kebabCase(action).replace(/-/g, " "))} ${capitalize(kebabCase(resource).replace(/-/g, " "))}`,
|
|
101
|
-
errorMessage: `You
|
|
101
|
+
errorMessage: `You cannot perform ${sentenceCase(action).toLowerCase()} for ${sentenceCase(resource).toLowerCase()}`,
|
|
102
102
|
};
|
|
103
103
|
const config = getArkosConfig();
|
|
104
104
|
if (config?.authentication?.mode === "dynamic")
|
|
@@ -107,7 +107,11 @@ class AuthActionService {
|
|
|
107
107
|
return baseAuthAction;
|
|
108
108
|
if (Array.isArray(accessControl))
|
|
109
109
|
return baseAuthAction;
|
|
110
|
-
const actionRule = accessControl !== "*"
|
|
110
|
+
const actionRule = accessControl !== "*"
|
|
111
|
+
? accessControl[action]
|
|
112
|
+
: undefined;
|
|
113
|
+
if (config?.authentication?.mode !== "static")
|
|
114
|
+
delete baseAuthAction.roles;
|
|
111
115
|
if (actionRule) {
|
|
112
116
|
if (Array.isArray(actionRule)) {
|
|
113
117
|
return baseAuthAction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-action.service.js","sourceRoot":"","sources":["../../../../../../src/modules/auth/utils/services/auth-action.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAKtD,OAAO,EAAE,cAAc,EAAE,MAAM,gDAAgD,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAWpE,MAAM,iBAAiB;IAAvB;QACE,gBAAW,GAAiB;YAC1B;gBACE,KAAK,EAAE,EAAE;gBACT,MAAM,EAAE,MAAM;gBACd,QAAQ,EAAE,aAAa;gBACvB,IAAI,EAAE,kBAAkB;gBACxB,WAAW,EAAE,qBAAqB;gBAClC,YAAY,EAAE,sDAAsD;aACrE;SACF,CAAC;IAgMJ,CAAC;IA9LC,GAAG,CAAC,MAAc,EAAE,QAAgB,EAAE,aAAmC;QACvE,MAAM,iBAAiB,GAAG,IAAI,CAAC,uCAAuC,CAC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,CAAC,CAAC;IACzC,CAAC;CACF;AAED,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAElD,eAAe,iBAAiB,CAAC","sourcesContent":["import { kebabCase } from \"../../../../exports/utils\";\nimport {\n AccessControlConfig,\n DetailedAccessControlRule,\n} from \"../../../../types/auth\";\nimport { getArkosConfig } from \"../../../../utils/helpers/arkos-config.helpers\";\nimport { capitalize } from \"../../../../utils/helpers/text.helpers\";\n\ninterface AuthAction {\n roles?: string[] | \"*\";\n action: string;\n resource: string;\n name?: string;\n description?: string;\n errorMessage?: string;\n}\n\nclass AuthActionService {\n authActions: AuthAction[] = [\n {\n roles: [],\n action: \"View\",\n resource: \"auth-action\",\n name: \"View auth action\",\n description: \"View an auth action\",\n errorMessage: \"You do not have permission to perform this operation\",\n },\n ];\n\n add(action: string, resource: string, accessControl?: AccessControlConfig) {\n const transformedAction = this.transformAccessControlToValidAuthAction(\n action,\n resource,\n accessControl\n );\n const existingAuthAction = this.getOne(action, resource);\n\n if (existingAuthAction) {\n const inconsistencies: string[] = [];\n\n const defaultName = `${capitalize(kebabCase(action).replace(/-/g, \" \"))} ${capitalize(kebabCase(resource).replace(/-/g, \" \"))}`;\n const defaultDescription = `${capitalize(kebabCase(action).replace(/-/g, \" \"))} ${capitalize(kebabCase(resource).replace(/-/g, \" \"))}`;\n const defaultErrorMessage =\n \"You do not have permission to perform this operation\";\n\n const isNonDefault = (\n value: string | undefined,\n defaultValue: string\n ): boolean => {\n return value !== undefined && value !== defaultValue;\n };\n\n if (\n isNonDefault(existingAuthAction.name, defaultName) &&\n isNonDefault(transformedAction.name, defaultName) &&\n existingAuthAction.name !== transformedAction.name\n ) {\n inconsistencies.push(\n ` - name: \"${existingAuthAction.name}\" vs \"${transformedAction.name}\"`\n );\n }\n\n if (\n isNonDefault(existingAuthAction.description, defaultDescription) &&\n isNonDefault(transformedAction.description, defaultDescription) &&\n existingAuthAction.description !== transformedAction.description\n ) {\n inconsistencies.push(\n ` - description: \"${existingAuthAction.description}\" vs \"${transformedAction.description}\"`\n );\n }\n\n if (\n isNonDefault(existingAuthAction.errorMessage, defaultErrorMessage) &&\n isNonDefault(transformedAction.errorMessage, defaultErrorMessage) &&\n existingAuthAction.errorMessage !== transformedAction.errorMessage\n ) {\n inconsistencies.push(\n ` - errorMessage: \"${existingAuthAction.errorMessage}\" vs \"${transformedAction.errorMessage}\"`\n );\n }\n if (inconsistencies.length > 0) {\n throw new Error(\n `Inconsistent metadata for permission \"${action}:${resource}\". ` +\n `The same action+resource combination is being defined with different values:\\n` +\n inconsistencies.join(\"\\n\") +\n `\\n\\nPlease ensure all definitions of \"${action}:${resource}\" have the same name, description, and errorMessage values.`\n );\n }\n\n const mergedRoles =\n existingAuthAction.roles || transformedAction.roles\n ? [\n ...(existingAuthAction.roles || []),\n ...(transformedAction.roles || []),\n ]\n : undefined;\n\n const uniqueRoles = mergedRoles\n ? [...new Set(mergedRoles)].sort()\n : undefined;\n\n const merged: AuthAction = {\n action: existingAuthAction.action,\n resource: existingAuthAction.resource,\n roles: uniqueRoles,\n name: existingAuthAction.name ?? transformedAction.name,\n description:\n existingAuthAction.description ?? transformedAction.description,\n errorMessage:\n existingAuthAction.errorMessage ?? transformedAction.errorMessage,\n };\n\n this.remove(action, resource);\n this.authActions.push(merged);\n } else {\n if (transformedAction.roles) {\n transformedAction.roles = [...transformedAction.roles].sort();\n }\n this.authActions.push(transformedAction);\n }\n }\n\n remove(action: string, resource: string) {\n this.authActions = this.authActions.filter(\n (authAction) =>\n !(authAction.action === action && authAction.resource === resource)\n );\n }\n\n getAll(): AuthAction[] {\n return this.authActions;\n }\n\n getOne(action: string, resource: string): AuthAction | undefined {\n return this.authActions.find(\n (authAction) =>\n authAction.action === action && authAction.resource === resource\n );\n }\n\n private transformAccessControlToValidAuthAction(\n action: string,\n resource: string,\n accessControl?: AccessControlConfig\n ): AuthAction {\n const baseAuthAction: AuthAction = {\n roles:\n (accessControl &&\n (Array.isArray(accessControl)\n ? accessControl\n : typeof accessControl === \"string\"\n ? [accessControl]\n : Array.isArray(accessControl?.[action] || {})\n ? (accessControl[action] as string[])\n : (accessControl[action] as DetailedAccessControlRule)\n ?.roles)) ||\n [],\n action,\n resource,\n name: `${capitalize(kebabCase(action).replace(/-/g, \" \"))} ${capitalize(kebabCase(resource).replace(/-/g, \" \"))}`,\n description: `${capitalize(kebabCase(action).replace(/-/g, \" \"))} ${capitalize(kebabCase(resource).replace(/-/g, \" \"))}`,\n errorMessage: `You do not have permission to perform this operation`,\n };\n\n const config = getArkosConfig();\n\n if (config?.authentication?.mode === \"dynamic\") delete baseAuthAction.roles;\n\n if (!accessControl) return baseAuthAction;\n\n if (Array.isArray(accessControl)) return baseAuthAction;\n\n const actionRule =\n accessControl !== \"*\" ? accessControl[action] : undefined;\n\n if (actionRule) {\n if (Array.isArray(actionRule)) {\n return baseAuthAction;\n } else if (typeof actionRule === \"object\") {\n return {\n ...baseAuthAction,\n name: actionRule.name || baseAuthAction.name,\n description: actionRule?.description || baseAuthAction.description,\n errorMessage: actionRule?.errorMessage || baseAuthAction.errorMessage,\n };\n }\n }\n\n return baseAuthAction;\n }\n\n getUniqueActions(): string[] {\n return [\n ...new Set(this.authActions.map((authAction) => authAction.action)),\n ];\n }\n\n getUniqueResources(): string[] {\n return [\n ...new Set(this.authActions.map((authAction) => authAction.resource)),\n ];\n }\n\n getByResource(resource: string): AuthAction[] | undefined {\n return this.authActions.filter(\n (authAction) => authAction.resource === resource\n );\n }\n\n getByAction(action: string): AuthAction[] {\n return this.authActions.filter(\n (authAction) => authAction.action === action\n );\n }\n\n exists(action: string, resource: string): boolean {\n return !!this.getOne(action, resource);\n }\n}\n\nconst authActionService = new AuthActionService();\n\nexport default authActionService;\n"]}
|
|
1
|
+
{"version":3,"file":"auth-action.service.js","sourceRoot":"","sources":["../../../../../../src/modules/auth/utils/services/auth-action.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,2BAA2B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xB,CAAC;IAED,gBAAgB;QACd,OAAO;YACL,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;SACpE,CAAC;IACJ,CAAC;IAED,kBAAkB;QAChB,OAAO;YACL,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;SACtE,CAAC;IACJ,CAAC;IAED,aAAa,CAAC,QAAgB;QAC5B,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAC5B,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,QAAQ,CACjD,CAAC;IACJ,CAAC;IAED,WAAW,CAAC,MAAc;QACxB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAC5B,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,KAAK,MAAM,CAC7C,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,QAAgB;QACrC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;CACF;AAED,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAElD,eAAe,iBAAiB,CAAC","sourcesContent":["import { kebabCase, sentenceCase } from \"../../../../exports/utils\";\nimport {\n AccessControlConfig,\n DetailedAccessControlRule,\n} from \"../../../../types/auth\";\nimport { getArkosConfig } from \"../../../../utils/helpers/arkos-config.helpers\";\nimport { capitalize } from \"../../../../utils/helpers/text.helpers\";\n\nexport interface AuthAction {\n roles?: string[] | \"*\";\n action: string;\n resource: string;\n name?: string;\n description?: string;\n errorMessage?: string;\n}\n\nclass AuthActionService {\n authActions: AuthAction[] = [\n {\n roles: [],\n action: \"View\",\n resource: \"auth-action\",\n name: \"View auth action\",\n description: \"View an auth action\",\n errorMessage: \"You cannot perform view for auth action\",\n },\n ];\n\n add(\n action: string,\n resource: string,\n accessControl?: AccessControlConfig\n ): Required<AuthAction> {\n const transformedAction = this.transformAccessControlToValidAuthAction(\n action,\n resource,\n accessControl\n );\n const existingAuthAction = this.getOne(action, resource);\n\n if (existingAuthAction) {\n const inconsistencies: string[] = [];\n\n const defaultName = `${capitalize(kebabCase(action).replace(/-/g, \" \"))} ${capitalize(kebabCase(resource).replace(/-/g, \" \"))}`;\n const defaultDescription = `${capitalize(kebabCase(action).replace(/-/g, \" \"))} ${capitalize(kebabCase(resource).replace(/-/g, \" \"))}`;\n const defaultErrorMessage = `You cannot perform ${sentenceCase(action).toLowerCase()} for ${sentenceCase(resource).toLowerCase()}`;\n\n const isNonDefault = (\n value: string | undefined,\n defaultValue: string\n ): boolean => {\n return value !== undefined && value !== defaultValue;\n };\n\n if (\n isNonDefault(existingAuthAction.name, defaultName) &&\n isNonDefault(transformedAction.name, defaultName) &&\n existingAuthAction.name !== transformedAction.name\n ) {\n inconsistencies.push(\n ` - name: \"${existingAuthAction.name}\" vs \"${transformedAction.name}\"`\n );\n }\n\n if (\n isNonDefault(existingAuthAction.description, defaultDescription) &&\n isNonDefault(transformedAction.description, defaultDescription) &&\n existingAuthAction.description !== transformedAction.description\n ) {\n inconsistencies.push(\n ` - description: \"${existingAuthAction.description}\" vs \"${transformedAction.description}\"`\n );\n }\n\n if (\n isNonDefault(existingAuthAction.errorMessage, defaultErrorMessage) &&\n isNonDefault(transformedAction.errorMessage, defaultErrorMessage) &&\n existingAuthAction.errorMessage !== transformedAction.errorMessage\n ) {\n inconsistencies.push(\n ` - errorMessage: \"${existingAuthAction.errorMessage}\" vs \"${transformedAction.errorMessage}\"`\n );\n }\n if (inconsistencies.length > 0) {\n throw new Error(\n `Inconsistent metadata for permission \"${action}:${resource}\". ` +\n `The same action+resource combination is being defined with different values:\\n` +\n inconsistencies.join(\"\\n\") +\n `\\n\\nPlease ensure all definitions of \"${action}:${resource}\" have the same name, description, and errorMessage values.`\n );\n }\n\n const mergedRoles =\n existingAuthAction.roles || transformedAction.roles\n ? [\n ...(existingAuthAction.roles || []),\n ...(transformedAction.roles || []),\n ]\n : undefined;\n\n const uniqueRoles = mergedRoles\n ? [...new Set(mergedRoles)].sort()\n : undefined;\n\n const merged: Required<AuthAction> = {\n action: existingAuthAction.action,\n resource: existingAuthAction.resource,\n roles: uniqueRoles,\n name: existingAuthAction.name ?? transformedAction.name,\n description:\n existingAuthAction.description ?? transformedAction.description,\n errorMessage:\n existingAuthAction.errorMessage ?? transformedAction.errorMessage,\n } as any;\n\n this.remove(action, resource);\n this.authActions.push(merged);\n return merged;\n } else {\n if (transformedAction.roles) {\n transformedAction.roles = [...transformedAction.roles].sort();\n }\n this.authActions.push(transformedAction);\n return transformedAction;\n }\n }\n\n remove(action: string, resource: string) {\n this.authActions = this.authActions.filter(\n (authAction) =>\n !(authAction.action === action && authAction.resource === resource)\n );\n }\n\n getAll(): AuthAction[] {\n return this.authActions;\n }\n\n getOne(action: string, resource: string): AuthAction | undefined {\n return this.authActions.find(\n (authAction) =>\n authAction.action === action && authAction.resource === resource\n );\n }\n\n private transformAccessControlToValidAuthAction(\n action: string,\n resource: string,\n accessControl?: AccessControlConfig\n ): Required<AuthAction> {\n const baseAuthAction: Required<AuthAction> = {\n roles:\n (accessControl &&\n (Array.isArray(accessControl)\n ? accessControl\n : typeof accessControl === \"string\"\n ? [accessControl]\n : Array.isArray(accessControl?.[action] || {})\n ? (accessControl[action] as string[])\n : (accessControl[action] as DetailedAccessControlRule)\n ?.roles)) ||\n [],\n action,\n resource,\n name: `${capitalize(kebabCase(action).replace(/-/g, \" \"))} ${capitalize(kebabCase(resource).replace(/-/g, \" \"))}`,\n description: `${capitalize(kebabCase(action).replace(/-/g, \" \"))} ${capitalize(kebabCase(resource).replace(/-/g, \" \"))}`,\n errorMessage: `You cannot perform ${sentenceCase(action).toLowerCase()} for ${sentenceCase(resource).toLowerCase()}`,\n };\n\n const config = getArkosConfig();\n\n if (config?.authentication?.mode === \"dynamic\")\n delete (baseAuthAction as any).roles;\n\n if (!accessControl) return baseAuthAction;\n\n if (Array.isArray(accessControl)) return baseAuthAction;\n\n const actionRule =\n (accessControl as any) !== \"*\"\n ? (accessControl as any)[action]\n : undefined;\n\n if (config?.authentication?.mode !== \"static\")\n delete (baseAuthAction as any).roles;\n\n if (actionRule) {\n if (Array.isArray(actionRule)) {\n return baseAuthAction;\n } else if (typeof actionRule === \"object\") {\n return {\n ...baseAuthAction,\n name: actionRule.name || baseAuthAction.name,\n description: actionRule?.description || baseAuthAction.description,\n errorMessage: actionRule?.errorMessage || baseAuthAction.errorMessage,\n };\n }\n }\n\n return baseAuthAction;\n }\n\n getUniqueActions(): string[] {\n return [\n ...new Set(this.authActions.map((authAction) => authAction.action)),\n ];\n }\n\n getUniqueResources(): string[] {\n return [\n ...new Set(this.authActions.map((authAction) => authAction.resource)),\n ];\n }\n\n getByResource(resource: string): AuthAction[] | undefined {\n return this.authActions.filter(\n (authAction) => authAction.resource === resource\n );\n }\n\n getByAction(action: string): AuthAction[] {\n return this.authActions.filter(\n (authAction) => authAction.action === action\n );\n }\n\n exists(action: string, resource: string): boolean {\n return !!this.getOne(action, resource);\n }\n}\n\nconst authActionService = new AuthActionService();\n\nexport default authActionService;\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import catchAsync from "../error-handler/utils/catch-async.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ArkosPrismaService } from "./base.service.js";
|
|
3
3
|
import AppError from "../error-handler/utils/app-error.js";
|
|
4
4
|
import { kebabCase, pascalCase } from "../../utils/helpers/change-case.helpers.js";
|
|
5
5
|
import pluralize from "pluralize";
|
|
@@ -8,171 +8,113 @@ import deepmerge from "../../utils/helpers/deepmerge.helper.js";
|
|
|
8
8
|
import loadableRegistry from "../../components/arkos-loadable-registry/index.js";
|
|
9
9
|
import { routeHookReader } from "../../components/arkos-route-hook/reader.js";
|
|
10
10
|
export class BaseController {
|
|
11
|
+
service;
|
|
12
|
+
modelName;
|
|
11
13
|
constructor(modelName) {
|
|
12
|
-
this.executeOperation = (config) => {
|
|
13
|
-
return catchAsync(async (req, res, next) => {
|
|
14
|
-
if (config.hooks?.beforeQuery)
|
|
15
|
-
await config.hooks.beforeQuery(req);
|
|
16
|
-
if (config.requiresQueryForBulk) {
|
|
17
|
-
if (Object.keys(req.query).every((key) => ["filterMode", "prismaQueryOptions"].includes(key))) {
|
|
18
|
-
return next(new AppError(`Filter criteria not provided for bulk ${config.operationType.replace(/Many$/, "")}.`, 400, "MissingRequestQueryParameters"));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (config.preventORFilter && req.query.filterMode === "OR") {
|
|
22
|
-
throw new AppError(`req.query.filterMode === OR is not valid for ${config.operationType} operation`, 400);
|
|
23
|
-
}
|
|
24
|
-
if (config.preventORFilter)
|
|
25
|
-
req.query.filterMode = "AND";
|
|
26
|
-
let apiFeatures = new APIFeatures(req, this.modelName);
|
|
27
|
-
config.queryFeatures.forEach((feature) => {
|
|
28
|
-
switch (feature) {
|
|
29
|
-
case "filter":
|
|
30
|
-
apiFeatures = apiFeatures.filter();
|
|
31
|
-
break;
|
|
32
|
-
case "sort":
|
|
33
|
-
apiFeatures = apiFeatures.sort();
|
|
34
|
-
break;
|
|
35
|
-
case "limitFields":
|
|
36
|
-
apiFeatures = apiFeatures.limitFields();
|
|
37
|
-
break;
|
|
38
|
-
case "paginate":
|
|
39
|
-
apiFeatures = apiFeatures.paginate();
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
const { where, ...queryOptions } = apiFeatures.filters;
|
|
44
|
-
if (config.hooks?.afterQuery)
|
|
45
|
-
await config.hooks.afterQuery({ where, queryOptions }, req);
|
|
46
|
-
let serviceArgs = this.buildServiceArgs(config, req, where, queryOptions);
|
|
47
|
-
if (config.hooks?.beforeService)
|
|
48
|
-
serviceArgs = await config.hooks.beforeService(serviceArgs, req);
|
|
49
|
-
const serviceMethod = this.service[config.serviceMethod];
|
|
50
|
-
let result = await serviceMethod.apply(this.service, serviceArgs);
|
|
51
|
-
if (config.hooks?.afterService)
|
|
52
|
-
result = await config.hooks.afterService(result, req);
|
|
53
|
-
let data = result;
|
|
54
|
-
let additionalData = null;
|
|
55
|
-
if (config.operationType === "findMany") {
|
|
56
|
-
const [records, total] = await Promise.all([
|
|
57
|
-
result,
|
|
58
|
-
this.service.count(where, {
|
|
59
|
-
user: req?.user,
|
|
60
|
-
accessToken: req?.accessToken,
|
|
61
|
-
}),
|
|
62
|
-
]);
|
|
63
|
-
data = records;
|
|
64
|
-
additionalData = { total, results: records.length };
|
|
65
|
-
}
|
|
66
|
-
const error = config.errorHandler
|
|
67
|
-
? config.errorHandler(data, req, this.modelName)
|
|
68
|
-
: this.defaultErrorHandler(data, req, config.operationType);
|
|
69
|
-
if (error)
|
|
70
|
-
return next(error);
|
|
71
|
-
let responseData = config.responseBuilder
|
|
72
|
-
? config.responseBuilder(data, additionalData)
|
|
73
|
-
: this.defaultResponseBuilder(data, additionalData, config.operationType);
|
|
74
|
-
if (config.hooks?.beforeResponse)
|
|
75
|
-
responseData = await config.hooks.beforeResponse(responseData, req);
|
|
76
|
-
const routeHook = this.getRouteHook();
|
|
77
|
-
if (routeHook &&
|
|
78
|
-
routeHookReader.getHooks(this.modelName, config.operationType)
|
|
79
|
-
?.after) {
|
|
80
|
-
this.setResponseData(req, res, responseData, config.successStatus);
|
|
81
|
-
next();
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (config.operationType === "deleteOne") {
|
|
85
|
-
res.status(config.successStatus).send();
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
res.status(config.successStatus).json(responseData);
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
this.createOne = this.executeOperation({
|
|
92
|
-
operationType: "createOne",
|
|
93
|
-
serviceMethod: "createOne",
|
|
94
|
-
successStatus: 201,
|
|
95
|
-
queryFeatures: ["limitFields"],
|
|
96
|
-
usesRequestBody: true,
|
|
97
|
-
});
|
|
98
|
-
this.createMany = this.executeOperation({
|
|
99
|
-
operationType: "createMany",
|
|
100
|
-
serviceMethod: "createMany",
|
|
101
|
-
successStatus: 201,
|
|
102
|
-
queryFeatures: ["limitFields"],
|
|
103
|
-
usesRequestBody: true,
|
|
104
|
-
hooks: {
|
|
105
|
-
async beforeQuery(req) {
|
|
106
|
-
if (!req.body || (Array.isArray(req.body) && req.body.length === 0))
|
|
107
|
-
throw new AppError("Expected request body array to contain at least on item but received none", 400, { body: req.body }, "MissingArrayRequestBody");
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
this.findMany = this.executeOperation({
|
|
112
|
-
operationType: "findMany",
|
|
113
|
-
serviceMethod: "findMany",
|
|
114
|
-
successStatus: 200,
|
|
115
|
-
queryFeatures: ["filter", "sort", "limitFields", "paginate"],
|
|
116
|
-
});
|
|
117
|
-
this.findOne = this.executeOperation({
|
|
118
|
-
operationType: "findOne",
|
|
119
|
-
serviceMethod: "findOne",
|
|
120
|
-
successStatus: 200,
|
|
121
|
-
queryFeatures: ["limitFields", "filter"],
|
|
122
|
-
usesRequestParams: true,
|
|
123
|
-
});
|
|
124
|
-
this.updateOne = this.executeOperation({
|
|
125
|
-
operationType: "updateOne",
|
|
126
|
-
serviceMethod: "updateOne",
|
|
127
|
-
successStatus: 200,
|
|
128
|
-
queryFeatures: ["limitFields", "filter"],
|
|
129
|
-
usesRequestParams: true,
|
|
130
|
-
usesRequestBody: true,
|
|
131
|
-
});
|
|
132
|
-
this.updateMany = this.executeOperation({
|
|
133
|
-
operationType: "updateMany",
|
|
134
|
-
serviceMethod: "updateMany",
|
|
135
|
-
successStatus: 200,
|
|
136
|
-
queryFeatures: ["filter", "limitFields"],
|
|
137
|
-
requiresQueryForBulk: true,
|
|
138
|
-
preventORFilter: true,
|
|
139
|
-
usesRequestBody: true,
|
|
140
|
-
});
|
|
141
|
-
this.batchUpdate = this.executeOperation({
|
|
142
|
-
operationType: "batchUpdate",
|
|
143
|
-
serviceMethod: "batchUpdate",
|
|
144
|
-
successStatus: 200,
|
|
145
|
-
queryFeatures: ["limitFields", "filter"],
|
|
146
|
-
usesRequestBody: true,
|
|
147
|
-
});
|
|
148
|
-
this.deleteOne = this.executeOperation({
|
|
149
|
-
operationType: "deleteOne",
|
|
150
|
-
serviceMethod: "deleteOne",
|
|
151
|
-
successStatus: 204,
|
|
152
|
-
queryFeatures: ["filter"],
|
|
153
|
-
usesRequestParams: true,
|
|
154
|
-
});
|
|
155
|
-
this.deleteMany = this.executeOperation({
|
|
156
|
-
operationType: "deleteMany",
|
|
157
|
-
serviceMethod: "deleteMany",
|
|
158
|
-
successStatus: 200,
|
|
159
|
-
queryFeatures: ["filter"],
|
|
160
|
-
requiresQueryForBulk: true,
|
|
161
|
-
preventORFilter: true,
|
|
162
|
-
});
|
|
163
|
-
this.batchDelete = this.executeOperation({
|
|
164
|
-
operationType: "batchDelete",
|
|
165
|
-
serviceMethod: "batchDelete",
|
|
166
|
-
successStatus: 200,
|
|
167
|
-
queryFeatures: ["filter"],
|
|
168
|
-
usesRequestBody: true,
|
|
169
|
-
});
|
|
170
14
|
this.modelName = kebabCase(modelName);
|
|
171
|
-
this.service = new
|
|
15
|
+
this.service = new ArkosPrismaService(modelName);
|
|
172
16
|
}
|
|
173
17
|
getRouteHook() {
|
|
174
18
|
return loadableRegistry.getItem("ArkosRouteHook", kebabCase(kebabCase(this.modelName)));
|
|
175
19
|
}
|
|
20
|
+
executeOperation = (config) => {
|
|
21
|
+
return catchAsync(async (req, res, next) => {
|
|
22
|
+
if (config.hooks?.beforeQuery)
|
|
23
|
+
await config.hooks.beforeQuery(req);
|
|
24
|
+
if (config.requiresQueryForBulk) {
|
|
25
|
+
if (Object.keys(req.query).every((key) => ["filterMode", "prismaQueryOptions"].includes(key))) {
|
|
26
|
+
return next(new AppError(`Filter criteria not provided for bulk ${config.operationType.replace(/Many$/, "")}.`, 400, "MissingRequestQueryParameters"));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (config.preventORFilter && req.query.filterMode === "OR") {
|
|
30
|
+
throw new AppError(`req.query.filterMode === OR is not valid for ${config.operationType} operation`, 400);
|
|
31
|
+
}
|
|
32
|
+
if (config.preventORFilter)
|
|
33
|
+
req.query.filterMode = "AND";
|
|
34
|
+
let apiFeatures = new APIFeatures(req, this.modelName);
|
|
35
|
+
config.queryFeatures.forEach((feature) => {
|
|
36
|
+
switch (feature) {
|
|
37
|
+
case "filter":
|
|
38
|
+
apiFeatures = apiFeatures.filter();
|
|
39
|
+
break;
|
|
40
|
+
case "sort":
|
|
41
|
+
apiFeatures = apiFeatures.sort();
|
|
42
|
+
break;
|
|
43
|
+
case "limitFields":
|
|
44
|
+
apiFeatures = apiFeatures.limitFields();
|
|
45
|
+
break;
|
|
46
|
+
case "paginate":
|
|
47
|
+
apiFeatures = apiFeatures.paginate();
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
const { where, ...queryOptions } = apiFeatures.filters;
|
|
52
|
+
if (config.hooks?.afterQuery)
|
|
53
|
+
await config.hooks.afterQuery({ where, queryOptions }, req);
|
|
54
|
+
let serviceArgs = this.buildServiceArgs(config, req, where, queryOptions);
|
|
55
|
+
if (config.hooks?.beforeService)
|
|
56
|
+
serviceArgs = await config.hooks.beforeService(serviceArgs, req);
|
|
57
|
+
const routeHook = this.getRouteHook();
|
|
58
|
+
const isRouteHookMethod = routeHook && routeHook._configs.service &&
|
|
59
|
+
routeHook._configs.service[config.serviceMethod]
|
|
60
|
+
? true
|
|
61
|
+
: false;
|
|
62
|
+
const serviceMethod = (isRouteHookMethod
|
|
63
|
+
? routeHook._configs.service[config.serviceMethod]
|
|
64
|
+
: this.service[config.serviceMethod]);
|
|
65
|
+
let result = await serviceMethod.apply(isRouteHookMethod ? routeHook._configs.service : this.service, serviceArgs);
|
|
66
|
+
if (config.hooks?.afterService)
|
|
67
|
+
result = await config.hooks.afterService(result, req);
|
|
68
|
+
let data = result;
|
|
69
|
+
let additionalData = null;
|
|
70
|
+
if (config.operationType === "findMany") {
|
|
71
|
+
const [records, total] = await Promise.all([
|
|
72
|
+
result,
|
|
73
|
+
this.service.count(where, {
|
|
74
|
+
user: req?.user,
|
|
75
|
+
accessToken: req?.accessToken,
|
|
76
|
+
}),
|
|
77
|
+
]);
|
|
78
|
+
const take = serviceArgs[1]?.take ?? null;
|
|
79
|
+
const skip = serviceArgs[1]?.skip ?? 0;
|
|
80
|
+
const limit = take ?? total;
|
|
81
|
+
const currentPage = limit > 0 ? Math.floor(skip / limit) + 1 : 1;
|
|
82
|
+
const totalPages = limit > 0 ? Math.ceil(total / limit) : 1;
|
|
83
|
+
data = records;
|
|
84
|
+
additionalData = {
|
|
85
|
+
total,
|
|
86
|
+
results: records.length,
|
|
87
|
+
page: currentPage,
|
|
88
|
+
pages: totalPages,
|
|
89
|
+
limit,
|
|
90
|
+
hasNextPage: currentPage < totalPages,
|
|
91
|
+
hasPrevPage: currentPage > 1,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const error = config.errorHandler
|
|
95
|
+
? config.errorHandler(data, req, this.modelName)
|
|
96
|
+
: this.defaultErrorHandler(data, req, config.operationType);
|
|
97
|
+
if (error)
|
|
98
|
+
return next(error);
|
|
99
|
+
let responseData = config.responseBuilder
|
|
100
|
+
? config.responseBuilder(data, additionalData)
|
|
101
|
+
: this.defaultResponseBuilder(data, additionalData, config.operationType);
|
|
102
|
+
if (config.hooks?.beforeResponse)
|
|
103
|
+
responseData = await config.hooks.beforeResponse(responseData, req);
|
|
104
|
+
if (routeHook &&
|
|
105
|
+
routeHookReader.getHooks(this.modelName, config.operationType)
|
|
106
|
+
?.after) {
|
|
107
|
+
this.setResponseData(req, res, responseData, config.successStatus);
|
|
108
|
+
next();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (config.operationType === "deleteOne") {
|
|
112
|
+
res.status(config.successStatus).send();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
res.status(config.successStatus).json(responseData);
|
|
116
|
+
});
|
|
117
|
+
};
|
|
176
118
|
setResponseData(req, res, data, status) {
|
|
177
119
|
res.originalData = data;
|
|
178
120
|
req.responseData = data;
|
|
@@ -251,8 +193,7 @@ export class BaseController {
|
|
|
251
193
|
defaultResponseBuilder(data, additionalData, operationType) {
|
|
252
194
|
if (operationType === "findMany" && additionalData)
|
|
253
195
|
return {
|
|
254
|
-
|
|
255
|
-
results: additionalData.results,
|
|
196
|
+
...additionalData,
|
|
256
197
|
data,
|
|
257
198
|
};
|
|
258
199
|
if (operationType.includes("Many") &&
|
|
@@ -264,5 +205,84 @@ export class BaseController {
|
|
|
264
205
|
return { results: data.length, data };
|
|
265
206
|
return { data };
|
|
266
207
|
}
|
|
208
|
+
createOne = this.executeOperation({
|
|
209
|
+
operationType: "createOne",
|
|
210
|
+
serviceMethod: "createOne",
|
|
211
|
+
successStatus: 201,
|
|
212
|
+
queryFeatures: ["limitFields"],
|
|
213
|
+
usesRequestBody: true,
|
|
214
|
+
});
|
|
215
|
+
createMany = this.executeOperation({
|
|
216
|
+
operationType: "createMany",
|
|
217
|
+
serviceMethod: "createMany",
|
|
218
|
+
successStatus: 201,
|
|
219
|
+
queryFeatures: ["limitFields"],
|
|
220
|
+
usesRequestBody: true,
|
|
221
|
+
hooks: {
|
|
222
|
+
async beforeQuery(req) {
|
|
223
|
+
if (!req.body || (Array.isArray(req.body) && req.body.length === 0))
|
|
224
|
+
throw new AppError("Expected request body array to contain at least on item but received none", 400, { body: req.body }, "MissingArrayRequestBody");
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
findMany = this.executeOperation({
|
|
229
|
+
operationType: "findMany",
|
|
230
|
+
serviceMethod: "findMany",
|
|
231
|
+
successStatus: 200,
|
|
232
|
+
queryFeatures: ["filter", "sort", "limitFields", "paginate"],
|
|
233
|
+
});
|
|
234
|
+
findOne = this.executeOperation({
|
|
235
|
+
operationType: "findOne",
|
|
236
|
+
serviceMethod: "findOne",
|
|
237
|
+
successStatus: 200,
|
|
238
|
+
queryFeatures: ["limitFields", "filter"],
|
|
239
|
+
usesRequestParams: true,
|
|
240
|
+
});
|
|
241
|
+
updateOne = this.executeOperation({
|
|
242
|
+
operationType: "updateOne",
|
|
243
|
+
serviceMethod: "updateOne",
|
|
244
|
+
successStatus: 200,
|
|
245
|
+
queryFeatures: ["limitFields", "filter"],
|
|
246
|
+
usesRequestParams: true,
|
|
247
|
+
usesRequestBody: true,
|
|
248
|
+
});
|
|
249
|
+
updateMany = this.executeOperation({
|
|
250
|
+
operationType: "updateMany",
|
|
251
|
+
serviceMethod: "updateMany",
|
|
252
|
+
successStatus: 200,
|
|
253
|
+
queryFeatures: ["filter", "limitFields"],
|
|
254
|
+
requiresQueryForBulk: true,
|
|
255
|
+
preventORFilter: true,
|
|
256
|
+
usesRequestBody: true,
|
|
257
|
+
});
|
|
258
|
+
batchUpdate = this.executeOperation({
|
|
259
|
+
operationType: "batchUpdate",
|
|
260
|
+
serviceMethod: "batchUpdate",
|
|
261
|
+
successStatus: 200,
|
|
262
|
+
queryFeatures: ["limitFields", "filter"],
|
|
263
|
+
usesRequestBody: true,
|
|
264
|
+
});
|
|
265
|
+
deleteOne = this.executeOperation({
|
|
266
|
+
operationType: "deleteOne",
|
|
267
|
+
serviceMethod: "deleteOne",
|
|
268
|
+
successStatus: 204,
|
|
269
|
+
queryFeatures: ["filter"],
|
|
270
|
+
usesRequestParams: true,
|
|
271
|
+
});
|
|
272
|
+
deleteMany = this.executeOperation({
|
|
273
|
+
operationType: "deleteMany",
|
|
274
|
+
serviceMethod: "deleteMany",
|
|
275
|
+
successStatus: 200,
|
|
276
|
+
queryFeatures: ["filter"],
|
|
277
|
+
requiresQueryForBulk: true,
|
|
278
|
+
preventORFilter: true,
|
|
279
|
+
});
|
|
280
|
+
batchDelete = this.executeOperation({
|
|
281
|
+
operationType: "batchDelete",
|
|
282
|
+
serviceMethod: "batchDelete",
|
|
283
|
+
successStatus: 200,
|
|
284
|
+
queryFeatures: ["filter"],
|
|
285
|
+
usesRequestBody: true,
|
|
286
|
+
});
|
|
267
287
|
}
|
|
268
288
|
//# sourceMappingURL=base.controller.js.map
|