@saihu/common 1.1.79 → 1.1.81

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.
@@ -1,2 +1,3 @@
1
1
  export * from './saihu-subscribe.decorator';
2
+ export * from './operlog.decorator';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC"}
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./saihu-subscribe.decorator"), exports);
18
+ __exportStar(require("./operlog.decorator"), exports);
@@ -0,0 +1,7 @@
1
+ export declare const OPERLOG_KEY = "operlog";
2
+ /**
3
+ * Decorator to enable operation logging for specific endpoints
4
+ * @param enabled - Whether to enable logging for this endpoint (default: true)
5
+ */
6
+ export declare const LogOperation: (enabled?: boolean) => import("@nestjs/common").CustomDecorator<string>;
7
+ //# sourceMappingURL=operlog.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operlog.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/operlog.decorator.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,YAAY,CAAC;AAErC;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,UAAS,OAAc,qDACjB,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogOperation = exports.OPERLOG_KEY = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.OPERLOG_KEY = 'operlog';
6
+ /**
7
+ * Decorator to enable operation logging for specific endpoints
8
+ * @param enabled - Whether to enable logging for this endpoint (default: true)
9
+ */
10
+ const LogOperation = (enabled = true) => (0, common_1.SetMetadata)(exports.OPERLOG_KEY, enabled);
11
+ exports.LogOperation = LogOperation;
@@ -7,6 +7,7 @@ export interface Operlog {
7
7
  org_id: string;
8
8
  oper_url: string;
9
9
  oper_ip: string;
10
+ headers?: string;
10
11
  oper_param: string;
11
12
  json_result: string;
12
13
  status: number;
@@ -1 +1 @@
1
- {"version":3,"file":"operlog.dto.d.ts","sourceRoot":"","sources":["../../src/dto/operlog.dto.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IAEtB,KAAK,EAAE,MAAM,CAAC;IAEd,MAAM,EAAE,MAAM,CAAC;IAEf,cAAc,EAAE,MAAM,CAAC;IAEvB,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,MAAM,CAAC;IAElB,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,EAAE,MAAM,CAAC;IAEjB,OAAO,EAAE,MAAM,CAAC;IAEhB,UAAU,EAAE,MAAM,CAAC;IAEnB,WAAW,EAAE,MAAM,CAAC;IAEpB,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,MAAM,CAAC;CACnB"}
1
+ {"version":3,"file":"operlog.dto.d.ts","sourceRoot":"","sources":["../../src/dto/operlog.dto.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IAEtB,KAAK,EAAE,MAAM,CAAC;IAEd,MAAM,EAAE,MAAM,CAAC;IAEf,cAAc,EAAE,MAAM,CAAC;IAEvB,UAAU,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,MAAM,CAAC;IAElB,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,EAAE,MAAM,CAAC;IAEjB,OAAO,EAAE,MAAM,CAAC;IAEhB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,UAAU,EAAE,MAAM,CAAC;IAEnB,WAAW,EAAE,MAAM,CAAC;IAEpB,MAAM,EAAE,MAAM,CAAC;IAEf,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -17,5 +17,9 @@ export declare class OperlogInterceptor implements NestInterceptor {
17
17
  * 获取请求参数
18
18
  */
19
19
  private getRequestParams;
20
+ /**
21
+ * 获取请求头
22
+ */
23
+ private getRequestHeaders;
20
24
  }
21
25
  //# sourceMappingURL=operlog.interceptor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"operlog.interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/operlog.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,gBAAgB,EAChB,WAAW,EAGZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAKtE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAIlE,qBACa,kBAAmB,YAAW,eAAe;IAMtD,OAAO,CAAC,SAAS;IACS,OAAO,CAAC,QAAQ,CAAC,eAAe;IAE1D,OAAO,CAAC,QAAQ,CAAC,OAAO;IAR1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,SAAS,CAAW;gBAGlB,SAAS,EAAE,SAAS,EACe,eAAe,EAAE,eAAe,EAE1D,OAAO,EAAE,mBAAmB;IAa/C,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC;IAqExE,OAAO,CAAC,WAAW;IAiCnB;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAWzB"}
1
+ {"version":3,"file":"operlog.interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/operlog.interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,gBAAgB,EAChB,WAAW,EAGZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAKtE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAKlE,qBACa,kBAAmB,YAAW,eAAe;IAMtD,OAAO,CAAC,SAAS;IACS,OAAO,CAAC,QAAQ,CAAC,eAAe;IAE1D,OAAO,CAAC,QAAQ,CAAC,OAAO;IAR1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,SAAS,CAAW;gBAGlB,SAAS,EAAE,SAAS,EACe,eAAe,EAAE,eAAe,EAE1D,OAAO,EAAE,mBAAmB;IAa/C,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC;IAkFxE,OAAO,CAAC,WAAW;IAiCnB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAYxB;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAG1B"}
@@ -18,6 +18,7 @@ const common_1 = require("@nestjs/common");
18
18
  const core_1 = require("@nestjs/core");
19
19
  const operators_1 = require("rxjs/operators");
20
20
  const common_consts_1 = require("../consts/common.consts");
21
+ const operlog_decorator_1 = require("../decorators/operlog.decorator");
21
22
  let OperlogInterceptor = OperlogInterceptor_1 = class OperlogInterceptor {
22
23
  constructor(reflector, rabbitmqService, options) {
23
24
  this.reflector = reflector;
@@ -35,6 +36,12 @@ let OperlogInterceptor = OperlogInterceptor_1 = class OperlogInterceptor {
35
36
  }
36
37
  intercept(context, next) {
37
38
  var _a;
39
+ // Check if the decorator is present and enabled
40
+ const isOperlogEnabled = this.reflector.getAllAndOverride(operlog_decorator_1.OPERLOG_KEY, [context.getHandler(), context.getClass()]);
41
+ // If decorator is not present or is disabled, skip logging
42
+ if (isOperlogEnabled !== true) {
43
+ return next.handle();
44
+ }
38
45
  if (!this.isEnabled) {
39
46
  return next.handle();
40
47
  }
@@ -62,6 +69,7 @@ let OperlogInterceptor = OperlogInterceptor_1 = class OperlogInterceptor {
62
69
  const method = request.method;
63
70
  const userAgent = request.get('user-agent') || '';
64
71
  const requestParams = this.getRequestParams(request);
72
+ const headers = this.getRequestHeaders(request);
65
73
  const operLog = {
66
74
  title: this.options.name,
67
75
  method: controllerClass + '.' + handler.name,
@@ -71,6 +79,7 @@ let OperlogInterceptor = OperlogInterceptor_1 = class OperlogInterceptor {
71
79
  org_id: ((_a = user === null || user === void 0 ? void 0 : user.orgId) === null || _a === void 0 ? void 0 : _a.toString()) || '',
72
80
  oper_url: url,
73
81
  oper_ip: clientIp,
82
+ headers: JSON.stringify(headers),
74
83
  oper_param: JSON.stringify(requestParams),
75
84
  json_result: '',
76
85
  status: 0,
@@ -133,6 +142,12 @@ let OperlogInterceptor = OperlogInterceptor_1 = class OperlogInterceptor {
133
142
  // 移除敏感信息
134
143
  return params;
135
144
  }
145
+ /**
146
+ * 获取请求头
147
+ */
148
+ getRequestHeaders(request) {
149
+ return { ...(request.headers || {}) };
150
+ }
136
151
  };
137
152
  exports.OperlogInterceptor = OperlogInterceptor;
138
153
  exports.OperlogInterceptor = OperlogInterceptor = OperlogInterceptor_1 = __decorate([
@@ -1,21 +1,27 @@
1
- import { Type } from "@nestjs/common";
1
+ import { Type } from '@nestjs/common';
2
2
  export interface CommonModuleOptions {
3
3
  /**
4
4
  * 模块名称
5
5
  */
6
6
  name: string;
7
7
  /**
8
- * 是否开启权限校验
8
+ * 是否开启权限校验 (需要配置 redis)
9
9
  */
10
10
  usePerms?: boolean;
11
11
  /**
12
- * 是否开启操作日志
12
+ * 是否开启操作日志 (需要配置 rabbitmq)
13
13
  */
14
14
  useOperlog?: boolean;
15
+ /**
16
+ * Redis 配置 (仅在 usePerms 为 true 时需要)
17
+ */
15
18
  redis?: {
16
19
  url: string;
17
20
  password: string;
18
21
  };
22
+ /**
23
+ * RabbitMQ 配置 (仅在 useOperlog 为 true 时需要)
24
+ */
19
25
  rabbitmq?: {
20
26
  url: string;
21
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE;QACN,GAAG,EAAE,MAAM,CAAC;QACZ,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IAEF,QAAQ,CAAC,EAAE;QACT,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC;IACnF,QAAQ,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,WAAW,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB"}
1
+ {"version":3,"file":"options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE;QACN,GAAG,EAAE,MAAM,CAAC;QACZ,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF;;OAEG;IACH,QAAQ,CAAC,EAAE;QACT,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,UAAU,EAAE,CACV,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,OAAO,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC;IACxD,QAAQ,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB,WAAW,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB"}
@@ -1 +1 @@
1
- {"version":3,"file":"saihu-common.module.d.ts","sourceRoot":"","sources":["../src/saihu-common.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,aAAa,EAAY,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,gCAAgC,CAAC;AAWxC,qBACa,iBAAiB;IAC5B,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,mBAAmB,GAAG,aAAa;IA6B3D,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;IA0BrE,MAAM,CAAC,sBAAsB,IAAI,aAAa;CAa/C"}
1
+ {"version":3,"file":"saihu-common.module.d.ts","sourceRoot":"","sources":["../src/saihu-common.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,aAAa,EAAY,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,gCAAgC,CAAC;AAWxC,qBACa,iBAAiB;IAC5B,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,mBAAmB,GAAG,aAAa;IA6B3D,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa;IAiCrE,MAAM,CAAC,sBAAsB,IAAI,aAAa;CAa/C"}
@@ -30,18 +30,18 @@ let SaihuCommonModule = SaihuCommonModule_1 = class SaihuCommonModule {
30
30
  provide: common_consts_1.RABBITMQ_SERVICE,
31
31
  useClass: rabbitmq_service_1.RabbitmqServiceImpl,
32
32
  },
33
+ // Add OperlogInterceptor as a regular provider so it can be used manually
34
+ interceptors_1.OperlogInterceptor,
33
35
  ];
34
- const useOperlog = options.useOperlog !== false;
35
- if (useOperlog) {
36
- providers.push({
37
- provide: core_1.APP_INTERCEPTOR,
38
- useClass: interceptors_1.OperlogInterceptor,
39
- });
40
- }
41
36
  return {
42
37
  module: SaihuCommonModule_1,
43
38
  providers,
44
- exports: [common_consts_1.COMMON_MODULE_OPTIONS, common_consts_1.REDIS_SERVICE, common_consts_1.RABBITMQ_SERVICE],
39
+ exports: [
40
+ common_consts_1.COMMON_MODULE_OPTIONS,
41
+ common_consts_1.REDIS_SERVICE,
42
+ common_consts_1.RABBITMQ_SERVICE,
43
+ interceptors_1.OperlogInterceptor,
44
+ ],
45
45
  global: true,
46
46
  };
47
47
  }
@@ -60,12 +60,19 @@ let SaihuCommonModule = SaihuCommonModule_1 = class SaihuCommonModule {
60
60
  provide: common_consts_1.RABBITMQ_SERVICE,
61
61
  useClass: rabbitmq_service_1.RabbitmqServiceImpl,
62
62
  },
63
+ // Add OperlogInterceptor as a regular provider so it can be used manually
64
+ interceptors_1.OperlogInterceptor,
63
65
  ];
64
66
  return {
65
67
  module: SaihuCommonModule_1,
66
68
  imports: [config_1.ConfigModule, ...(options.imports || [])],
67
69
  providers,
68
- exports: [common_consts_1.COMMON_MODULE_OPTIONS, common_consts_1.REDIS_SERVICE, common_consts_1.RABBITMQ_SERVICE],
70
+ exports: [
71
+ common_consts_1.COMMON_MODULE_OPTIONS,
72
+ common_consts_1.REDIS_SERVICE,
73
+ common_consts_1.RABBITMQ_SERVICE,
74
+ interceptors_1.OperlogInterceptor,
75
+ ],
69
76
  global: true, // 设置为全局模块
70
77
  };
71
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"redis.service.d.ts","sourceRoot":"","sources":["../../src/services/redis.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,qBACa,gBACX,YAAW,YAAY,EAAE,YAAY,EAAE,eAAe;IASpD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAPhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAC5D,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAkB;gBAIhB,aAAa,EAAE,mBAAmB;IAK/C,YAAY;IAIZ,UAAU;IAkCV,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAYtC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,eAAe;CAMhB"}
1
+ {"version":3,"file":"redis.service.d.ts","sourceRoot":"","sources":["../../src/services/redis.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,qBACa,gBACX,YAAW,YAAY,EAAE,YAAY,EAAE,eAAe;IASpD,OAAO,CAAC,QAAQ,CAAC,aAAa;IAPhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAC5D,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAkB;gBAIhB,aAAa,EAAE,mBAAmB;IAM/C,YAAY;IAIZ,UAAU;IAuCV,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAYtC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,eAAe;CAMhB"}
@@ -26,7 +26,8 @@ let RedisServiceImpl = RedisServiceImpl_1 = class RedisServiceImpl {
26
26
  this.logger = new common_1.Logger(RedisServiceImpl_1.name);
27
27
  this.isInitialized = false;
28
28
  this.isEnabled = false;
29
- this.isEnabled = commonOptions.usePerms !== false;
29
+ // Only enable Redis if usePerms is explicitly true
30
+ this.isEnabled = commonOptions.usePerms === true;
30
31
  }
31
32
  async onModuleInit() {
32
33
  await this.initialize();
@@ -40,16 +41,16 @@ let RedisServiceImpl = RedisServiceImpl_1 = class RedisServiceImpl {
40
41
  }
41
42
  try {
42
43
  if (!this.commonOptions.redis) {
43
- this.logger.error('common Redis options not found');
44
- throw new Error('common Redis options not found');
44
+ this.logger.error('Redis options not found. Redis is required when usePerms is true.');
45
+ throw new Error('Redis configuration is required when usePerms is enabled');
45
46
  }
46
47
  if (!this.commonOptions.redis.url) {
47
- this.logger.error('common Redis url not found');
48
- throw new Error('common Redis url not found');
48
+ this.logger.error('Redis url not found');
49
+ throw new Error('Redis url is required');
49
50
  }
50
51
  if (!this.commonOptions.redis.password) {
51
- this.logger.error('common Redis password not found');
52
- throw new Error('common Redis password not found');
52
+ this.logger.error('Redis password not found');
53
+ throw new Error('Redis password is required');
53
54
  }
54
55
  const url = this.commonOptions.redis.url;
55
56
  const password = this.commonOptions.redis.password;
@@ -57,10 +58,11 @@ let RedisServiceImpl = RedisServiceImpl_1 = class RedisServiceImpl {
57
58
  password,
58
59
  db: common_consts_1.REDIS_AUTH_DB,
59
60
  });
60
- // this.logger.log('common Redis connected successfully');
61
+ this.logger.log('Redis connected successfully');
62
+ this.isInitialized = true;
61
63
  }
62
64
  catch (error) {
63
- this.logger.error('common Failed to connect to Redis:', error);
65
+ this.logger.error('Failed to connect to Redis:', error);
64
66
  throw error;
65
67
  }
66
68
  }
@@ -89,7 +91,7 @@ let RedisServiceImpl = RedisServiceImpl_1 = class RedisServiceImpl {
89
91
  await this.redisClient.del(key);
90
92
  }
91
93
  onModuleDestroy() {
92
- if (!this.isEnabled) {
94
+ if (!this.isEnabled || !this.redisClient) {
93
95
  return;
94
96
  }
95
97
  this.redisClient.disconnect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saihu/common",
3
- "version": "1.1.79",
3
+ "version": "1.1.81",
4
4
  "description": "Common utilities for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",