@nest-omni/core 1.0.57 → 2.0.1-0
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/.history/src/common/boilerplate.polyfill_20250521135408.ts +202 -0
- package/.history/src/common/boilerplate.polyfill_20250712165919.ts +254 -0
- package/.history/src/common/boilerplate.polyfill_20250712165924.ts +254 -0
- package/.history/src/common/boilerplate.polyfill_20250712165927.ts +254 -0
- package/.history/src/common/boilerplate.polyfill_20250712170044.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170049.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170053.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170610.ts +280 -0
- package/.history/src/common/boilerplate.polyfill_20250712170614.ts +280 -0
- package/.history/src/common/boilerplate.polyfill_20250712170739.ts +265 -0
- package/.history/src/common/boilerplate.polyfill_20250712170801.ts +291 -0
- package/.history/src/common/boilerplate.polyfill_20250712170809.ts +317 -0
- package/.history/src/common/boilerplate.polyfill_20250712170816.ts +319 -0
- package/.history/src/common/boilerplate.polyfill_20250712170820.ts +318 -0
- package/.history/src/common/boilerplate.polyfill_20250712170824.ts +318 -0
- package/.history/src/common/boilerplate.polyfill_20250712171040.ts +289 -0
- package/README.md +16 -0
- package/build.sh +45 -0
- package/{common → dist/common}/abstract.entity.d.ts +1 -0
- package/{common → dist/common}/abstract.entity.js +13 -0
- package/{decorators → dist/decorators}/field.decorators.d.ts +1 -1
- package/dist/package.json +71 -0
- package/dist/setup/bootstrap.setup.d.ts +2 -0
- package/{setup → dist/setup}/bootstrap.setup.js +45 -27
- package/{shared → dist/shared}/serviceRegistryModule.js +4 -11
- package/{shared → dist/shared}/services/api-config.service.d.ts +3 -15
- package/{shared → dist/shared}/services/api-config.service.js +15 -42
- package/{shared → dist/shared}/services/index.d.ts +0 -1
- package/{shared → dist/shared}/services/index.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/yarn.lock +644 -0
- package/package.json +1 -3
- package/src/.hygen.js +116 -0
- package/src/common/abstract-client.service.ts +56 -0
- package/src/common/abstract.entity.ts +82 -0
- package/src/common/boilerplate.polyfill.ts +202 -0
- package/src/common/dto/abstract.dto.ts +61 -0
- package/src/common/dto/bulk-id.dto.ts +13 -0
- package/src/common/dto/create-translation.dto.ts +10 -0
- package/src/common/dto/index.ts +6 -0
- package/src/common/dto/page-meta.dto.ts +37 -0
- package/src/common/dto/page-options.dto.ts +35 -0
- package/src/common/dto/page.dto.ts +36 -0
- package/src/common/index.ts +7 -0
- package/src/common/snake-naming.strategy.ts +64 -0
- package/src/common/types.ts +44 -0
- package/src/common/utils.ts +45 -0
- package/src/constants/index.ts +2 -0
- package/src/constants/language-code.ts +7 -0
- package/src/constants/order.ts +4 -0
- package/src/decorators/api-page-ok-response.decorator.ts +32 -0
- package/src/decorators/auth-user.decorator.ts +16 -0
- package/src/decorators/controller.decorator.ts +8 -0
- package/src/decorators/field.decorators.ts +856 -0
- package/src/decorators/http.decorators.ts +10 -0
- package/src/decorators/index.ts +12 -0
- package/src/decorators/operation.decorator.ts +4 -0
- package/src/decorators/property.decorators.ts +62 -0
- package/src/decorators/public-route.decorator.ts +8 -0
- package/src/decorators/swagger.schema.ts +117 -0
- package/src/decorators/timestamp-column.decorator.ts +29 -0
- package/src/decorators/transform.decorators.ts +159 -0
- package/src/decorators/translate.decorator.ts +19 -0
- package/src/decorators/use-dto.decorator.ts +11 -0
- package/src/decorators/user-check.decorator.ts +30 -0
- package/src/decorators/user.decorator.ts +59 -0
- package/src/decorators/user_auth.decorator.ts +15 -0
- package/src/decorators/validator.decorators.ts +98 -0
- package/src/exceptions/file-not-image.exception.ts +7 -0
- package/src/exceptions/index.ts +2 -0
- package/src/exceptions/page-type.exception.ts +7 -0
- package/src/exceptions/user-not-found.exception.ts +7 -0
- package/src/filters/bad-request.filter.ts +77 -0
- package/src/filters/constraint-errors.ts +5 -0
- package/src/filters/index.ts +3 -0
- package/src/filters/query-failed.filter.ts +32 -0
- package/src/health-checker/health-checker.controller.ts +51 -0
- package/src/health-checker/health-checker.module.ts +13 -0
- package/src/health-checker/health-indicators/service.indicator.ts +44 -0
- package/src/helpers/common.helper.ts +49 -0
- package/src/helpers/date.helper.ts +64 -0
- package/src/helpers/index.ts +2 -0
- package/src/i18n/en_US/validation.json +41 -0
- package/src/i18n/zh_CN/validation.json +41 -0
- package/src/index.ts +11 -0
- package/src/interceptors/index.ts +2 -0
- package/src/interceptors/language-interceptor.service.ts +28 -0
- package/src/interceptors/translation-interceptor.service.ts +43 -0
- package/src/interfaces/IApiFile.ts +4 -0
- package/src/interfaces/IFile.ts +8 -0
- package/src/interfaces/ITranslationDecoratorInterface.ts +3 -0
- package/src/interfaces/index.ts +3 -0
- package/src/interfaces/response.ts +37 -0
- package/src/middlewares/index.ts +4 -0
- package/src/middlewares/omni-auth.middleware.ts +10 -0
- package/src/middlewares/powerby.middleware.ts +6 -0
- package/src/middlewares/request-id.middleware.ts +28 -0
- package/src/middlewares/xml.middleware.ts +14 -0
- package/src/providers/context.provider.ts +109 -0
- package/src/providers/generator.provider.ts +66 -0
- package/src/providers/index.ts +2 -0
- package/src/setup/bootstrap.setup.ts +254 -0
- package/src/setup/index.ts +1 -0
- package/src/shared/index.ts +2 -0
- package/src/shared/serviceRegistryModule.ts +135 -0
- package/src/shared/services/api-config.service.ts +336 -0
- package/src/shared/services/generator.service.ts +13 -0
- package/src/shared/services/index.ts +4 -0
- package/src/shared/services/translation.service.ts +59 -0
- package/src/shared/services/validator.service.ts +10 -0
- package/src/validator-json/decorators.ts +63 -0
- package/src/validator-json/default.ts +257 -0
- package/src/validator-json/defaultConverters.ts +402 -0
- package/src/validator-json/index.ts +4 -0
- package/src/validator-json/options.ts +50 -0
- package/src/validators/file-mimetype.validator.ts +34 -0
- package/src/validators/index.ts +6 -0
- package/src/validators/is-exists.validator.ts +60 -0
- package/src/validators/is-unique.validator.ts +93 -0
- package/src/validators/phone-country-code.validator.ts +36 -0
- package/src/validators/same-as.validator.ts +27 -0
- package/src/validators/skip-empty.validator.ts +25 -0
- package/tsconfig.json +31 -0
- package/tsconfig.lib.json +16 -0
- package/setup/bootstrap.setup.d.ts +0 -2
- package/shared/services/aws-s3.service.d.ts +0 -10
- package/shared/services/aws-s3.service.js +0 -56
- package/tsconfig.tsbuildinfo +0 -1
- /package/{.hygen → dist/.hygen}/new/crud/controller.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/create.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/entity.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/get.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/index-dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/index-response.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/module.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/prompt.js +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/service.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/crud/update.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/controller.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/create-command.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/create.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/entity.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/get-query.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/module.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/not-found.exception.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/page-options.dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/prompt.js +0 -0
- /package/{.hygen → dist/.hygen}/new/module/repository.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/service.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/translation-dto.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/translation-entity.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/translation-repository.ejs.t +0 -0
- /package/{.hygen → dist/.hygen}/new/module/update.dto.ejs.t +0 -0
- /package/{.hygen.js → dist/.hygen.js} +0 -0
- /package/{common → dist/common}/abstract-client.service.d.ts +0 -0
- /package/{common → dist/common}/abstract-client.service.js +0 -0
- /package/{common → dist/common}/boilerplate.polyfill.d.ts +0 -0
- /package/{common → dist/common}/boilerplate.polyfill.js +0 -0
- /package/{common → dist/common}/dto/abstract.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/abstract.dto.js +0 -0
- /package/{common → dist/common}/dto/bulk-id.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/bulk-id.dto.js +0 -0
- /package/{common → dist/common}/dto/create-translation.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/create-translation.dto.js +0 -0
- /package/{common → dist/common}/dto/index.d.ts +0 -0
- /package/{common → dist/common}/dto/index.js +0 -0
- /package/{common → dist/common}/dto/page-meta.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/page-meta.dto.js +0 -0
- /package/{common → dist/common}/dto/page-options.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/page-options.dto.js +0 -0
- /package/{common → dist/common}/dto/page.dto.d.ts +0 -0
- /package/{common → dist/common}/dto/page.dto.js +0 -0
- /package/{common → dist/common}/index.d.ts +0 -0
- /package/{common → dist/common}/index.js +0 -0
- /package/{common → dist/common}/snake-naming.strategy.d.ts +0 -0
- /package/{common → dist/common}/snake-naming.strategy.js +0 -0
- /package/{common → dist/common}/types.d.ts +0 -0
- /package/{common → dist/common}/types.js +0 -0
- /package/{common → dist/common}/utils.d.ts +0 -0
- /package/{common → dist/common}/utils.js +0 -0
- /package/{constants → dist/constants}/index.d.ts +0 -0
- /package/{constants → dist/constants}/index.js +0 -0
- /package/{constants → dist/constants}/language-code.d.ts +0 -0
- /package/{constants → dist/constants}/language-code.js +0 -0
- /package/{constants → dist/constants}/order.d.ts +0 -0
- /package/{constants → dist/constants}/order.js +0 -0
- /package/{decorators → dist/decorators}/api-page-ok-response.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/api-page-ok-response.decorator.js +0 -0
- /package/{decorators → dist/decorators}/auth-user.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/auth-user.decorator.js +0 -0
- /package/{decorators → dist/decorators}/controller.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/controller.decorator.js +0 -0
- /package/{decorators → dist/decorators}/field.decorators.js +0 -0
- /package/{decorators → dist/decorators}/http.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/http.decorators.js +0 -0
- /package/{decorators → dist/decorators}/index.d.ts +0 -0
- /package/{decorators → dist/decorators}/index.js +0 -0
- /package/{decorators → dist/decorators}/operation.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/operation.decorator.js +0 -0
- /package/{decorators → dist/decorators}/property.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/property.decorators.js +0 -0
- /package/{decorators → dist/decorators}/public-route.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/public-route.decorator.js +0 -0
- /package/{decorators → dist/decorators}/swagger.schema.d.ts +0 -0
- /package/{decorators → dist/decorators}/swagger.schema.js +0 -0
- /package/{decorators → dist/decorators}/timestamp-column.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/timestamp-column.decorator.js +0 -0
- /package/{decorators → dist/decorators}/transform.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/transform.decorators.js +0 -0
- /package/{decorators → dist/decorators}/translate.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/translate.decorator.js +0 -0
- /package/{decorators → dist/decorators}/use-dto.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/use-dto.decorator.js +0 -0
- /package/{decorators → dist/decorators}/user-check.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/user-check.decorator.js +0 -0
- /package/{decorators → dist/decorators}/user.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/user.decorator.js +0 -0
- /package/{decorators → dist/decorators}/user_auth.decorator.d.ts +0 -0
- /package/{decorators → dist/decorators}/user_auth.decorator.js +0 -0
- /package/{decorators → dist/decorators}/validator.decorators.d.ts +0 -0
- /package/{decorators → dist/decorators}/validator.decorators.js +0 -0
- /package/{exceptions → dist/exceptions}/file-not-image.exception.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/file-not-image.exception.js +0 -0
- /package/{exceptions → dist/exceptions}/index.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/index.js +0 -0
- /package/{exceptions → dist/exceptions}/page-type.exception.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/page-type.exception.js +0 -0
- /package/{exceptions → dist/exceptions}/user-not-found.exception.d.ts +0 -0
- /package/{exceptions → dist/exceptions}/user-not-found.exception.js +0 -0
- /package/{filters → dist/filters}/bad-request.filter.d.ts +0 -0
- /package/{filters → dist/filters}/bad-request.filter.js +0 -0
- /package/{filters → dist/filters}/constraint-errors.d.ts +0 -0
- /package/{filters → dist/filters}/constraint-errors.js +0 -0
- /package/{filters → dist/filters}/index.d.ts +0 -0
- /package/{filters → dist/filters}/index.js +0 -0
- /package/{filters → dist/filters}/query-failed.filter.d.ts +0 -0
- /package/{filters → dist/filters}/query-failed.filter.js +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.controller.d.ts +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.controller.js +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.module.d.ts +0 -0
- /package/{health-checker → dist/health-checker}/health-checker.module.js +0 -0
- /package/{health-checker → dist/health-checker}/health-indicators/service.indicator.d.ts +0 -0
- /package/{health-checker → dist/health-checker}/health-indicators/service.indicator.js +0 -0
- /package/{helpers → dist/helpers}/common.helper.d.ts +0 -0
- /package/{helpers → dist/helpers}/common.helper.js +0 -0
- /package/{helpers → dist/helpers}/date.helper.d.ts +0 -0
- /package/{helpers → dist/helpers}/date.helper.js +0 -0
- /package/{helpers → dist/helpers}/index.d.ts +0 -0
- /package/{helpers → dist/helpers}/index.js +0 -0
- /package/{i18n → dist/i18n}/en_US/validation.json +0 -0
- /package/{i18n → dist/i18n}/zh_CN/validation.json +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{interceptors → dist/interceptors}/index.d.ts +0 -0
- /package/{interceptors → dist/interceptors}/index.js +0 -0
- /package/{interceptors → dist/interceptors}/language-interceptor.service.d.ts +0 -0
- /package/{interceptors → dist/interceptors}/language-interceptor.service.js +0 -0
- /package/{interceptors → dist/interceptors}/translation-interceptor.service.d.ts +0 -0
- /package/{interceptors → dist/interceptors}/translation-interceptor.service.js +0 -0
- /package/{interfaces → dist/interfaces}/IApiFile.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/IApiFile.js +0 -0
- /package/{interfaces → dist/interfaces}/IFile.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/IFile.js +0 -0
- /package/{interfaces → dist/interfaces}/ITranslationDecoratorInterface.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/ITranslationDecoratorInterface.js +0 -0
- /package/{interfaces → dist/interfaces}/index.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/index.js +0 -0
- /package/{interfaces → dist/interfaces}/response.d.ts +0 -0
- /package/{interfaces → dist/interfaces}/response.js +0 -0
- /package/{middlewares → dist/middlewares}/index.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/index.js +0 -0
- /package/{middlewares → dist/middlewares}/omni-auth.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/omni-auth.middleware.js +0 -0
- /package/{middlewares → dist/middlewares}/powerby.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/powerby.middleware.js +0 -0
- /package/{middlewares → dist/middlewares}/request-id.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/request-id.middleware.js +0 -0
- /package/{middlewares → dist/middlewares}/xml.middleware.d.ts +0 -0
- /package/{middlewares → dist/middlewares}/xml.middleware.js +0 -0
- /package/{providers → dist/providers}/context.provider.d.ts +0 -0
- /package/{providers → dist/providers}/context.provider.js +0 -0
- /package/{providers → dist/providers}/generator.provider.d.ts +0 -0
- /package/{providers → dist/providers}/generator.provider.js +0 -0
- /package/{providers → dist/providers}/index.d.ts +0 -0
- /package/{providers → dist/providers}/index.js +0 -0
- /package/{setup → dist/setup}/index.d.ts +0 -0
- /package/{setup → dist/setup}/index.js +0 -0
- /package/{shared → dist/shared}/index.d.ts +0 -0
- /package/{shared → dist/shared}/index.js +0 -0
- /package/{shared → dist/shared}/serviceRegistryModule.d.ts +0 -0
- /package/{shared → dist/shared}/services/generator.service.d.ts +0 -0
- /package/{shared → dist/shared}/services/generator.service.js +0 -0
- /package/{shared → dist/shared}/services/translation.service.d.ts +0 -0
- /package/{shared → dist/shared}/services/translation.service.js +0 -0
- /package/{shared → dist/shared}/services/validator.service.d.ts +0 -0
- /package/{shared → dist/shared}/services/validator.service.js +0 -0
- /package/{validator-json → dist/validator-json}/decorators.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/decorators.js +0 -0
- /package/{validator-json → dist/validator-json}/default.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/default.js +0 -0
- /package/{validator-json → dist/validator-json}/defaultConverters.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/defaultConverters.js +0 -0
- /package/{validator-json → dist/validator-json}/index.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/index.js +0 -0
- /package/{validator-json → dist/validator-json}/options.d.ts +0 -0
- /package/{validator-json → dist/validator-json}/options.js +0 -0
- /package/{validators → dist/validators}/file-mimetype.validator.d.ts +0 -0
- /package/{validators → dist/validators}/file-mimetype.validator.js +0 -0
- /package/{validators → dist/validators}/index.d.ts +0 -0
- /package/{validators → dist/validators}/index.js +0 -0
- /package/{validators → dist/validators}/is-exists.validator.d.ts +0 -0
- /package/{validators → dist/validators}/is-exists.validator.js +0 -0
- /package/{validators → dist/validators}/is-unique.validator.d.ts +0 -0
- /package/{validators → dist/validators}/is-unique.validator.js +0 -0
- /package/{validators → dist/validators}/phone-country-code.validator.d.ts +0 -0
- /package/{validators → dist/validators}/phone-country-code.validator.js +0 -0
- /package/{validators → dist/validators}/same-as.validator.d.ts +0 -0
- /package/{validators → dist/validators}/same-as.validator.js +0 -0
- /package/{validators → dist/validators}/skip-empty.validator.d.ts +0 -0
- /package/{validators → dist/validators}/skip-empty.validator.js +0 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import type { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
|
4
|
+
import { isNil } from 'lodash';
|
|
5
|
+
import session from 'express-session';
|
|
6
|
+
import { Params } from 'nestjs-pino';
|
|
7
|
+
import { redisStore } from 'cache-manager-ioredis-yet';
|
|
8
|
+
import { BullRootModuleOptions } from '@nestjs/bull/dist/interfaces/bull-module-options.interface';
|
|
9
|
+
import RedisStore from 'connect-redis';
|
|
10
|
+
import Redis from 'ioredis';
|
|
11
|
+
import { AxiosProxyConfig } from 'axios';
|
|
12
|
+
import { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
13
|
+
import { SnakeNamingStrategy } from '../../common';
|
|
14
|
+
|
|
15
|
+
@Injectable()
|
|
16
|
+
export class ApiConfigService {
|
|
17
|
+
static rootPath: string;
|
|
18
|
+
|
|
19
|
+
constructor(private configService: ConfigService) {}
|
|
20
|
+
|
|
21
|
+
static getRootPath(): string {
|
|
22
|
+
if (!ApiConfigService.rootPath) {
|
|
23
|
+
throw new Error(`rootPath is not set`);
|
|
24
|
+
}
|
|
25
|
+
return ApiConfigService.rootPath;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get isDev(): boolean {
|
|
29
|
+
return this.nodeEnv === 'dev';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get apiVersion(): string {
|
|
33
|
+
return this.getString('API_VERSION');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get isProd(): boolean {
|
|
37
|
+
return this.nodeEnv === 'prod';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get isSit(): boolean {
|
|
41
|
+
return this.nodeEnv === 'sit';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get isUat(): boolean {
|
|
45
|
+
return this.nodeEnv === 'uat';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get isTest(): boolean {
|
|
49
|
+
return this.nodeEnv === 'test';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getNumber(key: string, defaultValue?: number): number {
|
|
53
|
+
const value = this.get(key, defaultValue);
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
return Number(value);
|
|
57
|
+
} catch {
|
|
58
|
+
throw new Error(`key:${key}, value:${value} - is not a number`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getBoolean(key: string, defaultValue?: boolean): boolean {
|
|
63
|
+
const value = this.get(key, defaultValue);
|
|
64
|
+
|
|
65
|
+
return ApiConfigService.toBoolean(value);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static toBoolean(value: string, defaultValue = null): boolean {
|
|
69
|
+
try {
|
|
70
|
+
return Boolean(JSON.parse(value));
|
|
71
|
+
} catch {
|
|
72
|
+
if (!isNil(defaultValue)) {
|
|
73
|
+
return defaultValue;
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`value:${value} - is not a boolean`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getString(key: string): string {
|
|
80
|
+
const value = this.get(key);
|
|
81
|
+
|
|
82
|
+
return value.replace(/\\n/g, '\n');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get nodeEnv(): string {
|
|
86
|
+
return this.getString('NODE_ENV');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get fallbackLanguage(): string {
|
|
90
|
+
return this.getString('FALLBACK_LANGUAGE');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get typeormConfig(): TypeOrmModuleOptions {
|
|
94
|
+
return {
|
|
95
|
+
autoLoadEntities: true,
|
|
96
|
+
keepConnectionAlive: !this.isDev,
|
|
97
|
+
type: 'mysql',
|
|
98
|
+
host: this.getString('DB_HOST'),
|
|
99
|
+
port: this.getNumber('DB_PORT'),
|
|
100
|
+
username: this.getString('DB_USERNAME'),
|
|
101
|
+
password: this.getString('DB_PASSWORD'),
|
|
102
|
+
database: this.getString('DB_DATABASE'),
|
|
103
|
+
subscribers: [],
|
|
104
|
+
synchronize: this.isDev,
|
|
105
|
+
migrationsRun: true,
|
|
106
|
+
logging: this.getBoolean('DB_LOG_ENABLED'),
|
|
107
|
+
maxQueryExecutionTime: 3000,
|
|
108
|
+
namingStrategy: new SnakeNamingStrategy(),
|
|
109
|
+
timezone: this.getString('TZ'),
|
|
110
|
+
cache: this.getBoolean('DB_CACHE_ENABLED')
|
|
111
|
+
? {
|
|
112
|
+
type: 'ioredis',
|
|
113
|
+
options: this.ioRedisConfig,
|
|
114
|
+
}
|
|
115
|
+
: false,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
get documentationEnabled(): boolean {
|
|
120
|
+
return this.getBoolean('SWAGGER_ENABLED');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
get documentationPath(): string {
|
|
124
|
+
return this.getString('SWAGGER_PATH');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
get viewsEnabled(): boolean {
|
|
128
|
+
return this.getBoolean('VIEWS_ENABLED');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get sessionEnabled(): boolean {
|
|
132
|
+
return this.getBoolean('SESSION_ENABLED');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
get corsEnabled(): boolean {
|
|
136
|
+
try {
|
|
137
|
+
return this.getBoolean('CORS_ENABLED');
|
|
138
|
+
} catch (error) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
get corsConfig(): CorsOptions {
|
|
144
|
+
const allowedDomains = this.getString('CORS_ORIGIN').split(',');
|
|
145
|
+
return {
|
|
146
|
+
origin: (origin, callback) => {
|
|
147
|
+
if (!origin) {
|
|
148
|
+
return callback(null, true);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 支持通配符匹配逻辑
|
|
152
|
+
const isAllowed = allowedDomains.some((domain) => {
|
|
153
|
+
// 处理包含通配符的情况(如 *.example.com)
|
|
154
|
+
if (domain.includes('*')) {
|
|
155
|
+
// 将通配符转换为正则表达式
|
|
156
|
+
const regexPattern = domain
|
|
157
|
+
.replace(/\./g, '\\.')
|
|
158
|
+
.replace(':*', '(:\\d+)?') // 处理端口通配符
|
|
159
|
+
.replace('*\\.', '(.*\\.)?');
|
|
160
|
+
const fullRegex = new RegExp(`^https?:\/\/${regexPattern}$`, 'i');
|
|
161
|
+
return fullRegex.test(origin);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 完全匹配(包含端口匹配)
|
|
165
|
+
return origin === domain || origin.startsWith(`${domain}:`);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
isAllowed
|
|
169
|
+
? callback(null, origin)
|
|
170
|
+
: callback(new BadRequestException('Not allowed by CORS'));
|
|
171
|
+
},
|
|
172
|
+
methods: this.getString('CORS_METHODS'),
|
|
173
|
+
allowedHeaders: this.getString('CORS_ALLOWED_HEADERS'),
|
|
174
|
+
exposedHeaders: this.getString('CORS_EXPOSED_HEADERS'),
|
|
175
|
+
credentials: this.getBoolean('CORS_CREDENTIALS'),
|
|
176
|
+
optionsSuccessStatus: 200,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
get sessionConfig(): session.SessionOptions {
|
|
181
|
+
const config: session.SessionOptions = {
|
|
182
|
+
secret: this.getString('SESSION_KEY'),
|
|
183
|
+
resave: false,
|
|
184
|
+
saveUninitialized: false,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
if (this.getBoolean('SESSION_REDIS_ENABLED')) {
|
|
188
|
+
config.store = new RedisStore({
|
|
189
|
+
client: new Redis(this.ioRedisConfig),
|
|
190
|
+
prefix: this.getString('SESSION_REDIS_PREFIX'),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return config;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
get authConfig() {
|
|
198
|
+
return {
|
|
199
|
+
privateKey: this.getString('JWT_PRIVATE_KEY'),
|
|
200
|
+
publicKey: this.getString('JWT_PUBLIC_KEY'),
|
|
201
|
+
jwtExpirationTime: this.getNumber('JWT_EXPIRATION_TIME'),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
get appConfig() {
|
|
206
|
+
return {
|
|
207
|
+
port: this.getString('PORT'),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
get apiKey(): string {
|
|
212
|
+
return this.getString('API_KEY');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
get ioRedisConfig() {
|
|
216
|
+
return {
|
|
217
|
+
host: this.getString('REDIS_HOST'),
|
|
218
|
+
port: this.getNumber('REDIS_PORT'),
|
|
219
|
+
username: this.getString('REDIS_USERNAME'),
|
|
220
|
+
password: this.getString('REDIS_PASSWORD'),
|
|
221
|
+
db: this.getNumber('REDIS_DB'),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 是否使用Redis,用于health check
|
|
227
|
+
*/
|
|
228
|
+
get isRedisEnabled(): boolean {
|
|
229
|
+
return (
|
|
230
|
+
this.getBoolean('BULL_ENABLED') ||
|
|
231
|
+
this.getBoolean('CACHE_ENABLED') ||
|
|
232
|
+
this.getBoolean('DB_CACHE_ENABLED') ||
|
|
233
|
+
(this.sessionEnabled && this.getBoolean('SESSION_REDIS_ENABLED'))
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
get bullConfig(): BullRootModuleOptions {
|
|
238
|
+
return {
|
|
239
|
+
redis: {
|
|
240
|
+
...this.ioRedisConfig,
|
|
241
|
+
// 增加重连策略
|
|
242
|
+
retryStrategy: (times: number) => Math.min(times * 1000, 5000),
|
|
243
|
+
},
|
|
244
|
+
prefix: this.getString('BULL_PREFIX'),
|
|
245
|
+
defaultJobOptions: {
|
|
246
|
+
removeOnComplete: true,
|
|
247
|
+
removeOnFail: true,
|
|
248
|
+
attempts: this.getNumber('BULL_JOB_ATTEMPTS', 5),
|
|
249
|
+
backoff: {
|
|
250
|
+
type: 'exponential',
|
|
251
|
+
delay: this.getNumber('BULL_JOB_BACKOFF_DELAY_MS', 5000),
|
|
252
|
+
},
|
|
253
|
+
timeout: this.getNumber('BULL_JOB_TIMEOUT_MS', 30 * 1000), // 默认30秒超时
|
|
254
|
+
},
|
|
255
|
+
settings: {
|
|
256
|
+
// 增强稳定性配置
|
|
257
|
+
maxStalledCount: 2, // 最大卡住重试次数
|
|
258
|
+
guardInterval: 5000, // 检查卡住任务间隔
|
|
259
|
+
retryProcessDelay: 1000, // 进程重启后的重试延迟
|
|
260
|
+
},
|
|
261
|
+
// 增加队列级限流配置
|
|
262
|
+
limiter: {
|
|
263
|
+
max: this.getNumber('BULL_MAX_CONCURRENT_JOBS', 100), // 最大并发任务数
|
|
264
|
+
duration: 1000, // 时间窗口
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async cacheConfig() {
|
|
270
|
+
return {
|
|
271
|
+
isGlobal: true,
|
|
272
|
+
store: await redisStore({
|
|
273
|
+
...this.ioRedisConfig,
|
|
274
|
+
ttl: this.getNumber('CACHE_TTL'),
|
|
275
|
+
}),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
get pinoConfig(): Params {
|
|
280
|
+
const transport = this.isDev
|
|
281
|
+
? {
|
|
282
|
+
target: 'pino-pretty',
|
|
283
|
+
}
|
|
284
|
+
: null;
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
pinoHttp: {
|
|
288
|
+
genReqId: (req: any) => req.id,
|
|
289
|
+
transport,
|
|
290
|
+
level: this.isDev ? 'debug' : 'info',
|
|
291
|
+
customLogLevel: function (res) {
|
|
292
|
+
if (res.statusCode >= 500) return 'error';
|
|
293
|
+
if (res.statusCode >= 400) return 'warn';
|
|
294
|
+
return 'info';
|
|
295
|
+
},
|
|
296
|
+
wrapSerializers: true,
|
|
297
|
+
customProps: (req: any, res: any) => {
|
|
298
|
+
return {
|
|
299
|
+
env: this.nodeEnv,
|
|
300
|
+
appName: this.getString('NAME'),
|
|
301
|
+
user: req?.user,
|
|
302
|
+
'req.body': req?.body,
|
|
303
|
+
'res.body': res?.body,
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
redact: {
|
|
307
|
+
paths: ['req.headers.authorization', 'req.headers.apikey'],
|
|
308
|
+
remove: true,
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
get axiosProxyConfig(): AxiosProxyConfig | false {
|
|
315
|
+
if (!this.getBoolean('DIRECT_PROXY_ENABLED')) {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
host: this.getString('DIRECT_PROXY_HOST'),
|
|
320
|
+
port: this.getNumber('DIRECT_PROXY_PORT'),
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
private get(key: string, defaultValue?: any): string {
|
|
325
|
+
const value = this.configService.get<string>(key);
|
|
326
|
+
|
|
327
|
+
if (isNil(value)) {
|
|
328
|
+
if (defaultValue) {
|
|
329
|
+
return defaultValue;
|
|
330
|
+
}
|
|
331
|
+
throw new Error(`key:'${key}' - environment does not set`); // probably we should call process.exit() too to avoid locking the service
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return value;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { v1 as uuid } from 'uuid';
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class GeneratorService {
|
|
6
|
+
public uuid(): string {
|
|
7
|
+
return uuid();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public fileName(ext: string): string {
|
|
11
|
+
return this.uuid() + '.' + ext;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { isArray, isString, map } from 'lodash';
|
|
3
|
+
import type { TranslateOptions } from 'nestjs-i18n';
|
|
4
|
+
import { I18nService } from 'nestjs-i18n';
|
|
5
|
+
|
|
6
|
+
import { AbstractDto } from '../../common/dto/abstract.dto';
|
|
7
|
+
import { STATIC_TRANSLATION_DECORATOR_KEY } from '../../decorators';
|
|
8
|
+
import type { ITranslationDecoratorInterface } from '../../interfaces';
|
|
9
|
+
import { ContextProvider } from '../../providers';
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class TranslationService {
|
|
13
|
+
constructor(private readonly i18n: I18nService) {}
|
|
14
|
+
|
|
15
|
+
async translate(key: string, options?: TranslateOptions): Promise<string> {
|
|
16
|
+
return this.i18n.translate(`${key}`, {
|
|
17
|
+
...options,
|
|
18
|
+
lang: ContextProvider.getLanguage(),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async translateNecessaryKeys<T extends AbstractDto>(dto: T): Promise<T> {
|
|
23
|
+
if (isString(dto)) {
|
|
24
|
+
return dto;
|
|
25
|
+
}
|
|
26
|
+
await Promise.all(
|
|
27
|
+
map(dto, async (value, key) => {
|
|
28
|
+
if (isString(value)) {
|
|
29
|
+
const translateDec: ITranslationDecoratorInterface | undefined =
|
|
30
|
+
Reflect.getMetadata(STATIC_TRANSLATION_DECORATOR_KEY, dto, key);
|
|
31
|
+
|
|
32
|
+
if (translateDec) {
|
|
33
|
+
return this.translate(
|
|
34
|
+
`${translateDec.translationKey ?? key}.${value}`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (value instanceof AbstractDto) {
|
|
42
|
+
return this.translateNecessaryKeys(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (isArray(value)) {
|
|
46
|
+
return Promise.all(
|
|
47
|
+
map(value, (v) => {
|
|
48
|
+
if (v instanceof AbstractDto) {
|
|
49
|
+
return this.translateNecessaryKeys(v);
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return dto;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// tslint:disable:ban-types
|
|
2
|
+
import {
|
|
3
|
+
ReferenceObject,
|
|
4
|
+
SchemaObject,
|
|
5
|
+
} from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
|
|
6
|
+
import 'reflect-metadata';
|
|
7
|
+
|
|
8
|
+
import { IOptions } from './options';
|
|
9
|
+
|
|
10
|
+
const SCHEMA_KEY = Symbol('class-validator-jsonschema:JSONSchema');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Either a plain JSON Schema object that gets merged into the existing schema,
|
|
14
|
+
* or a function that receives as parameters the existing schema and global
|
|
15
|
+
* options, returning an updated schema.
|
|
16
|
+
*/
|
|
17
|
+
export type DecoratorSchema =
|
|
18
|
+
| ReferenceObject
|
|
19
|
+
| SchemaObject
|
|
20
|
+
| ((
|
|
21
|
+
source: SchemaObject,
|
|
22
|
+
options: IOptions,
|
|
23
|
+
) => ReferenceObject | SchemaObject);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Supplement class or property with additional JSON Schema keywords.
|
|
27
|
+
*
|
|
28
|
+
* @param schema JSON Schema object that is merged into the schema derived from
|
|
29
|
+
* class-validator decorators. In case of conflicts, keywords defined here
|
|
30
|
+
* overwrite the existing ones. Alternatively you can supply a function that
|
|
31
|
+
* receives as parameters the existing schema and global options, returning an
|
|
32
|
+
* updated schema.
|
|
33
|
+
*/
|
|
34
|
+
export function JSONSchema(schema: DecoratorSchema) {
|
|
35
|
+
return (target: object | Function, key?: string) => {
|
|
36
|
+
if (key) {
|
|
37
|
+
setMetadataSchema(schema, target.constructor, key); // Property metadata
|
|
38
|
+
} else {
|
|
39
|
+
setMetadataSchema(schema, target, (target as Function).name); // Class metadata
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get the JSON Schema stored in given target's metadata.
|
|
46
|
+
*/
|
|
47
|
+
export function getMetadataSchema(
|
|
48
|
+
target: object | Function,
|
|
49
|
+
key: string,
|
|
50
|
+
): DecoratorSchema {
|
|
51
|
+
return Reflect.getMetadata(SCHEMA_KEY, target.constructor, key) || {};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Store given JSON Schema into target object's metadata.
|
|
56
|
+
*/
|
|
57
|
+
function setMetadataSchema(
|
|
58
|
+
value: DecoratorSchema,
|
|
59
|
+
target: object | Function,
|
|
60
|
+
key: string,
|
|
61
|
+
) {
|
|
62
|
+
return Reflect.defineMetadata(SCHEMA_KEY, value, target, key);
|
|
63
|
+
}
|