@dofe/infra-common 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/base.adapter.d.ts +84 -0
- package/dist/adapters/base.adapter.d.ts.map +1 -0
- package/dist/adapters/base.adapter.js +19 -0
- package/dist/adapters/base.adapter.js.map +1 -0
- package/dist/adapters/index.d.ts +35 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +53 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/common.module.d.ts +7 -0
- package/dist/common.module.d.ts.map +1 -0
- package/dist/common.module.js +26 -0
- package/dist/common.module.js.map +1 -0
- package/dist/config/agentx.config.d.ts +37 -0
- package/dist/config/agentx.config.d.ts.map +1 -0
- package/dist/config/agentx.config.js +81 -0
- package/dist/config/agentx.config.js.map +1 -0
- package/dist/config/configuration.d.ts +55 -0
- package/dist/config/configuration.d.ts.map +1 -0
- package/dist/config/configuration.js +336 -0
- package/dist/config/configuration.js.map +1 -0
- package/dist/config/constant/config.constants.d.ts +48 -0
- package/dist/config/constant/config.constants.d.ts.map +1 -0
- package/dist/config/constant/config.constants.js +86 -0
- package/dist/config/constant/config.constants.js.map +1 -0
- package/dist/config/dto/config.dto.d.ts +222 -0
- package/dist/config/dto/config.dto.d.ts.map +1 -0
- package/dist/config/dto/config.dto.js +42 -0
- package/dist/config/dto/config.dto.js.map +1 -0
- package/dist/config/env-config.service.d.ts +147 -0
- package/dist/config/env-config.service.d.ts.map +1 -0
- package/dist/config/env-config.service.js +296 -0
- package/dist/config/env-config.service.js.map +1 -0
- package/dist/config/features/feature-errors.d.ts +13 -0
- package/dist/config/features/feature-errors.d.ts.map +1 -0
- package/dist/config/features/feature-errors.js +25 -0
- package/dist/config/features/feature-errors.js.map +1 -0
- package/dist/config/features/feature-registry.d.ts +26 -0
- package/dist/config/features/feature-registry.d.ts.map +1 -0
- package/dist/config/features/feature-registry.js +172 -0
- package/dist/config/features/feature-registry.js.map +1 -0
- package/dist/config/features/index.d.ts +4 -0
- package/dist/config/features/index.d.ts.map +1 -0
- package/dist/config/features/index.js +9 -0
- package/dist/config/features/index.js.map +1 -0
- package/dist/config/validation/env.validation.d.ts +132 -0
- package/dist/config/validation/env.validation.d.ts.map +1 -0
- package/dist/config/validation/env.validation.js +304 -0
- package/dist/config/validation/env.validation.js.map +1 -0
- package/dist/config/validation/index.d.ts +21 -0
- package/dist/config/validation/index.d.ts.map +1 -0
- package/dist/config/validation/index.js +119 -0
- package/dist/config/validation/index.js.map +1 -0
- package/dist/config/validation/keys.validation.d.ts +884 -0
- package/dist/config/validation/keys.validation.d.ts.map +1 -0
- package/dist/config/validation/keys.validation.js +506 -0
- package/dist/config/validation/keys.validation.js.map +1 -0
- package/dist/config/validation/yaml.validation.d.ts +765 -0
- package/dist/config/validation/yaml.validation.d.ts.map +1 -0
- package/dist/config/validation/yaml.validation.js +488 -0
- package/dist/config/validation/yaml.validation.js.map +1 -0
- package/dist/config/vendor.config.d.ts +48 -0
- package/dist/config/vendor.config.d.ts.map +1 -0
- package/dist/config/vendor.config.js +136 -0
- package/dist/config/vendor.config.js.map +1 -0
- package/dist/decorators/api-key/api-key.decorator.d.ts +25 -0
- package/dist/decorators/api-key/api-key.decorator.d.ts.map +1 -0
- package/dist/decorators/api-key/api-key.decorator.js +30 -0
- package/dist/decorators/api-key/api-key.decorator.js.map +1 -0
- package/dist/decorators/api-key/index.d.ts +2 -0
- package/dist/decorators/api-key/index.d.ts.map +1 -0
- package/dist/decorators/api-key/index.js +18 -0
- package/dist/decorators/api-key/index.js.map +1 -0
- package/dist/decorators/app-version/app-version.controller.d.ts +30 -0
- package/dist/decorators/app-version/app-version.controller.d.ts.map +1 -0
- package/dist/decorators/app-version/app-version.controller.js +159 -0
- package/dist/decorators/app-version/app-version.controller.js.map +1 -0
- package/dist/decorators/app-version/app-version.interceptor.d.ts +15 -0
- package/dist/decorators/app-version/app-version.interceptor.d.ts.map +1 -0
- package/dist/decorators/app-version/app-version.interceptor.js +42 -0
- package/dist/decorators/app-version/app-version.interceptor.js.map +1 -0
- package/dist/decorators/app-version/app-version.module.d.ts +8 -0
- package/dist/decorators/app-version/app-version.module.d.ts.map +1 -0
- package/dist/decorators/app-version/app-version.module.js +39 -0
- package/dist/decorators/app-version/app-version.module.js.map +1 -0
- package/dist/decorators/app-version/app-version.service.d.ts +88 -0
- package/dist/decorators/app-version/app-version.service.d.ts.map +1 -0
- package/dist/decorators/app-version/app-version.service.js +251 -0
- package/dist/decorators/app-version/app-version.service.js.map +1 -0
- package/dist/decorators/app-version/index.d.ts +8 -0
- package/dist/decorators/app-version/index.d.ts.map +1 -0
- package/dist/decorators/app-version/index.js +15 -0
- package/dist/decorators/app-version/index.js.map +1 -0
- package/dist/decorators/audit-log.decorator.d.ts +41 -0
- package/dist/decorators/audit-log.decorator.d.ts.map +1 -0
- package/dist/decorators/audit-log.decorator.js +19 -0
- package/dist/decorators/audit-log.decorator.js.map +1 -0
- package/dist/decorators/cache/cache.decorator.d.ts +256 -0
- package/dist/decorators/cache/cache.decorator.d.ts.map +1 -0
- package/dist/decorators/cache/cache.decorator.js +339 -0
- package/dist/decorators/cache/cache.decorator.js.map +1 -0
- package/dist/decorators/cache/cache.interceptor.d.ts +43 -0
- package/dist/decorators/cache/cache.interceptor.d.ts.map +1 -0
- package/dist/decorators/cache/cache.interceptor.js +219 -0
- package/dist/decorators/cache/cache.interceptor.js.map +1 -0
- package/dist/decorators/cache/cache.module.d.ts +9 -0
- package/dist/decorators/cache/cache.module.d.ts.map +1 -0
- package/dist/decorators/cache/cache.module.js +36 -0
- package/dist/decorators/cache/cache.module.js.map +1 -0
- package/dist/decorators/cache/index.d.ts +7 -0
- package/dist/decorators/cache/index.d.ts.map +1 -0
- package/dist/decorators/cache/index.js +32 -0
- package/dist/decorators/cache/index.js.map +1 -0
- package/dist/decorators/data-visibility/data-visibility.decorator.d.ts +74 -0
- package/dist/decorators/data-visibility/data-visibility.decorator.d.ts.map +1 -0
- package/dist/decorators/data-visibility/data-visibility.decorator.js +87 -0
- package/dist/decorators/data-visibility/data-visibility.decorator.js.map +1 -0
- package/dist/decorators/data-visibility/index.d.ts +2 -0
- package/dist/decorators/data-visibility/index.d.ts.map +1 -0
- package/dist/decorators/data-visibility/index.js +18 -0
- package/dist/decorators/data-visibility/index.js.map +1 -0
- package/dist/decorators/event/event.decorator.d.ts +152 -0
- package/dist/decorators/event/event.decorator.d.ts.map +1 -0
- package/dist/decorators/event/event.decorator.js +158 -0
- package/dist/decorators/event/event.decorator.js.map +1 -0
- package/dist/decorators/event/event.interceptor.d.ts +23 -0
- package/dist/decorators/event/event.interceptor.d.ts.map +1 -0
- package/dist/decorators/event/event.interceptor.js +140 -0
- package/dist/decorators/event/event.interceptor.js.map +1 -0
- package/dist/decorators/event/event.module.d.ts +9 -0
- package/dist/decorators/event/event.module.d.ts.map +1 -0
- package/dist/decorators/event/event.module.js +59 -0
- package/dist/decorators/event/event.module.js.map +1 -0
- package/dist/decorators/event/handlers/cache-event.handler.d.ts +55 -0
- package/dist/decorators/event/handlers/cache-event.handler.d.ts.map +1 -0
- package/dist/decorators/event/handlers/cache-event.handler.js +159 -0
- package/dist/decorators/event/handlers/cache-event.handler.js.map +1 -0
- package/dist/decorators/event/index.d.ts +8 -0
- package/dist/decorators/event/index.d.ts.map +1 -0
- package/dist/decorators/event/index.js +26 -0
- package/dist/decorators/event/index.js.map +1 -0
- package/dist/decorators/feature-flag/feature-flag.decorator.d.ts +144 -0
- package/dist/decorators/feature-flag/feature-flag.decorator.d.ts.map +1 -0
- package/dist/decorators/feature-flag/feature-flag.decorator.js +135 -0
- package/dist/decorators/feature-flag/feature-flag.decorator.js.map +1 -0
- package/dist/decorators/feature-flag/feature-flag.interceptor.d.ts +30 -0
- package/dist/decorators/feature-flag/feature-flag.interceptor.d.ts.map +1 -0
- package/dist/decorators/feature-flag/feature-flag.interceptor.js +127 -0
- package/dist/decorators/feature-flag/feature-flag.interceptor.js.map +1 -0
- package/dist/decorators/feature-flag/feature-flag.module.d.ts +9 -0
- package/dist/decorators/feature-flag/feature-flag.module.d.ts.map +1 -0
- package/dist/decorators/feature-flag/feature-flag.module.js +39 -0
- package/dist/decorators/feature-flag/feature-flag.module.js.map +1 -0
- package/dist/decorators/feature-flag/feature-flag.service.d.ts +102 -0
- package/dist/decorators/feature-flag/feature-flag.service.d.ts.map +1 -0
- package/dist/decorators/feature-flag/feature-flag.service.js +373 -0
- package/dist/decorators/feature-flag/feature-flag.service.js.map +1 -0
- package/dist/decorators/feature-flag/feature-flag.service.spec.d.ts +2 -0
- package/dist/decorators/feature-flag/feature-flag.service.spec.d.ts.map +1 -0
- package/dist/decorators/feature-flag/feature-flag.service.spec.js +264 -0
- package/dist/decorators/feature-flag/feature-flag.service.spec.js.map +1 -0
- package/dist/decorators/feature-flag/index.d.ts +8 -0
- package/dist/decorators/feature-flag/index.d.ts.map +1 -0
- package/dist/decorators/feature-flag/index.js +23 -0
- package/dist/decorators/feature-flag/index.js.map +1 -0
- package/dist/decorators/rate-limit/dto/rate-limit.dto.d.ts +174 -0
- package/dist/decorators/rate-limit/dto/rate-limit.dto.d.ts.map +1 -0
- package/dist/decorators/rate-limit/dto/rate-limit.dto.js +8 -0
- package/dist/decorators/rate-limit/dto/rate-limit.dto.js.map +1 -0
- package/dist/decorators/rate-limit/index.d.ts +24 -0
- package/dist/decorators/rate-limit/index.d.ts.map +1 -0
- package/dist/decorators/rate-limit/index.js +44 -0
- package/dist/decorators/rate-limit/index.js.map +1 -0
- package/dist/decorators/rate-limit/rate-limit.constants.d.ts +16 -0
- package/dist/decorators/rate-limit/rate-limit.constants.d.ts.map +1 -0
- package/dist/decorators/rate-limit/rate-limit.constants.js +22 -0
- package/dist/decorators/rate-limit/rate-limit.constants.js.map +1 -0
- package/dist/decorators/rate-limit/rate-limit.decorator.d.ts +132 -0
- package/dist/decorators/rate-limit/rate-limit.decorator.d.ts.map +1 -0
- package/dist/decorators/rate-limit/rate-limit.decorator.js +185 -0
- package/dist/decorators/rate-limit/rate-limit.decorator.js.map +1 -0
- package/dist/decorators/rate-limit/rate-limit.exception.d.ts +39 -0
- package/dist/decorators/rate-limit/rate-limit.exception.d.ts.map +1 -0
- package/dist/decorators/rate-limit/rate-limit.exception.js +67 -0
- package/dist/decorators/rate-limit/rate-limit.exception.js.map +1 -0
- package/dist/decorators/rate-limit/rate-limit.module.d.ts +25 -0
- package/dist/decorators/rate-limit/rate-limit.module.d.ts.map +1 -0
- package/dist/decorators/rate-limit/rate-limit.module.js +48 -0
- package/dist/decorators/rate-limit/rate-limit.module.js.map +1 -0
- package/dist/decorators/rate-limit/rate-limit.service.d.ts +102 -0
- package/dist/decorators/rate-limit/rate-limit.service.d.ts.map +1 -0
- package/dist/decorators/rate-limit/rate-limit.service.js +390 -0
- package/dist/decorators/rate-limit/rate-limit.service.js.map +1 -0
- package/dist/decorators/response.decorator.d.ts +10 -0
- package/dist/decorators/response.decorator.d.ts.map +1 -0
- package/dist/decorators/response.decorator.js +58 -0
- package/dist/decorators/response.decorator.js.map +1 -0
- package/dist/decorators/skip-version-check.decorator.d.ts +25 -0
- package/dist/decorators/skip-version-check.decorator.d.ts.map +1 -0
- package/dist/decorators/skip-version-check.decorator.js +31 -0
- package/dist/decorators/skip-version-check.decorator.js.map +1 -0
- package/dist/decorators/tenant/index.d.ts +2 -0
- package/dist/decorators/tenant/index.d.ts.map +1 -0
- package/dist/decorators/tenant/index.js +18 -0
- package/dist/decorators/tenant/index.js.map +1 -0
- package/dist/decorators/tenant/tenant.decorator.d.ts +82 -0
- package/dist/decorators/tenant/tenant.decorator.d.ts.map +1 -0
- package/dist/decorators/tenant/tenant.decorator.js +98 -0
- package/dist/decorators/tenant/tenant.decorator.js.map +1 -0
- package/dist/decorators/transaction/index.d.ts +6 -0
- package/dist/decorators/transaction/index.d.ts.map +1 -0
- package/dist/decorators/transaction/index.js +12 -0
- package/dist/decorators/transaction/index.js.map +1 -0
- package/dist/decorators/transaction/transactional.decorator.d.ts +234 -0
- package/dist/decorators/transaction/transactional.decorator.d.ts.map +1 -0
- package/dist/decorators/transaction/transactional.decorator.js +433 -0
- package/dist/decorators/transaction/transactional.decorator.js.map +1 -0
- package/dist/decorators/ts-rest-controller.decorator.d.ts +38 -0
- package/dist/decorators/ts-rest-controller.decorator.d.ts.map +1 -0
- package/dist/decorators/ts-rest-controller.decorator.js +25 -0
- package/dist/decorators/ts-rest-controller.decorator.js.map +1 -0
- package/dist/decorators/validation.decorator.d.ts +4 -0
- package/dist/decorators/validation.decorator.d.ts.map +1 -0
- package/dist/decorators/validation.decorator.js +121 -0
- package/dist/decorators/validation.decorator.js.map +1 -0
- package/dist/decorators/version/index.d.ts +7 -0
- package/dist/decorators/version/index.d.ts.map +1 -0
- package/dist/decorators/version/index.js +25 -0
- package/dist/decorators/version/index.js.map +1 -0
- package/dist/decorators/version/version.decorator.d.ts +96 -0
- package/dist/decorators/version/version.decorator.d.ts.map +1 -0
- package/dist/decorators/version/version.decorator.js +146 -0
- package/dist/decorators/version/version.decorator.js.map +1 -0
- package/dist/decorators/version/version.interceptor.d.ts +19 -0
- package/dist/decorators/version/version.interceptor.d.ts.map +1 -0
- package/dist/decorators/version/version.interceptor.js +86 -0
- package/dist/decorators/version/version.interceptor.js.map +1 -0
- package/dist/decorators/version/version.module.d.ts +8 -0
- package/dist/decorators/version/version.module.d.ts.map +1 -0
- package/dist/decorators/version/version.module.js +33 -0
- package/dist/decorators/version/version.module.js.map +1 -0
- package/dist/encryption.service.d.ts +15 -0
- package/dist/encryption.service.d.ts.map +1 -0
- package/dist/encryption.service.js +35 -0
- package/dist/encryption.service.js.map +1 -0
- package/dist/enums/action.enum.d.ts +8 -0
- package/dist/enums/action.enum.d.ts.map +1 -0
- package/dist/enums/action.enum.js +12 -0
- package/dist/enums/action.enum.js.map +1 -0
- package/dist/enums/error-codes.d.ts +33 -0
- package/dist/enums/error-codes.d.ts.map +1 -0
- package/dist/enums/error-codes.js +52 -0
- package/dist/enums/error-codes.js.map +1 -0
- package/dist/enums/role.enum.d.ts +5 -0
- package/dist/enums/role.enum.d.ts.map +1 -0
- package/dist/enums/role.enum.js +9 -0
- package/dist/enums/role.enum.js.map +1 -0
- package/dist/filter/exception/api.exception.d.ts +77 -0
- package/dist/filter/exception/api.exception.d.ts.map +1 -0
- package/dist/filter/exception/api.exception.js +151 -0
- package/dist/filter/exception/api.exception.js.map +1 -0
- package/dist/filter/exception/exception.d.ts +8 -0
- package/dist/filter/exception/exception.d.ts.map +1 -0
- package/dist/filter/exception/exception.js +50 -0
- package/dist/filter/exception/exception.js.map +1 -0
- package/dist/filter/exception/http.exception.d.ts +11 -0
- package/dist/filter/exception/http.exception.d.ts.map +1 -0
- package/dist/filter/exception/http.exception.js +152 -0
- package/dist/filter/exception/http.exception.js.map +1 -0
- package/dist/guards/api-key.guard.d.ts +42 -0
- package/dist/guards/api-key.guard.d.ts.map +1 -0
- package/dist/guards/api-key.guard.js +159 -0
- package/dist/guards/api-key.guard.js.map +1 -0
- package/dist/guards/auth.guard.d.ts +39 -0
- package/dist/guards/auth.guard.d.ts.map +1 -0
- package/dist/guards/auth.guard.js +178 -0
- package/dist/guards/auth.guard.js.map +1 -0
- package/dist/guards/data-visibility.guard.d.ts +18 -0
- package/dist/guards/data-visibility.guard.d.ts.map +1 -0
- package/dist/guards/data-visibility.guard.js +84 -0
- package/dist/guards/data-visibility.guard.js.map +1 -0
- package/dist/guards/index.d.ts +7 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/index.js +23 -0
- package/dist/guards/index.js.map +1 -0
- package/dist/guards/permission.guard.d.ts +20 -0
- package/dist/guards/permission.guard.d.ts.map +1 -0
- package/dist/guards/permission.guard.js +141 -0
- package/dist/guards/permission.guard.js.map +1 -0
- package/dist/guards/tenant-context.guard.d.ts +12 -0
- package/dist/guards/tenant-context.guard.d.ts.map +1 -0
- package/dist/guards/tenant-context.guard.js +94 -0
- package/dist/guards/tenant-context.guard.js.map +1 -0
- package/dist/guards/version.guard.d.ts +100 -0
- package/dist/guards/version.guard.d.ts.map +1 -0
- package/dist/guards/version.guard.js +233 -0
- package/dist/guards/version.guard.js.map +1 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptor/audit/audit-log.interceptor.d.ts +16 -0
- package/dist/interceptor/audit/audit-log.interceptor.d.ts.map +1 -0
- package/dist/interceptor/audit/audit-log.interceptor.js +156 -0
- package/dist/interceptor/audit/audit-log.interceptor.js.map +1 -0
- package/dist/interceptor/audit/index.d.ts +2 -0
- package/dist/interceptor/audit/index.d.ts.map +1 -0
- package/dist/interceptor/audit/index.js +18 -0
- package/dist/interceptor/audit/index.js.map +1 -0
- package/dist/interceptor/mask/index.d.ts +2 -0
- package/dist/interceptor/mask/index.d.ts.map +1 -0
- package/dist/interceptor/mask/index.js +18 -0
- package/dist/interceptor/mask/index.js.map +1 -0
- package/dist/interceptor/mask/mask.interceptor.d.ts +79 -0
- package/dist/interceptor/mask/mask.interceptor.d.ts.map +1 -0
- package/dist/interceptor/mask/mask.interceptor.js +197 -0
- package/dist/interceptor/mask/mask.interceptor.js.map +1 -0
- package/dist/interceptor/rate-limit/no-rate-limit.interceptor.d.ts +6 -0
- package/dist/interceptor/rate-limit/no-rate-limit.interceptor.d.ts.map +1 -0
- package/dist/interceptor/rate-limit/no-rate-limit.interceptor.js +20 -0
- package/dist/interceptor/rate-limit/no-rate-limit.interceptor.js.map +1 -0
- package/dist/interceptor/rate-limit/rate-limit.interceptor.d.ts +45 -0
- package/dist/interceptor/rate-limit/rate-limit.interceptor.d.ts.map +1 -0
- package/dist/interceptor/rate-limit/rate-limit.interceptor.js +193 -0
- package/dist/interceptor/rate-limit/rate-limit.interceptor.js.map +1 -0
- package/dist/interceptor/transform/transform.interceptor.d.ts +37 -0
- package/dist/interceptor/transform/transform.interceptor.d.ts.map +1 -0
- package/dist/interceptor/transform/transform.interceptor.js +72 -0
- package/dist/interceptor/transform/transform.interceptor.js.map +1 -0
- package/dist/interceptor/transform/transform.interceptor.spec.d.ts +2 -0
- package/dist/interceptor/transform/transform.interceptor.spec.d.ts.map +1 -0
- package/dist/interceptor/transform/transform.interceptor.spec.js +9 -0
- package/dist/interceptor/transform/transform.interceptor.spec.js.map +1 -0
- package/dist/interceptor/version/index.d.ts +2 -0
- package/dist/interceptor/version/index.d.ts.map +1 -0
- package/dist/interceptor/version/index.js +18 -0
- package/dist/interceptor/version/index.js.map +1 -0
- package/dist/interceptor/version/version-header.interceptor.d.ts +31 -0
- package/dist/interceptor/version/version-header.interceptor.d.ts.map +1 -0
- package/dist/interceptor/version/version-header.interceptor.js +62 -0
- package/dist/interceptor/version/version-header.interceptor.js.map +1 -0
- package/dist/middleware/request.middleware.d.ts +27 -0
- package/dist/middleware/request.middleware.d.ts.map +1 -0
- package/dist/middleware/request.middleware.js +141 -0
- package/dist/middleware/request.middleware.js.map +1 -0
- package/dist/middleware/tenant-isolation.middleware.d.ts +12 -0
- package/dist/middleware/tenant-isolation.middleware.d.ts.map +1 -0
- package/dist/middleware/tenant-isolation.middleware.js +51 -0
- package/dist/middleware/tenant-isolation.middleware.js.map +1 -0
- package/dist/pipes/transform-root.pipe.d.ts +5 -0
- package/dist/pipes/transform-root.pipe.d.ts.map +1 -0
- package/dist/pipes/transform-root.pipe.js +24 -0
- package/dist/pipes/transform-root.pipe.js.map +1 -0
- package/dist/ts-rest/index.d.ts +36 -0
- package/dist/ts-rest/index.d.ts.map +1 -0
- package/dist/ts-rest/index.js +65 -0
- package/dist/ts-rest/index.js.map +1 -0
- package/dist/ts-rest/response.helper.d.ts +261 -0
- package/dist/ts-rest/response.helper.d.ts.map +1 -0
- package/dist/ts-rest/response.helper.js +372 -0
- package/dist/ts-rest/response.helper.js.map +1 -0
- package/dist/utils/audit-log-helper.util.d.ts +41 -0
- package/dist/utils/audit-log-helper.util.d.ts.map +1 -0
- package/dist/utils/audit-log-helper.util.js +115 -0
- package/dist/utils/audit-log-helper.util.js.map +1 -0
- package/dist/utils/audit-signature.util.d.ts +64 -0
- package/dist/utils/audit-signature.util.d.ts.map +1 -0
- package/dist/utils/audit-signature.util.js +155 -0
- package/dist/utils/audit-signature.util.js.map +1 -0
- package/dist/utils/prisma-error.util.d.ts +160 -0
- package/dist/utils/prisma-error.util.d.ts.map +1 -0
- package/dist/utils/prisma-error.util.js +342 -0
- package/dist/utils/prisma-error.util.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ts-rest Response Helpers
|
|
3
|
+
* ts-rest 响应辅助工具
|
|
4
|
+
*
|
|
5
|
+
* 提供标准化的响应格式:
|
|
6
|
+
* - 成功响应:{ code: 200, msg: 'ok', data: ... }
|
|
7
|
+
* - 错误响应:{ code: xxx, msg: 'xxxx', data: { error: ... } }
|
|
8
|
+
*
|
|
9
|
+
* 配合 ApiResponseSchema 定义的 Contract 使用
|
|
10
|
+
*/
|
|
11
|
+
import { ApiErrorCode } from '@dofe/infra-contracts';
|
|
12
|
+
/**
|
|
13
|
+
* 标准成功响应格式
|
|
14
|
+
*/
|
|
15
|
+
export interface SuccessBody<T> {
|
|
16
|
+
code: number;
|
|
17
|
+
msg: string;
|
|
18
|
+
data: T;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 标准错误响应格式(用于 ts-rest,使用 data 字段)
|
|
22
|
+
*/
|
|
23
|
+
export interface ErrorBody<T = unknown> {
|
|
24
|
+
code: number;
|
|
25
|
+
msg: string;
|
|
26
|
+
data: T;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* ts-rest 处理器响应类型
|
|
30
|
+
*/
|
|
31
|
+
export type TsRestResponse<T, S extends number = 200> = {
|
|
32
|
+
status: S;
|
|
33
|
+
body: SuccessBody<T>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* ts-rest 成功响应类型(仅包含成功体)
|
|
37
|
+
*/
|
|
38
|
+
export type TsRestSuccessResponse<T, S extends number = 200> = {
|
|
39
|
+
status: S;
|
|
40
|
+
body: SuccessBody<T>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* 创建成功响应
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* @TsRestHandler(c.getItem)
|
|
48
|
+
* async getItem() {
|
|
49
|
+
* return tsRestHandler(c.getItem, async ({ params }) => {
|
|
50
|
+
* const data = await this.service.findById(params.id);
|
|
51
|
+
* return success(data);
|
|
52
|
+
* });
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function success<T>(data: T, status?: 200): TsRestSuccessResponse<T, 200>;
|
|
57
|
+
/**
|
|
58
|
+
* 创建分页成功响应
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* return paginated(items, total, query.page, query.limit);
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function paginated<T>(list: T[], total: number, page: number, limit: number): TsRestSuccessResponse<{
|
|
66
|
+
list: T[];
|
|
67
|
+
total: number;
|
|
68
|
+
page: number;
|
|
69
|
+
limit: number;
|
|
70
|
+
}, 200>;
|
|
71
|
+
/**
|
|
72
|
+
* 创建 201 响应(创建成功)
|
|
73
|
+
*/
|
|
74
|
+
export declare function created<T>(data: T): TsRestSuccessResponse<T, 201>;
|
|
75
|
+
/**
|
|
76
|
+
* 创建删除成功响应
|
|
77
|
+
*/
|
|
78
|
+
export declare function deleted(): TsRestResponse<{
|
|
79
|
+
success: boolean;
|
|
80
|
+
}, 200>;
|
|
81
|
+
/**
|
|
82
|
+
* 创建成功响应体(用于普通 NestJS 控制器,不使用 ts-rest)
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* @Get('items')
|
|
87
|
+
* async getItems() {
|
|
88
|
+
* const items = await this.service.findAll();
|
|
89
|
+
* return successBody({ list: items });
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function successBody<T>(data: T): SuccessBody<T>;
|
|
94
|
+
/**
|
|
95
|
+
* 创建分页成功响应体(用于普通 NestJS 控制器)
|
|
96
|
+
*/
|
|
97
|
+
export declare function paginatedBody<T>(list: T[], total: number, page: number, limit: number): SuccessBody<{
|
|
98
|
+
list: T[];
|
|
99
|
+
total: number;
|
|
100
|
+
page: number;
|
|
101
|
+
limit: number;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* 创建删除成功响应体(用于普通 NestJS 控制器)
|
|
105
|
+
*/
|
|
106
|
+
export declare function deletedBody(): SuccessBody<{
|
|
107
|
+
success: boolean;
|
|
108
|
+
}>;
|
|
109
|
+
/**
|
|
110
|
+
* 创建错误响应体(用于普通 NestJS 控制器)
|
|
111
|
+
*/
|
|
112
|
+
export declare function errorBody<T = unknown>(errorCode: ApiErrorCode, errorData?: T): ErrorBody<T>;
|
|
113
|
+
export declare function deletedWithData<T>(data: T): TsRestResponse<T, 200>;
|
|
114
|
+
/**
|
|
115
|
+
* HTTP Status 字面量类型
|
|
116
|
+
*/
|
|
117
|
+
type HttpStatus = 200 | 201 | 204 | 400 | 401 | 403 | 404 | 409 | 410 | 429 | 500;
|
|
118
|
+
/**
|
|
119
|
+
* 创建 ts-rest 错误响应(使用 data 字段,符合 ApiResponseSchema)
|
|
120
|
+
*
|
|
121
|
+
* 注意:此函数返回 status: 200 类型以兼容 ts-rest 类型推断。
|
|
122
|
+
* 实际 HTTP 状态码由 errorCode 决定。
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* if (!item) {
|
|
127
|
+
* return error(CommonErrorCode.NotFound, { error: 'Item not found' });
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare function error<T = {
|
|
132
|
+
error: string;
|
|
133
|
+
}>(errorCode: ApiErrorCode, errorData?: T): {
|
|
134
|
+
status: HttpStatus;
|
|
135
|
+
body: SuccessBody<T>;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* 404 Not Found 错误响应(类型安全)
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* if (!item) {
|
|
143
|
+
* return notFound('Item not found');
|
|
144
|
+
* }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export declare function notFound<T = {
|
|
148
|
+
error: string;
|
|
149
|
+
}>(errorData?: T): {
|
|
150
|
+
status: 404;
|
|
151
|
+
body: SuccessBody<T>;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* 400 Bad Request 错误响应(类型安全)
|
|
155
|
+
*/
|
|
156
|
+
export declare function badRequest<T = {
|
|
157
|
+
error: string;
|
|
158
|
+
}>(errorData?: T): {
|
|
159
|
+
status: 400;
|
|
160
|
+
body: SuccessBody<T>;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* 401 Unauthorized 错误响应(类型安全)
|
|
164
|
+
*/
|
|
165
|
+
export declare function unauthorized<T = {
|
|
166
|
+
error: string;
|
|
167
|
+
}>(errorData?: T): {
|
|
168
|
+
status: 401;
|
|
169
|
+
body: SuccessBody<T>;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* 403 Forbidden 错误响应(类型安全)
|
|
173
|
+
*/
|
|
174
|
+
export declare function forbidden<T = {
|
|
175
|
+
error: string;
|
|
176
|
+
}>(errorData?: T): {
|
|
177
|
+
status: 403;
|
|
178
|
+
body: SuccessBody<T>;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* 409 Conflict 错误响应(类型安全)
|
|
182
|
+
*/
|
|
183
|
+
export declare function conflict<T = {
|
|
184
|
+
error: string;
|
|
185
|
+
}>(errorData?: T): {
|
|
186
|
+
status: 409;
|
|
187
|
+
body: SuccessBody<T>;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* 500 Internal Server Error 响应(类型安全)
|
|
191
|
+
*/
|
|
192
|
+
export declare function internalError<T = {
|
|
193
|
+
error: string;
|
|
194
|
+
}>(errorData?: T): {
|
|
195
|
+
status: 500;
|
|
196
|
+
body: SuccessBody<T>;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* 从错误码创建符合 Contract 标准的错误响应
|
|
200
|
+
*
|
|
201
|
+
* 与 error() 相同,提供更好的语义化命名。
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* if (!item) {
|
|
206
|
+
* return errorResponse(CommonErrorCode.NotFound, { error: 'Item not found' });
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export declare function errorResponse<T = {
|
|
211
|
+
error: string;
|
|
212
|
+
}>(errorCode: ApiErrorCode, errorData?: T): {
|
|
213
|
+
status: HttpStatus;
|
|
214
|
+
body: SuccessBody<T>;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* 从错误类型字符串创建错误响应
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* return errorFromType('userNotFound', 200401, 404);
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
export declare function errorFromType<T = unknown>(errorType: string, errorCode: number, httpStatus?: HttpStatus, errorData?: T): {
|
|
225
|
+
status: HttpStatus;
|
|
226
|
+
body: SuccessBody<T>;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* 创建简单错误响应(不带 error 详情)
|
|
230
|
+
*/
|
|
231
|
+
export declare function errorSimple(code: number, msg: string, httpStatus?: HttpStatus): {
|
|
232
|
+
status: HttpStatus;
|
|
233
|
+
body: SuccessBody<unknown>;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* 递归地将对象中的 Date 类型转换为 ISO 字符串
|
|
237
|
+
* 用于确保 ts-rest 响应符合 zod schema(Date 字段定义为 z.coerce.date())
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const data = await this.service.findById(id);
|
|
242
|
+
* return success(serializeDates(data));
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
export declare function serializeDates<T>(obj: T): any;
|
|
246
|
+
/**
|
|
247
|
+
* 安全获取数据 - 如果查询抛出 NotFoundException 则返回 null
|
|
248
|
+
* 用于配合 notFound() 辅助函数,简化类型安全的错误处理
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* const result = await fetchOrNull(() =>
|
|
253
|
+
* this.service.findById(params.id),
|
|
254
|
+
* );
|
|
255
|
+
* if (result === null) return notFound({ error: 'Item not found' });
|
|
256
|
+
* return success(result);
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
export declare function fetchOrNull<T>(fn: () => Promise<T>): Promise<T | null>;
|
|
260
|
+
export {};
|
|
261
|
+
//# sourceMappingURL=response.helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.helper.d.ts","sourceRoot":"","sources":["../../src/ts-rest/response.helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,YAAY,EAIb,MAAM,uBAAuB,CAAC;AAE/B;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,CAAC,CAAC;CACT;AAED;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,CAAC,CAAC;CACT;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,GAAG,IAAI;IACtD,MAAM,E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ACH,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,EACvC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,UAAU,GAAE,UAAgB,EAC5B,SAAS,CAAC,EAAE,CAAC,GACZ;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CAAE,CAW9C;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,UAAU,GAAE,UAAgB,GAC3B;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAAE,CASpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,GAAG,CAsB7C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAcnB"}
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ts-rest Response Helpers
|
|
4
|
+
* ts-rest 响应辅助工具
|
|
5
|
+
*
|
|
6
|
+
* 提供标准化的响应格式:
|
|
7
|
+
* - 成功响应:{ code: 200, msg: 'ok', data: ... }
|
|
8
|
+
* - 错误响应:{ code: xxx, msg: 'xxxx', data: { error: ... } }
|
|
9
|
+
*
|
|
10
|
+
* 配合 ApiResponseSchema 定义的 Contract 使用
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.success = success;
|
|
14
|
+
exports.paginated = paginated;
|
|
15
|
+
exports.created = created;
|
|
16
|
+
exports.deleted = deleted;
|
|
17
|
+
exports.successBody = successBody;
|
|
18
|
+
exports.paginatedBody = paginatedBody;
|
|
19
|
+
exports.deletedBody = deletedBody;
|
|
20
|
+
exports.errorBody = errorBody;
|
|
21
|
+
exports.deletedWithData = deletedWithData;
|
|
22
|
+
exports.error = error;
|
|
23
|
+
exports.notFound = notFound;
|
|
24
|
+
exports.badRequest = badRequest;
|
|
25
|
+
exports.unauthorized = unauthorized;
|
|
26
|
+
exports.forbidden = forbidden;
|
|
27
|
+
exports.conflict = conflict;
|
|
28
|
+
exports.internalError = internalError;
|
|
29
|
+
exports.errorResponse = errorResponse;
|
|
30
|
+
exports.errorFromType = errorFromType;
|
|
31
|
+
exports.errorSimple = errorSimple;
|
|
32
|
+
exports.serializeDates = serializeDates;
|
|
33
|
+
exports.fetchOrNull = fetchOrNull;
|
|
34
|
+
const infra_contracts_1 = require("@dofe/infra-contracts");
|
|
35
|
+
/**
|
|
36
|
+
* 创建成功响应
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* @TsRestHandler(c.getItem)
|
|
41
|
+
* async getItem() {
|
|
42
|
+
* return tsRestHandler(c.getItem, async ({ params }) => {
|
|
43
|
+
* const data = await this.service.findById(params.id);
|
|
44
|
+
* return success(data);
|
|
45
|
+
* });
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
function success(data, status = 200) {
|
|
50
|
+
return {
|
|
51
|
+
status,
|
|
52
|
+
body: {
|
|
53
|
+
code: 200,
|
|
54
|
+
msg: 'ok',
|
|
55
|
+
data: serializeDates(data),
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 创建分页成功响应
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* return paginated(items, total, query.page, query.limit);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
function paginated(list, total, page, limit) {
|
|
68
|
+
return success({ list, total, page, limit });
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 创建 201 响应(创建成功)
|
|
72
|
+
*/
|
|
73
|
+
function created(data) {
|
|
74
|
+
return {
|
|
75
|
+
status: 201,
|
|
76
|
+
body: {
|
|
77
|
+
code: 200,
|
|
78
|
+
msg: 'ok',
|
|
79
|
+
data: serializeDates(data),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 创建删除成功响应
|
|
85
|
+
*/
|
|
86
|
+
function deleted() {
|
|
87
|
+
return {
|
|
88
|
+
status: 200,
|
|
89
|
+
body: {
|
|
90
|
+
code: 200,
|
|
91
|
+
msg: 'ok',
|
|
92
|
+
data: { success: true },
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// ============================================================================
|
|
97
|
+
// Plain NestJS Controller Helpers (不使用 ts-rest 的控制器)
|
|
98
|
+
// ============================================================================
|
|
99
|
+
/**
|
|
100
|
+
* 创建成功响应体(用于普通 NestJS 控制器,不使用 ts-rest)
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* @Get('items')
|
|
105
|
+
* async getItems() {
|
|
106
|
+
* const items = await this.service.findAll();
|
|
107
|
+
* return successBody({ list: items });
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
function successBody(data) {
|
|
112
|
+
return {
|
|
113
|
+
code: 200,
|
|
114
|
+
msg: 'ok',
|
|
115
|
+
data: serializeDates(data),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 创建分页成功响应体(用于普通 NestJS 控制器)
|
|
120
|
+
*/
|
|
121
|
+
function paginatedBody(list, total, page, limit) {
|
|
122
|
+
return successBody({ list, total, page, limit });
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 创建删除成功响应体(用于普通 NestJS 控制器)
|
|
126
|
+
*/
|
|
127
|
+
function deletedBody() {
|
|
128
|
+
return {
|
|
129
|
+
code: 200,
|
|
130
|
+
msg: 'ok',
|
|
131
|
+
data: { success: true },
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 创建错误响应体(用于普通 NestJS 控制器)
|
|
136
|
+
*/
|
|
137
|
+
function errorBody(errorCode, errorData) {
|
|
138
|
+
const errorType = (0, infra_contracts_1.getErrorType)(errorCode) || 'unknown';
|
|
139
|
+
const numericCode = Number(errorCode);
|
|
140
|
+
const msg = (0, infra_contracts_1.getErrorMessage)(errorType);
|
|
141
|
+
return {
|
|
142
|
+
code: numericCode,
|
|
143
|
+
msg,
|
|
144
|
+
data: errorData,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function deletedWithData(data) {
|
|
148
|
+
return {
|
|
149
|
+
status: 200,
|
|
150
|
+
body: {
|
|
151
|
+
code: 200,
|
|
152
|
+
msg: 'ok',
|
|
153
|
+
data: serializeDates(data),
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 创建 ts-rest 错误响应(使用 data 字段,符合 ApiResponseSchema)
|
|
159
|
+
*
|
|
160
|
+
* 注意:此函数返回 status: 200 类型以兼容 ts-rest 类型推断。
|
|
161
|
+
* 实际 HTTP 状态码由 errorCode 决定。
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* if (!item) {
|
|
166
|
+
* return error(CommonErrorCode.NotFound, { error: 'Item not found' });
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
function error(errorCode, errorData) {
|
|
171
|
+
const errorType = (0, infra_contracts_1.getErrorType)(errorCode) || 'unknown';
|
|
172
|
+
const httpStatus = (0, infra_contracts_1.getHttpStatus)(errorCode);
|
|
173
|
+
const numericCode = Number(errorCode);
|
|
174
|
+
const msg = (0, infra_contracts_1.getErrorMessage)(errorType);
|
|
175
|
+
return {
|
|
176
|
+
status: httpStatus,
|
|
177
|
+
body: {
|
|
178
|
+
code: numericCode,
|
|
179
|
+
msg,
|
|
180
|
+
data: errorData,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* 404 Not Found 错误响应(类型安全)
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* if (!item) {
|
|
190
|
+
* return notFound('Item not found');
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
function notFound(errorData) {
|
|
195
|
+
return {
|
|
196
|
+
status: 404,
|
|
197
|
+
body: {
|
|
198
|
+
code: 905404,
|
|
199
|
+
msg: (0, infra_contracts_1.getErrorMessage)('notFound'),
|
|
200
|
+
data: errorData,
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* 400 Bad Request 错误响应(类型安全)
|
|
206
|
+
*/
|
|
207
|
+
function badRequest(errorData) {
|
|
208
|
+
return {
|
|
209
|
+
status: 400,
|
|
210
|
+
body: {
|
|
211
|
+
code: 900400,
|
|
212
|
+
msg: (0, infra_contracts_1.getErrorMessage)('badRequest'),
|
|
213
|
+
data: errorData,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* 401 Unauthorized 错误响应(类型安全)
|
|
219
|
+
*/
|
|
220
|
+
function unauthorized(errorData) {
|
|
221
|
+
return {
|
|
222
|
+
status: 401,
|
|
223
|
+
body: {
|
|
224
|
+
code: 923402,
|
|
225
|
+
msg: (0, infra_contracts_1.getErrorMessage)('unAuthorized'),
|
|
226
|
+
data: errorData,
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* 403 Forbidden 错误响应(类型安全)
|
|
232
|
+
*/
|
|
233
|
+
function forbidden(errorData) {
|
|
234
|
+
return {
|
|
235
|
+
status: 403,
|
|
236
|
+
body: {
|
|
237
|
+
code: 924403,
|
|
238
|
+
msg: (0, infra_contracts_1.getErrorMessage)('unauthorizedByKey'),
|
|
239
|
+
data: errorData,
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* 409 Conflict 错误响应(类型安全)
|
|
245
|
+
*/
|
|
246
|
+
function conflict(errorData) {
|
|
247
|
+
return {
|
|
248
|
+
status: 409,
|
|
249
|
+
body: {
|
|
250
|
+
code: 900403,
|
|
251
|
+
msg: (0, infra_contracts_1.getErrorMessage)('featureAlreadyExists'),
|
|
252
|
+
data: errorData,
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* 500 Internal Server Error 响应(类型安全)
|
|
258
|
+
*/
|
|
259
|
+
function internalError(errorData) {
|
|
260
|
+
return {
|
|
261
|
+
status: 500,
|
|
262
|
+
body: {
|
|
263
|
+
code: 900500,
|
|
264
|
+
msg: (0, infra_contracts_1.getErrorMessage)('innerError'),
|
|
265
|
+
data: errorData,
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* 从错误码创建符合 Contract 标准的错误响应
|
|
271
|
+
*
|
|
272
|
+
* 与 error() 相同,提供更好的语义化命名。
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* if (!item) {
|
|
277
|
+
* return errorResponse(CommonErrorCode.NotFound, { error: 'Item not found' });
|
|
278
|
+
* }
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
function errorResponse(errorCode, errorData) {
|
|
282
|
+
return error(errorCode, errorData);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* 从错误类型字符串创建错误响应
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* return errorFromType('userNotFound', 200401, 404);
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
function errorFromType(errorType, errorCode, httpStatus = 400, errorData) {
|
|
293
|
+
const msg = (0, infra_contracts_1.getErrorMessage)(errorType);
|
|
294
|
+
return {
|
|
295
|
+
status: httpStatus,
|
|
296
|
+
body: {
|
|
297
|
+
code: errorCode,
|
|
298
|
+
msg,
|
|
299
|
+
data: errorData,
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* 创建简单错误响应(不带 error 详情)
|
|
305
|
+
*/
|
|
306
|
+
function errorSimple(code, msg, httpStatus = 400) {
|
|
307
|
+
return {
|
|
308
|
+
status: httpStatus,
|
|
309
|
+
body: {
|
|
310
|
+
code,
|
|
311
|
+
msg,
|
|
312
|
+
data: undefined,
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* 递归地将对象中的 Date 类型转换为 ISO 字符串
|
|
318
|
+
* 用于确保 ts-rest 响应符合 zod schema(Date 字段定义为 z.coerce.date())
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```typescript
|
|
322
|
+
* const data = await this.service.findById(id);
|
|
323
|
+
* return success(serializeDates(data));
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
function serializeDates(obj) {
|
|
327
|
+
if (obj === null || obj === undefined) {
|
|
328
|
+
return obj;
|
|
329
|
+
}
|
|
330
|
+
if (obj instanceof Date) {
|
|
331
|
+
return obj.toISOString();
|
|
332
|
+
}
|
|
333
|
+
if (Array.isArray(obj)) {
|
|
334
|
+
return obj.map((item) => serializeDates(item));
|
|
335
|
+
}
|
|
336
|
+
if (typeof obj === 'object') {
|
|
337
|
+
const result = {};
|
|
338
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
339
|
+
result[key] = serializeDates(value);
|
|
340
|
+
}
|
|
341
|
+
return result;
|
|
342
|
+
}
|
|
343
|
+
return obj;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* 安全获取数据 - 如果查询抛出 NotFoundException 则返回 null
|
|
347
|
+
* 用于配合 notFound() 辅助函数,简化类型安全的错误处理
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* const result = await fetchOrNull(() =>
|
|
352
|
+
* this.service.findById(params.id),
|
|
353
|
+
* );
|
|
354
|
+
* if (result === null) return notFound({ error: 'Item not found' });
|
|
355
|
+
* return success(result);
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
async function fetchOrNull(fn) {
|
|
359
|
+
try {
|
|
360
|
+
return await fn();
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
if (error &&
|
|
364
|
+
typeof error === 'object' &&
|
|
365
|
+
'name' in error &&
|
|
366
|
+
error.name === 'NotFoundException') {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
throw error;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
//# sourceMappingURL=response.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.helper.js","sourceRoot":"","sources":["../../src/ts-rest/response.helper.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAyDH,0BAYC;AAUD,8BAUC;AAKD,0BASC;AAKD,0BASC;AAkBD,kCAMC;AAKD,sCAOC;AAKD,kCAMC;AAKD,8BAaC;AAED,0CASC;AAmCD,sBAiBC;AAYD,4BAWC;AAKD,gCAWC;AAKD,oCAWC;AAKD,8BAWC;AAKD,4BAWC;AAKD,sCAWC;AAcD,sCAKC;AAUD,sCAgBC;AAKD,kCAaC;AAYD,wCAsBC;AAeD,kCAgBC;AA1dD,2DAK+B;AAoC/B;;;;;;;;;;;;;GAaG;AACH,SAAgB,OAAO,CACrB,IAAO,EACP,SAAc,GAAG;IAEjB,OAAO;QACL,MAAM;QACN,IAAI,EAAE;YACJ,IAAI,EAAE,GAAG;YACT,GAAG,EAAE,IAAI;YACT,IAAI,EAA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AAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,WAAW,CAC/B,EAAoB;IAEpB,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IACE,KAAK;YACL,OAAO,KAAK,KAAK,QAAQ;YACzB,MAAM,IAAI,KAAK;YACd,KAA0B,CAAC,IAAI,KAAK,mBAAmB,EACxD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Audit log create data — uses loose typing since the Prisma schema may evolve */
|
|
2
|
+
type AuditLogData = Record<string, any>;
|
|
3
|
+
/**
|
|
4
|
+
* 为审计日志数据添加签名并脱敏敏感数据
|
|
5
|
+
*
|
|
6
|
+
* @param data Prisma 创建输入数据
|
|
7
|
+
* @returns 带签名且脱敏后的数据
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const data = prepareAuditLogWithSignature({
|
|
12
|
+
* user: { connect: { id: userId } },
|
|
13
|
+
* operateType: 'CREATE',
|
|
14
|
+
* target: 'BOT',
|
|
15
|
+
* targetId: botId,
|
|
16
|
+
* detail: { apiKey: 'sk-xxxx' }, // 会被脱敏为 { apiKey: 'sk-***' }
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* await operateLogService.create(data);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function prepareAuditLogWithSignature<T extends AuditLogData>(data: T): T;
|
|
23
|
+
/**
|
|
24
|
+
* 验证审计日志记录的签名
|
|
25
|
+
*
|
|
26
|
+
* @param log 审计日志记录
|
|
27
|
+
* @returns 验证是否通过
|
|
28
|
+
*/
|
|
29
|
+
export declare function verifyAuditLogSignature(log: {
|
|
30
|
+
operateType?: unknown;
|
|
31
|
+
target?: unknown;
|
|
32
|
+
targetId?: unknown;
|
|
33
|
+
targetName?: unknown;
|
|
34
|
+
tenant?: any;
|
|
35
|
+
result?: unknown;
|
|
36
|
+
userId: string;
|
|
37
|
+
signature?: string | null;
|
|
38
|
+
createdAt: Date | string;
|
|
39
|
+
}): boolean;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=audit-log-helper.util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log-helper.util.d.ts","sourceRoot":"","sources":["../../src/utils/audit-log-helper.util.ts"],"names":[],"mappings":"AAkBA,mFAAmF;AAEnF,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAoExC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,4BAA4B,CAAC,CAAC,SAAS,YAAY,EACjE,IAAI,EAAE,CAAC,GACN,CAAC,CAaH;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;CAC1B,GACA,OAAO,CAkBT"}
|