@nest-omni/core 1.0.57 → 2.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.
@@ -14,4 +14,5 @@ export declare class AbstractTranslationEntity<DTO extends AbstractTranslationDt
14
14
  }
15
15
  export declare class AbstractUuidPrimaryEntity<DTO extends AbstractDto = AbstractDto, O = never> extends AbstractBaseEntity<DTO, O> {
16
16
  id: string;
17
+ generateId(): void;
17
18
  }
@@ -13,6 +13,7 @@ exports.AbstractUuidPrimaryEntity = exports.AbstractTranslationEntity = exports.
13
13
  const typeorm_1 = require("typeorm");
14
14
  const decorators_1 = require("../decorators");
15
15
  const constants_1 = require("../constants");
16
+ const uuid_1 = require("uuid");
16
17
  class AbstractBaseEntity {
17
18
  toDto(options) {
18
19
  const dtoClass = Object.getPrototypeOf(this).dtoClass;
@@ -51,6 +52,12 @@ __decorate([
51
52
  __metadata("design:type", String)
52
53
  ], AbstractTranslationEntity.prototype, "languageCode", void 0);
53
54
  class AbstractUuidPrimaryEntity extends AbstractBaseEntity {
55
+ generateId() {
56
+ var _a;
57
+ if (!this.id || ((_a = this.id) === null || _a === void 0 ? void 0 : _a.length) < 2) {
58
+ this.id = (0, uuid_1.v4)();
59
+ }
60
+ }
54
61
  }
55
62
  exports.AbstractUuidPrimaryEntity = AbstractUuidPrimaryEntity;
56
63
  __decorate([
@@ -63,3 +70,9 @@ __decorate([
63
70
  }),
64
71
  __metadata("design:type", String)
65
72
  ], AbstractUuidPrimaryEntity.prototype, "id", void 0);
73
+ __decorate([
74
+ (0, typeorm_1.BeforeInsert)(),
75
+ __metadata("design:type", Function),
76
+ __metadata("design:paramtypes", []),
77
+ __metadata("design:returntype", void 0)
78
+ ], AbstractUuidPrimaryEntity.prototype, "generateId", null);
@@ -1,5 +1,5 @@
1
1
  import type { ApiPropertyOptions } from '@nestjs/swagger';
2
- import ValidatorJS from 'validator';
2
+ import * as ValidatorJS from 'validator';
3
3
  type RequireField<T, K extends keyof T> = T & Required<Pick<T, K>>;
4
4
  interface IFieldOptions {
5
5
  each?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-omni/core",
3
- "version": "1.0.57",
3
+ "version": "2.0.1-1",
4
4
  "description": "framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -34,8 +34,6 @@
34
34
  "@nestjs/swagger": "^7.1.11",
35
35
  "@nestjs/terminus": "^10.1.1",
36
36
  "@nestjs/typeorm": "^10.0.0",
37
- "@ntegral/nestjs-sentry": "^4.0.0",
38
- "@sentry/node": "^7.69.0",
39
37
  "axios": "^1.5.0",
40
38
  "axios-retry": "^3.7.0",
41
39
  "bcrypt": "5.1.0",
@@ -1,2 +1,2 @@
1
1
  import type { NestExpressApplication } from '@nestjs/platform-express';
2
- export declare function bootstrapSetup(AppModule: any, SetupSwagger: any): Promise<NestExpressApplication<import("http").Server>>;
2
+ export declare function bootstrapSetup(AppModule: any, SetupSwagger: any): Promise<NestExpressApplication<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>>;
@@ -10,19 +10,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.bootstrapSetup = bootstrapSetup;
13
- const core_1 = require("@nestjs/core");
14
- const typeorm_transactional_1 = require("typeorm-transactional");
15
- const skywalking_backend_js_1 = require("skywalking-backend-js");
16
- const nestjs_pino_1 = require("nestjs-pino");
17
- const session = require("express-session");
18
- const bodyParse = require("body-parser");
13
+ const Sentry = require("@sentry/nestjs");
14
+ const profiling_node_1 = require("@sentry/profiling-node");
15
+ const dotenv = require("dotenv");
16
+ const fs_1 = require("fs");
19
17
  const path_1 = require("path");
20
- const __1 = require("../");
21
- const common_1 = require("@nestjs/common");
22
- const nestjs_sentry_1 = require("@ntegral/nestjs-sentry");
23
- const nestjs_i18n_1 = require("nestjs-i18n");
18
+ const possibleRootPaths = [process.cwd(), __dirname];
19
+ const path0 = (0, path_1.join)(possibleRootPaths[0], 'config/base.env');
20
+ const path1 = (0, path_1.join)(possibleRootPaths[1], 'config/base.env');
21
+ if ((0, fs_1.existsSync)(path0)) {
22
+ dotenv.config({ path: path0 });
23
+ }
24
+ else if ((0, fs_1.existsSync)(path1)) {
25
+ dotenv.config({ path: path1 });
26
+ }
27
+ else {
28
+ throw new Error(`No valid base.env file: ${path0} or ${path1}`);
29
+ }
30
+ const requiredEnvVars = ['SENTRY_DSN', 'API_VERSION', 'NODE_ENV'];
31
+ requiredEnvVars.forEach((envVar) => {
32
+ if (!process.env[envVar]) {
33
+ throw new Error(`Missing required environment variable: ${envVar}`);
34
+ }
35
+ });
36
+ Sentry.init({
37
+ dsn: process.env.SENTRY_DSN || '',
38
+ release: process.env.API_VERSION || '',
39
+ environment: process.env.NODE_ENV || 'unkown',
40
+ debug: process.env.NODE_ENV === 'dev',
41
+ tracesSampleRate: 1.0,
42
+ profileSessionSampleRate: 1.0,
43
+ profileLifecycle: 'trace',
44
+ sendDefaultPii: true,
45
+ integrations: [profiling_node_1.nodeProfilingIntegration],
46
+ });
24
47
  const crud_1 = require("@dataui/crud");
25
- const nestjs_cls_1 = require("nestjs-cls");
26
48
  crud_1.CrudConfigService.load({
27
49
  auth: {
28
50
  property: 'user',
@@ -50,6 +72,16 @@ crud_1.CrudConfigService.load({
50
72
  },
51
73
  },
52
74
  });
75
+ const core_1 = require("@nestjs/core");
76
+ const typeorm_transactional_1 = require("typeorm-transactional");
77
+ const nestjs_pino_1 = require("nestjs-pino");
78
+ const session = require("express-session");
79
+ const bodyParse = require("body-parser");
80
+ const __1 = require("../");
81
+ const common_1 = require("@nestjs/common");
82
+ const nestjs_i18n_1 = require("nestjs-i18n");
83
+ const nestjs_cls_1 = require("nestjs-cls");
84
+ const setup_1 = require("@sentry/nestjs/setup");
53
85
  const setupProcessHandlers = (app) => {
54
86
  const logger = app.get(nestjs_pino_1.Logger);
55
87
  process.on('uncaughtException', (error) => {
@@ -126,18 +158,8 @@ function bootstrapSetup(AppModule, SetupSwagger) {
126
158
  app.enable('trust proxy');
127
159
  app.use(bodyParse.json({ limit: '50mb' }), new nestjs_cls_1.ClsMiddleware({}).use, (0, __1.RequestIdMiddleware)(), (0, __1.PowerByMiddleware)(), (0, __1.OmniAuthMiddleware)());
128
160
  const reflector = app.get(core_1.Reflector);
129
- app.useGlobalFilters(new __1.HttpExceptionFilter(), new __1.QueryFailedFilter(reflector));
130
- app.useGlobalInterceptors(new __1.LanguageInterceptor(), new __1.TranslationInterceptor(), new nestjs_pino_1.LoggerErrorInterceptor(), new nestjs_sentry_1.SentryInterceptor({
131
- filters: [
132
- {
133
- type: common_1.HttpException,
134
- filter: (exception) => {
135
- const status = exception.getStatus();
136
- return status === 401 || status === 404 || 200 > status;
137
- },
138
- },
139
- ],
140
- }));
161
+ app.useGlobalFilters(new setup_1.SentryGlobalFilter(), new __1.HttpExceptionFilter(), new __1.QueryFailedFilter(reflector));
162
+ app.useGlobalInterceptors(new __1.LanguageInterceptor(), new __1.TranslationInterceptor(), new nestjs_pino_1.LoggerErrorInterceptor());
141
163
  app.useGlobalPipes(new nestjs_i18n_1.I18nValidationPipe({
142
164
  whitelist: true,
143
165
  errorHttpStatusCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY,
@@ -145,10 +167,6 @@ function bootstrapSetup(AppModule, SetupSwagger) {
145
167
  stopAtFirstError: true,
146
168
  validationError: { target: false, value: false },
147
169
  }));
148
- if (configService.skywalkingEnabled) {
149
- skywalking_backend_js_1.default.start();
150
- logger.log('SkyWalking agent initialized');
151
- }
152
170
  if (configService.documentationEnabled && SetupSwagger) {
153
171
  SetupSwagger(app, configService.documentationPath);
154
172
  logger.log(`Swagger docs available at ${configService.documentationPath}`);
@@ -25,7 +25,7 @@ const config_1 = require("@nestjs/config");
25
25
  const common_1 = require("@nestjs/common");
26
26
  const typeorm_2 = require("@nestjs/typeorm");
27
27
  const schedule_1 = require("@nestjs/schedule");
28
- const nestjs_sentry_1 = require("@ntegral/nestjs-sentry");
28
+ const setup_1 = require("@sentry/nestjs/setup");
29
29
  const cache_manager_1 = require("@nestjs/cache-manager");
30
30
  const typeorm_transactional_1 = require("typeorm-transactional");
31
31
  const nestjs_i18n_1 = require("nestjs-i18n");
@@ -77,12 +77,7 @@ const modules = [
77
77
  expandVariables: false,
78
78
  envFilePath: [envFilePath, baseEnvFilePath],
79
79
  }),
80
- nestjs_sentry_1.SentryModule.forRootAsync({
81
- inject: [services_1.ApiConfigService],
82
- useFactory(configService) {
83
- return configService.sentryConfig;
84
- },
85
- }),
80
+ setup_1.SentryModule.forRoot(),
86
81
  nestjs_pino_1.LoggerModule.forRootAsync({
87
82
  inject: [services_1.ApiConfigService],
88
83
  useFactory: (config) => config.pinoConfig,
@@ -101,9 +96,6 @@ const modules = [
101
96
  }),
102
97
  health_checker_module_1.HealthCheckerModule,
103
98
  ];
104
- if (services_1.ApiConfigService.toBoolean(process.env.S3_ENABLED, false)) {
105
- providers.push(services_1.AwsS3Service);
106
- }
107
99
  if (services_1.ApiConfigService.toBoolean(process.env.DB_ENABLED, true)) {
108
100
  modules.push(typeorm_2.TypeOrmModule.forRootAsync({
109
101
  inject: [services_1.ApiConfigService],
@@ -122,6 +114,7 @@ if (services_1.ApiConfigService.toBoolean(process.env.BULL_ENABLED)) {
122
114
  if (services_1.ApiConfigService.toBoolean(process.env.CACHE_ENABLED)) {
123
115
  modules.push(cache_manager_1.CacheModule.registerAsync({
124
116
  inject: [services_1.ApiConfigService],
117
+ isGlobal: true,
125
118
  useFactory: (config) => config.cacheConfig(),
126
119
  }));
127
120
  }
@@ -136,6 +129,6 @@ exports.ServiceRegistryModule = ServiceRegistryModule = __decorate([
136
129
  (0, common_1.Module)({
137
130
  providers,
138
131
  imports: modules,
139
- exports: [...providers, ...modules],
132
+ exports: [...providers],
140
133
  })
141
134
  ], ServiceRegistryModule);
@@ -1,6 +1,5 @@
1
1
  import { ConfigService } from '@nestjs/config';
2
2
  import type { TypeOrmModuleOptions } from '@nestjs/typeorm';
3
- import { SentryModuleOptions } from '@ntegral/nestjs-sentry/lib/sentry.interfaces';
4
3
  import session from 'express-session';
5
4
  import { Params } from 'nestjs-pino';
6
5
  import { BullRootModuleOptions } from '@nestjs/bull/dist/interfaces/bull-module-options.interface';
@@ -12,36 +11,25 @@ export declare class ApiConfigService {
12
11
  constructor(configService: ConfigService);
13
12
  static getRootPath(): string;
14
13
  get isDev(): boolean;
14
+ get apiVersion(): string;
15
15
  get isProd(): boolean;
16
16
  get isSit(): boolean;
17
17
  get isUat(): boolean;
18
18
  get isTest(): boolean;
19
- getNumber(key: string): number;
20
- getBoolean(key: string): boolean;
19
+ getNumber(key: string, defaultValue?: number): number;
20
+ getBoolean(key: string, defaultValue?: boolean): boolean;
21
21
  static toBoolean(value: string, defaultValue?: any): boolean;
22
22
  getString(key: string): string;
23
23
  get nodeEnv(): string;
24
24
  get fallbackLanguage(): string;
25
- get sentryConfig(): SentryModuleOptions;
26
25
  get typeormConfig(): TypeOrmModuleOptions;
27
- get awsS3Config(): {
28
- bucketRegion: string;
29
- bucketApiVersion: string;
30
- bucketName: string;
31
- };
32
26
  get documentationEnabled(): boolean;
33
27
  get documentationPath(): string;
34
- get skywalkingEnabled(): boolean;
35
28
  get viewsEnabled(): boolean;
36
29
  get sessionEnabled(): boolean;
37
30
  get corsEnabled(): boolean;
38
31
  get corsConfig(): CorsOptions;
39
32
  get sessionConfig(): session.SessionOptions;
40
- get natsEnabled(): boolean;
41
- get natsConfig(): {
42
- host: string;
43
- port: number;
44
- };
45
33
  get authConfig(): {
46
34
  privateKey: string;
47
35
  publicKey: string;
@@ -40,6 +40,9 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
40
40
  get isDev() {
41
41
  return this.nodeEnv === 'dev';
42
42
  }
43
+ get apiVersion() {
44
+ return this.getString('API_VERSION');
45
+ }
43
46
  get isProd() {
44
47
  return this.nodeEnv === 'prod';
45
48
  }
@@ -52,8 +55,8 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
52
55
  get isTest() {
53
56
  return this.nodeEnv === 'test';
54
57
  }
55
- getNumber(key) {
56
- const value = this.get(key);
58
+ getNumber(key, defaultValue) {
59
+ const value = this.get(key, defaultValue);
57
60
  try {
58
61
  return Number(value);
59
62
  }
@@ -61,8 +64,8 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
61
64
  throw new Error(`key:${key}, value:${value} - is not a number`);
62
65
  }
63
66
  }
64
- getBoolean(key) {
65
- const value = this.get(key);
67
+ getBoolean(key, defaultValue) {
68
+ const value = this.get(key, defaultValue);
66
69
  return ApiConfigService_1.toBoolean(value);
67
70
  }
68
71
  static toBoolean(value, defaultValue = null) {
@@ -86,20 +89,6 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
86
89
  get fallbackLanguage() {
87
90
  return this.getString('FALLBACK_LANGUAGE');
88
91
  }
89
- get sentryConfig() {
90
- return {
91
- dsn: this.getString('SENTRY_DSN'),
92
- debug: this.isDev,
93
- environment: this.nodeEnv,
94
- tracesSampleRate: 1.0,
95
- release: '0.0.1',
96
- logLevels: ['warn', 'error'],
97
- close: {
98
- enabled: true,
99
- timeout: 10 * 1000,
100
- },
101
- };
102
- }
103
92
  get typeormConfig() {
104
93
  return {
105
94
  autoLoadEntities: true,
@@ -125,22 +114,12 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
125
114
  : false,
126
115
  };
127
116
  }
128
- get awsS3Config() {
129
- return {
130
- bucketRegion: this.getString('AWS_S3_BUCKET_REGION'),
131
- bucketApiVersion: this.getString('AWS_S3_API_VERSION'),
132
- bucketName: this.getString('AWS_S3_BUCKET_NAME'),
133
- };
134
- }
135
117
  get documentationEnabled() {
136
118
  return this.getBoolean('SWAGGER_ENABLED');
137
119
  }
138
120
  get documentationPath() {
139
121
  return this.getString('SWAGGER_PATH');
140
122
  }
141
- get skywalkingEnabled() {
142
- return this.getBoolean('SW_ENABLED');
143
- }
144
123
  get viewsEnabled() {
145
124
  return this.getBoolean('VIEWS_ENABLED');
146
125
  }
@@ -198,15 +177,6 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
198
177
  }
199
178
  return config;
200
179
  }
201
- get natsEnabled() {
202
- return this.getBoolean('NATS_ENABLED');
203
- }
204
- get natsConfig() {
205
- return {
206
- host: this.getString('NATS_HOST'),
207
- port: this.getNumber('NATS_PORT'),
208
- };
209
- }
210
180
  get authConfig() {
211
181
  return {
212
182
  privateKey: this.getString('JWT_PRIVATE_KEY'),
@@ -244,12 +214,12 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
244
214
  defaultJobOptions: {
245
215
  removeOnComplete: true,
246
216
  removeOnFail: true,
247
- attempts: this.getNumber('BULL_JOB_ATTEMPTS') || 5,
217
+ attempts: this.getNumber('BULL_JOB_ATTEMPTS', 5),
248
218
  backoff: {
249
219
  type: 'exponential',
250
- delay: this.getNumber('BULL_JOB_BACKOFF_DELAY_MS') || 5000,
220
+ delay: this.getNumber('BULL_JOB_BACKOFF_DELAY_MS', 5000),
251
221
  },
252
- timeout: this.getNumber('BULL_JOB_TIMEOUT_MS') || 30 * 1000,
222
+ timeout: this.getNumber('BULL_JOB_TIMEOUT_MS', 30 * 1000),
253
223
  },
254
224
  settings: {
255
225
  maxStalledCount: 2,
@@ -257,7 +227,7 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
257
227
  retryProcessDelay: 1000,
258
228
  },
259
229
  limiter: {
260
- max: this.getNumber('BULL_MAX_CONCURRENT_JOBS') || 100,
230
+ max: this.getNumber('BULL_MAX_CONCURRENT_JOBS', 100),
261
231
  duration: 1000,
262
232
  },
263
233
  };
@@ -314,9 +284,12 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
314
284
  port: this.getNumber('DIRECT_PROXY_PORT'),
315
285
  };
316
286
  }
317
- get(key) {
287
+ get(key, defaultValue) {
318
288
  const value = this.configService.get(key);
319
289
  if ((0, lodash_1.isNil)(value)) {
290
+ if (defaultValue) {
291
+ return defaultValue;
292
+ }
320
293
  throw new Error(`key:'${key}' - environment does not set`);
321
294
  }
322
295
  return value;
@@ -1,5 +1,4 @@
1
1
  export * from './api-config.service';
2
- export * from './aws-s3.service';
3
2
  export * from './generator.service';
4
3
  export * from './translation.service';
5
4
  export * from './validator.service';
@@ -15,7 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api-config.service"), exports);
18
- __exportStar(require("./aws-s3.service"), exports);
19
18
  __exportStar(require("./generator.service"), exports);
20
19
  __exportStar(require("./translation.service"), exports);
21
20
  __exportStar(require("./validator.service"), exports);