@nest-omni/core 2.0.1-0 → 2.0.1-10
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/decorators → decorators}/user.decorator.js +1 -1
- package/package.json +11 -4
- package/{dist/setup → setup}/bootstrap.setup.js +57 -22
- package/{dist/shared → shared}/serviceRegistryModule.js +11 -34
- package/tsconfig.tsbuildinfo +1 -0
- package/.history/src/common/boilerplate.polyfill_20250521135408.ts +0 -202
- package/.history/src/common/boilerplate.polyfill_20250712165919.ts +0 -254
- package/.history/src/common/boilerplate.polyfill_20250712165924.ts +0 -254
- package/.history/src/common/boilerplate.polyfill_20250712165927.ts +0 -254
- package/.history/src/common/boilerplate.polyfill_20250712170044.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170049.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170053.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170610.ts +0 -280
- package/.history/src/common/boilerplate.polyfill_20250712170614.ts +0 -280
- package/.history/src/common/boilerplate.polyfill_20250712170739.ts +0 -265
- package/.history/src/common/boilerplate.polyfill_20250712170801.ts +0 -291
- package/.history/src/common/boilerplate.polyfill_20250712170809.ts +0 -317
- package/.history/src/common/boilerplate.polyfill_20250712170816.ts +0 -319
- package/.history/src/common/boilerplate.polyfill_20250712170820.ts +0 -318
- package/.history/src/common/boilerplate.polyfill_20250712170824.ts +0 -318
- package/.history/src/common/boilerplate.polyfill_20250712171040.ts +0 -289
- package/README.md +0 -16
- package/build.sh +0 -45
- package/dist/package.json +0 -71
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/yarn.lock +0 -644
- package/src/.hygen.js +0 -116
- package/src/common/abstract-client.service.ts +0 -56
- package/src/common/abstract.entity.ts +0 -82
- package/src/common/boilerplate.polyfill.ts +0 -202
- package/src/common/dto/abstract.dto.ts +0 -61
- package/src/common/dto/bulk-id.dto.ts +0 -13
- package/src/common/dto/create-translation.dto.ts +0 -10
- package/src/common/dto/index.ts +0 -6
- package/src/common/dto/page-meta.dto.ts +0 -37
- package/src/common/dto/page-options.dto.ts +0 -35
- package/src/common/dto/page.dto.ts +0 -36
- package/src/common/index.ts +0 -7
- package/src/common/snake-naming.strategy.ts +0 -64
- package/src/common/types.ts +0 -44
- package/src/common/utils.ts +0 -45
- package/src/constants/index.ts +0 -2
- package/src/constants/language-code.ts +0 -7
- package/src/constants/order.ts +0 -4
- package/src/decorators/api-page-ok-response.decorator.ts +0 -32
- package/src/decorators/auth-user.decorator.ts +0 -16
- package/src/decorators/controller.decorator.ts +0 -8
- package/src/decorators/field.decorators.ts +0 -856
- package/src/decorators/http.decorators.ts +0 -10
- package/src/decorators/index.ts +0 -12
- package/src/decorators/operation.decorator.ts +0 -4
- package/src/decorators/property.decorators.ts +0 -62
- package/src/decorators/public-route.decorator.ts +0 -8
- package/src/decorators/swagger.schema.ts +0 -117
- package/src/decorators/timestamp-column.decorator.ts +0 -29
- package/src/decorators/transform.decorators.ts +0 -159
- package/src/decorators/translate.decorator.ts +0 -19
- package/src/decorators/use-dto.decorator.ts +0 -11
- package/src/decorators/user-check.decorator.ts +0 -30
- package/src/decorators/user.decorator.ts +0 -59
- package/src/decorators/user_auth.decorator.ts +0 -15
- package/src/decorators/validator.decorators.ts +0 -98
- package/src/exceptions/file-not-image.exception.ts +0 -7
- package/src/exceptions/index.ts +0 -2
- package/src/exceptions/page-type.exception.ts +0 -7
- package/src/exceptions/user-not-found.exception.ts +0 -7
- package/src/filters/bad-request.filter.ts +0 -77
- package/src/filters/constraint-errors.ts +0 -5
- package/src/filters/index.ts +0 -3
- package/src/filters/query-failed.filter.ts +0 -32
- package/src/health-checker/health-checker.controller.ts +0 -51
- package/src/health-checker/health-checker.module.ts +0 -13
- package/src/health-checker/health-indicators/service.indicator.ts +0 -44
- package/src/helpers/common.helper.ts +0 -49
- package/src/helpers/date.helper.ts +0 -64
- package/src/helpers/index.ts +0 -2
- package/src/i18n/en_US/validation.json +0 -41
- package/src/i18n/zh_CN/validation.json +0 -41
- package/src/index.ts +0 -11
- package/src/interceptors/index.ts +0 -2
- package/src/interceptors/language-interceptor.service.ts +0 -28
- package/src/interceptors/translation-interceptor.service.ts +0 -43
- package/src/interfaces/IApiFile.ts +0 -4
- package/src/interfaces/IFile.ts +0 -8
- package/src/interfaces/ITranslationDecoratorInterface.ts +0 -3
- package/src/interfaces/index.ts +0 -3
- package/src/interfaces/response.ts +0 -37
- package/src/middlewares/index.ts +0 -4
- package/src/middlewares/omni-auth.middleware.ts +0 -10
- package/src/middlewares/powerby.middleware.ts +0 -6
- package/src/middlewares/request-id.middleware.ts +0 -28
- package/src/middlewares/xml.middleware.ts +0 -14
- package/src/providers/context.provider.ts +0 -109
- package/src/providers/generator.provider.ts +0 -66
- package/src/providers/index.ts +0 -2
- package/src/setup/bootstrap.setup.ts +0 -254
- package/src/setup/index.ts +0 -1
- package/src/shared/index.ts +0 -2
- package/src/shared/serviceRegistryModule.ts +0 -135
- package/src/shared/services/api-config.service.ts +0 -336
- package/src/shared/services/generator.service.ts +0 -13
- package/src/shared/services/index.ts +0 -4
- package/src/shared/services/translation.service.ts +0 -59
- package/src/shared/services/validator.service.ts +0 -10
- package/src/validator-json/decorators.ts +0 -63
- package/src/validator-json/default.ts +0 -257
- package/src/validator-json/defaultConverters.ts +0 -402
- package/src/validator-json/index.ts +0 -4
- package/src/validator-json/options.ts +0 -50
- package/src/validators/file-mimetype.validator.ts +0 -34
- package/src/validators/index.ts +0 -6
- package/src/validators/is-exists.validator.ts +0 -60
- package/src/validators/is-unique.validator.ts +0 -93
- package/src/validators/phone-country-code.validator.ts +0 -36
- package/src/validators/same-as.validator.ts +0 -27
- package/src/validators/skip-empty.validator.ts +0 -25
- package/tsconfig.json +0 -31
- package/tsconfig.lib.json +0 -16
- /package/{dist/.hygen → .hygen}/new/crud/controller.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/create.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/entity.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/get.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/index-dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/index-response.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/module.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/prompt.js +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/service.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/crud/update.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/controller.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/create-command.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/create.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/entity.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/get-query.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/module.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/not-found.exception.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/page-options.dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/prompt.js +0 -0
- /package/{dist/.hygen → .hygen}/new/module/repository.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/service.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/translation-dto.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/translation-entity.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/translation-repository.ejs.t +0 -0
- /package/{dist/.hygen → .hygen}/new/module/update.dto.ejs.t +0 -0
- /package/{dist/.hygen.js → .hygen.js} +0 -0
- /package/{dist/common → common}/abstract-client.service.d.ts +0 -0
- /package/{dist/common → common}/abstract-client.service.js +0 -0
- /package/{dist/common → common}/abstract.entity.d.ts +0 -0
- /package/{dist/common → common}/abstract.entity.js +0 -0
- /package/{dist/common → common}/boilerplate.polyfill.d.ts +0 -0
- /package/{dist/common → common}/boilerplate.polyfill.js +0 -0
- /package/{dist/common → common}/dto/abstract.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/abstract.dto.js +0 -0
- /package/{dist/common → common}/dto/bulk-id.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/bulk-id.dto.js +0 -0
- /package/{dist/common → common}/dto/create-translation.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/create-translation.dto.js +0 -0
- /package/{dist/common → common}/dto/index.d.ts +0 -0
- /package/{dist/common → common}/dto/index.js +0 -0
- /package/{dist/common → common}/dto/page-meta.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/page-meta.dto.js +0 -0
- /package/{dist/common → common}/dto/page-options.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/page-options.dto.js +0 -0
- /package/{dist/common → common}/dto/page.dto.d.ts +0 -0
- /package/{dist/common → common}/dto/page.dto.js +0 -0
- /package/{dist/common → common}/index.d.ts +0 -0
- /package/{dist/common → common}/index.js +0 -0
- /package/{dist/common → common}/snake-naming.strategy.d.ts +0 -0
- /package/{dist/common → common}/snake-naming.strategy.js +0 -0
- /package/{dist/common → common}/types.d.ts +0 -0
- /package/{dist/common → common}/types.js +0 -0
- /package/{dist/common → common}/utils.d.ts +0 -0
- /package/{dist/common → common}/utils.js +0 -0
- /package/{dist/constants → constants}/index.d.ts +0 -0
- /package/{dist/constants → constants}/index.js +0 -0
- /package/{dist/constants → constants}/language-code.d.ts +0 -0
- /package/{dist/constants → constants}/language-code.js +0 -0
- /package/{dist/constants → constants}/order.d.ts +0 -0
- /package/{dist/constants → constants}/order.js +0 -0
- /package/{dist/decorators → decorators}/api-page-ok-response.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/api-page-ok-response.decorator.js +0 -0
- /package/{dist/decorators → decorators}/auth-user.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/auth-user.decorator.js +0 -0
- /package/{dist/decorators → decorators}/controller.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/controller.decorator.js +0 -0
- /package/{dist/decorators → decorators}/field.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/field.decorators.js +0 -0
- /package/{dist/decorators → decorators}/http.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/http.decorators.js +0 -0
- /package/{dist/decorators → decorators}/index.d.ts +0 -0
- /package/{dist/decorators → decorators}/index.js +0 -0
- /package/{dist/decorators → decorators}/operation.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/operation.decorator.js +0 -0
- /package/{dist/decorators → decorators}/property.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/property.decorators.js +0 -0
- /package/{dist/decorators → decorators}/public-route.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/public-route.decorator.js +0 -0
- /package/{dist/decorators → decorators}/swagger.schema.d.ts +0 -0
- /package/{dist/decorators → decorators}/swagger.schema.js +0 -0
- /package/{dist/decorators → decorators}/timestamp-column.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/timestamp-column.decorator.js +0 -0
- /package/{dist/decorators → decorators}/transform.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/transform.decorators.js +0 -0
- /package/{dist/decorators → decorators}/translate.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/translate.decorator.js +0 -0
- /package/{dist/decorators → decorators}/use-dto.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/use-dto.decorator.js +0 -0
- /package/{dist/decorators → decorators}/user-check.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/user-check.decorator.js +0 -0
- /package/{dist/decorators → decorators}/user.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/user_auth.decorator.d.ts +0 -0
- /package/{dist/decorators → decorators}/user_auth.decorator.js +0 -0
- /package/{dist/decorators → decorators}/validator.decorators.d.ts +0 -0
- /package/{dist/decorators → decorators}/validator.decorators.js +0 -0
- /package/{dist/exceptions → exceptions}/file-not-image.exception.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/file-not-image.exception.js +0 -0
- /package/{dist/exceptions → exceptions}/index.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/index.js +0 -0
- /package/{dist/exceptions → exceptions}/page-type.exception.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/page-type.exception.js +0 -0
- /package/{dist/exceptions → exceptions}/user-not-found.exception.d.ts +0 -0
- /package/{dist/exceptions → exceptions}/user-not-found.exception.js +0 -0
- /package/{dist/filters → filters}/bad-request.filter.d.ts +0 -0
- /package/{dist/filters → filters}/bad-request.filter.js +0 -0
- /package/{dist/filters → filters}/constraint-errors.d.ts +0 -0
- /package/{dist/filters → filters}/constraint-errors.js +0 -0
- /package/{dist/filters → filters}/index.d.ts +0 -0
- /package/{dist/filters → filters}/index.js +0 -0
- /package/{dist/filters → filters}/query-failed.filter.d.ts +0 -0
- /package/{dist/filters → filters}/query-failed.filter.js +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.controller.d.ts +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.controller.js +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.module.d.ts +0 -0
- /package/{dist/health-checker → health-checker}/health-checker.module.js +0 -0
- /package/{dist/health-checker → health-checker}/health-indicators/service.indicator.d.ts +0 -0
- /package/{dist/health-checker → health-checker}/health-indicators/service.indicator.js +0 -0
- /package/{dist/helpers → helpers}/common.helper.d.ts +0 -0
- /package/{dist/helpers → helpers}/common.helper.js +0 -0
- /package/{dist/helpers → helpers}/date.helper.d.ts +0 -0
- /package/{dist/helpers → helpers}/date.helper.js +0 -0
- /package/{dist/helpers → helpers}/index.d.ts +0 -0
- /package/{dist/helpers → helpers}/index.js +0 -0
- /package/{dist/i18n → i18n}/en_US/validation.json +0 -0
- /package/{dist/i18n → i18n}/zh_CN/validation.json +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/interceptors → interceptors}/index.d.ts +0 -0
- /package/{dist/interceptors → interceptors}/index.js +0 -0
- /package/{dist/interceptors → interceptors}/language-interceptor.service.d.ts +0 -0
- /package/{dist/interceptors → interceptors}/language-interceptor.service.js +0 -0
- /package/{dist/interceptors → interceptors}/translation-interceptor.service.d.ts +0 -0
- /package/{dist/interceptors → interceptors}/translation-interceptor.service.js +0 -0
- /package/{dist/interfaces → interfaces}/IApiFile.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/IApiFile.js +0 -0
- /package/{dist/interfaces → interfaces}/IFile.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/IFile.js +0 -0
- /package/{dist/interfaces → interfaces}/ITranslationDecoratorInterface.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/ITranslationDecoratorInterface.js +0 -0
- /package/{dist/interfaces → interfaces}/index.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/index.js +0 -0
- /package/{dist/interfaces → interfaces}/response.d.ts +0 -0
- /package/{dist/interfaces → interfaces}/response.js +0 -0
- /package/{dist/middlewares → middlewares}/index.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/index.js +0 -0
- /package/{dist/middlewares → middlewares}/omni-auth.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/omni-auth.middleware.js +0 -0
- /package/{dist/middlewares → middlewares}/powerby.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/powerby.middleware.js +0 -0
- /package/{dist/middlewares → middlewares}/request-id.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/request-id.middleware.js +0 -0
- /package/{dist/middlewares → middlewares}/xml.middleware.d.ts +0 -0
- /package/{dist/middlewares → middlewares}/xml.middleware.js +0 -0
- /package/{dist/providers → providers}/context.provider.d.ts +0 -0
- /package/{dist/providers → providers}/context.provider.js +0 -0
- /package/{dist/providers → providers}/generator.provider.d.ts +0 -0
- /package/{dist/providers → providers}/generator.provider.js +0 -0
- /package/{dist/providers → providers}/index.d.ts +0 -0
- /package/{dist/providers → providers}/index.js +0 -0
- /package/{dist/setup → setup}/bootstrap.setup.d.ts +0 -0
- /package/{dist/setup → setup}/index.d.ts +0 -0
- /package/{dist/setup → setup}/index.js +0 -0
- /package/{dist/shared → shared}/index.d.ts +0 -0
- /package/{dist/shared → shared}/index.js +0 -0
- /package/{dist/shared → shared}/serviceRegistryModule.d.ts +0 -0
- /package/{dist/shared → shared}/services/api-config.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/api-config.service.js +0 -0
- /package/{dist/shared → shared}/services/generator.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/generator.service.js +0 -0
- /package/{dist/shared → shared}/services/index.d.ts +0 -0
- /package/{dist/shared → shared}/services/index.js +0 -0
- /package/{dist/shared → shared}/services/translation.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/translation.service.js +0 -0
- /package/{dist/shared → shared}/services/validator.service.d.ts +0 -0
- /package/{dist/shared → shared}/services/validator.service.js +0 -0
- /package/{dist/validator-json → validator-json}/decorators.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/decorators.js +0 -0
- /package/{dist/validator-json → validator-json}/default.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/default.js +0 -0
- /package/{dist/validator-json → validator-json}/defaultConverters.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/defaultConverters.js +0 -0
- /package/{dist/validator-json → validator-json}/index.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/index.js +0 -0
- /package/{dist/validator-json → validator-json}/options.d.ts +0 -0
- /package/{dist/validator-json → validator-json}/options.js +0 -0
- /package/{dist/validators → validators}/file-mimetype.validator.d.ts +0 -0
- /package/{dist/validators → validators}/file-mimetype.validator.js +0 -0
- /package/{dist/validators → validators}/index.d.ts +0 -0
- /package/{dist/validators → validators}/index.js +0 -0
- /package/{dist/validators → validators}/is-exists.validator.d.ts +0 -0
- /package/{dist/validators → validators}/is-exists.validator.js +0 -0
- /package/{dist/validators → validators}/is-unique.validator.d.ts +0 -0
- /package/{dist/validators → validators}/is-unique.validator.js +0 -0
- /package/{dist/validators → validators}/phone-country-code.validator.d.ts +0 -0
- /package/{dist/validators → validators}/phone-country-code.validator.js +0 -0
- /package/{dist/validators → validators}/same-as.validator.d.ts +0 -0
- /package/{dist/validators → validators}/same-as.validator.js +0 -0
- /package/{dist/validators → validators}/skip-empty.validator.d.ts +0 -0
- /package/{dist/validators → validators}/skip-empty.validator.js +0 -0
|
@@ -1,336 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
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
|
-
}
|