@nest-omni/core 2.0.1-1 → 2.0.1-11

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.
@@ -15,7 +15,7 @@ function getOmniAuthData(request, key) {
15
15
  let user;
16
16
  const configService = new config_1.ConfigService(request);
17
17
  if ((0, lodash_1.isEmpty)(headers['x-user-id']) && (0, lodash_1.isEmpty)(headers['x-app-id'])) {
18
- if (process.env.NODE_ENV === 'dev') {
18
+ if (process.env.NODE_ENV === 'dev' || process.env.MOCK_ENABLED === 'true') {
19
19
  user = {
20
20
  uid: configService.get('MOCK_UID'),
21
21
  username: configService.get('MOCK_USERNAME'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-omni/core",
3
- "version": "2.0.1-1",
3
+ "version": "2.0.1-11",
4
4
  "description": "framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,7 +17,8 @@
17
17
  "author": "Jinpy",
18
18
  "license": "Apache-2.0",
19
19
  "devDependencies": {
20
- "typescript": "^5.4.5"
20
+ "typescript": "^5.4.5",
21
+ "@types/compression": "^1.8.1"
21
22
  },
22
23
  "peerDependencies": {
23
24
  "@dataui/crud": "^5.3.0",
@@ -56,7 +57,6 @@
56
57
  "pino-pretty": "^10.2.0",
57
58
  "reflect-metadata": "^0.1.13",
58
59
  "rxjs": "^7.8.1",
59
- "skywalking-backend-js": "^0.6.0",
60
60
  "source-map-support": "^0.5.21",
61
61
  "sprintf-js": "^1.1.3",
62
62
  "typeorm": "^0.3.17",
@@ -64,6 +64,13 @@
64
64
  "uuid": "^9.0.1"
65
65
  },
66
66
  "dependencies": {
67
- "hygen": "^6.2.11"
67
+ "hygen": "^6.2.11",
68
+ "nestjs-cls": "^4.3.0",
69
+ "compression": "^1.8.0",
70
+ "@sentry/nestjs": "~9.17.0",
71
+ "@sentry/profiling-node": "~9.17.0"
72
+ },
73
+ "overrides": {
74
+ "@sentry-internal/node-cpu-profiler": "2.1.0"
68
75
  }
69
76
  }
@@ -15,18 +15,50 @@ const profiling_node_1 = require("@sentry/profiling-node");
15
15
  const dotenv = require("dotenv");
16
16
  const fs_1 = require("fs");
17
17
  const path_1 = require("path");
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}`);
18
+ const process = require("process");
19
+ function findValidRootPath() {
20
+ const getAppRootPath = () => {
21
+ if (require.main && require.main.filename) {
22
+ return (0, path_1.dirname)(require.main.filename);
23
+ }
24
+ if (process.argv[1]) {
25
+ return (0, path_1.dirname)(process.argv[1]);
26
+ }
27
+ return process.cwd();
28
+ };
29
+ const possibleRootPaths = [getAppRootPath(), process.cwd(), __dirname];
30
+ const envFile = `${process.env.NODE_ENV || ''}.env`;
31
+ const isTest = process.env.NODE_ENV === 'test';
32
+ let envFilePath = '';
33
+ for (const rootPath of possibleRootPaths) {
34
+ const configPath = (0, path_1.join)(rootPath, 'config');
35
+ const baseEnvFilePath = (0, path_1.join)(configPath, 'base.env');
36
+ if (isTest) {
37
+ envFilePath = (0, path_1.join)(configPath, 'test.env');
38
+ if ((0, fs_1.existsSync)(envFilePath)) {
39
+ return { rootPath, baseEnvFilePath, envFilePath };
40
+ }
41
+ else {
42
+ envFilePath = (0, path_1.join)(configPath, 'dev.env');
43
+ if ((0, fs_1.existsSync)(envFilePath)) {
44
+ return { rootPath, baseEnvFilePath, envFilePath };
45
+ }
46
+ }
47
+ }
48
+ else {
49
+ envFilePath = (0, path_1.join)(configPath, envFile);
50
+ if ((0, fs_1.existsSync)(envFilePath)) {
51
+ return { rootPath, baseEnvFilePath, envFilePath };
52
+ }
53
+ }
54
+ }
55
+ throw new Error(`No valid .env file: ${envFilePath}`);
29
56
  }
57
+ const { envFilePath, rootPath, baseEnvFilePath } = findValidRootPath();
58
+ dotenv.config({ path: [envFilePath, baseEnvFilePath] });
59
+ process.env.ROOT_PATH = rootPath;
60
+ process.env.ENV_FILE_PATH = envFilePath;
61
+ process.env.BASE_ENV_FILE_PATH = baseEnvFilePath;
30
62
  const requiredEnvVars = ['SENTRY_DSN', 'API_VERSION', 'NODE_ENV'];
31
63
  requiredEnvVars.forEach((envVar) => {
32
64
  if (!process.env[envVar]) {
@@ -38,13 +70,26 @@ Sentry.init({
38
70
  release: process.env.API_VERSION || '',
39
71
  environment: process.env.NODE_ENV || 'unkown',
40
72
  debug: process.env.NODE_ENV === 'dev',
41
- tracesSampleRate: 1.0,
42
- profileSessionSampleRate: 1.0,
73
+ sampleRate: 1.0,
74
+ tracesSampleRate: 0.01,
75
+ profileSessionSampleRate: 0.01,
43
76
  profileLifecycle: 'trace',
44
77
  sendDefaultPii: true,
45
78
  integrations: [profiling_node_1.nodeProfilingIntegration],
46
79
  });
47
80
  const crud_1 = require("@dataui/crud");
81
+ const core_1 = require("@nestjs/core");
82
+ const typeorm_transactional_1 = require("typeorm-transactional");
83
+ const nestjs_pino_1 = require("nestjs-pino");
84
+ const session = require("express-session");
85
+ const bodyParse = require("body-parser");
86
+ const __1 = require("../");
87
+ const common_1 = require("@nestjs/common");
88
+ const nestjs_i18n_1 = require("nestjs-i18n");
89
+ const nestjs_cls_1 = require("nestjs-cls");
90
+ const compression = require("compression");
91
+ const class_validator_1 = require("class-validator");
92
+ const setup_1 = require("@sentry/nestjs/setup");
48
93
  crud_1.CrudConfigService.load({
49
94
  auth: {
50
95
  property: 'user',
@@ -72,16 +117,6 @@ crud_1.CrudConfigService.load({
72
117
  },
73
118
  },
74
119
  });
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");
85
120
  const setupProcessHandlers = (app) => {
86
121
  const logger = app.get(nestjs_pino_1.Logger);
87
122
  process.on('uncaughtException', (error) => {
@@ -149,6 +184,7 @@ function bootstrapSetup(AppModule, SetupSwagger) {
149
184
  const app = yield core_1.NestFactory.create(AppModule, {
150
185
  bufferLogs: true,
151
186
  });
187
+ (0, class_validator_1.useContainer)(app.select(AppModule), { fallbackOnErrors: true });
152
188
  const configService = app.select(__1.ServiceRegistryModule).get(__1.ApiConfigService);
153
189
  const logger = app.get(nestjs_pino_1.Logger);
154
190
  setupProcessHandlers(app);
@@ -156,7 +192,7 @@ function bootstrapSetup(AppModule, SetupSwagger) {
156
192
  setupGracefulShutdown(app);
157
193
  app.enableVersioning();
158
194
  app.enable('trust proxy');
159
- app.use(bodyParse.json({ limit: '50mb' }), new nestjs_cls_1.ClsMiddleware({}).use, (0, __1.RequestIdMiddleware)(), (0, __1.PowerByMiddleware)(), (0, __1.OmniAuthMiddleware)());
195
+ app.use(bodyParse.json({ limit: '50mb' }), new nestjs_cls_1.ClsMiddleware({}).use, (0, __1.RequestIdMiddleware)(), (0, __1.PowerByMiddleware)(), (0, __1.OmniAuthMiddleware)(), compression());
160
196
  const reflector = app.get(core_1.Reflector);
161
197
  app.useGlobalFilters(new setup_1.SentryGlobalFilter(), new __1.HttpExceptionFilter(), new __1.QueryFailedFilter(reflector));
162
198
  app.useGlobalInterceptors(new __1.LanguageInterceptor(), new __1.TranslationInterceptor(), new nestjs_pino_1.LoggerErrorInterceptor());
@@ -14,6 +14,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
14
14
  step((generator = generator.apply(thisArg, _arguments || [])).next());
15
15
  });
16
16
  };
17
+ var _a;
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
19
  exports.ServiceRegistryModule = void 0;
19
20
  const path = require("path");
@@ -31,53 +32,29 @@ const typeorm_transactional_1 = require("typeorm-transactional");
31
32
  const nestjs_i18n_1 = require("nestjs-i18n");
32
33
  const health_checker_module_1 = require("../health-checker/health-checker.module");
33
34
  const services_1 = require("./services");
34
- const fs_1 = require("fs");
35
- const path_1 = require("path");
35
+ const nestjs_cls_1 = require("nestjs-cls");
36
36
  const providers = [
37
37
  services_1.ApiConfigService,
38
38
  services_1.ValidatorService,
39
39
  services_1.GeneratorService,
40
40
  services_1.TranslationService,
41
41
  ];
42
- const isTest = process.env.NODE_ENV === 'test';
43
- function findValidRootPath() {
44
- const possibleRootPaths = [process.cwd(), __dirname];
45
- const envFile = `${process.env.NODE_ENV || ''}.env`;
46
- let envFilePath = '';
47
- for (const rootPath of possibleRootPaths) {
48
- const configPath = (0, path_1.join)(rootPath, 'config');
49
- const baseEnvFilePath = (0, path_1.join)(configPath, 'base.env');
50
- if (isTest) {
51
- envFilePath = (0, path_1.join)(configPath, 'test.env');
52
- if ((0, fs_1.existsSync)(envFilePath)) {
53
- return { rootPath, baseEnvFilePath, envFilePath };
54
- }
55
- else {
56
- envFilePath = (0, path_1.join)(configPath, 'dev.env');
57
- if ((0, fs_1.existsSync)(envFilePath)) {
58
- return { rootPath, baseEnvFilePath, envFilePath };
59
- }
60
- }
61
- }
62
- else {
63
- envFilePath = (0, path_1.join)(configPath, envFile);
64
- if ((0, fs_1.existsSync)(envFilePath)) {
65
- return { rootPath, baseEnvFilePath, envFilePath };
66
- }
67
- }
68
- }
69
- throw new Error(`No valid .env file: ${envFilePath}`);
42
+ if (!((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.ENV_FILE_PATH)) {
43
+ require('../setup/bootstrap.setup');
70
44
  }
71
- const { envFilePath, rootPath, baseEnvFilePath } = findValidRootPath();
72
- services_1.ApiConfigService.rootPath = rootPath;
45
+ services_1.ApiConfigService.rootPath = process.env.ROOT_PATH;
73
46
  const modules = [
47
+ setup_1.SentryModule.forRoot(),
74
48
  config_1.ConfigModule.forRoot({
75
49
  isGlobal: true,
76
50
  cache: true,
77
51
  expandVariables: false,
78
- envFilePath: [envFilePath, baseEnvFilePath],
52
+ envFilePath: [process.env.ENV_FILE_PATH, process.env.BASE_ENV_FILE_PATH],
53
+ }),
54
+ nestjs_cls_1.ClsModule.forRoot({
55
+ global: true,
56
+ middleware: { mount: true },
79
57
  }),
80
- setup_1.SentryModule.forRoot(),
81
58
  nestjs_pino_1.LoggerModule.forRootAsync({
82
59
  inject: [services_1.ApiConfigService],
83
60
  useFactory: (config) => config.pinoConfig,