@saihu/common 1.1.60 → 1.1.62

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.
@@ -3,6 +3,6 @@ export declare const LOGIN_USER_KEY = "login_user:";
3
3
  export declare const COMMON_MODULE_OPTIONS = "COMMON_MODULE_OPTIONS";
4
4
  export declare const REDIS_SERVICE = "REDIS_SERVICE";
5
5
  export declare const RABBITMQ_SERVICE = "RABBITMQ_SERVICE";
6
- export declare const OPER_LOG_QUEUE = "q.oper.log.created.im-id";
6
+ export declare const OPER_LOG_QUEUE = "oper_log_queue";
7
7
  export declare const OPER_LOG_EXCHANGE = "oper_log_exchange";
8
8
  //# sourceMappingURL=common.consts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.consts.d.ts","sourceRoot":"","sources":["../../src/consts/common.consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAC5C,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAC7D,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AACnD,eAAO,MAAM,cAAc,6BAA6B,CAAC;AACzD,eAAO,MAAM,iBAAiB,sBAAsB,CAAC"}
1
+ {"version":3,"file":"common.consts.d.ts","sourceRoot":"","sources":["../../src/consts/common.consts.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAC5C,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAC7D,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AACnD,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAC/C,eAAO,MAAM,iBAAiB,sBAAsB,CAAC"}
@@ -6,5 +6,5 @@ exports.LOGIN_USER_KEY = 'login_user:';
6
6
  exports.COMMON_MODULE_OPTIONS = 'COMMON_MODULE_OPTIONS';
7
7
  exports.REDIS_SERVICE = 'REDIS_SERVICE';
8
8
  exports.RABBITMQ_SERVICE = 'RABBITMQ_SERVICE';
9
- exports.OPER_LOG_QUEUE = 'q.oper.log.created.im-id';
9
+ exports.OPER_LOG_QUEUE = 'oper_log_queue';
10
10
  exports.OPER_LOG_EXCHANGE = 'oper_log_exchange';
@@ -1,7 +1,6 @@
1
1
  import { ArgumentsHost } from '@nestjs/common';
2
2
  import { BaseRpcExceptionFilter } from '@nestjs/microservices';
3
- import { BaseError } from '../dto/base-res.dto';
4
3
  export declare class BaseErrorRpcFilter extends BaseRpcExceptionFilter {
5
- catch(exception: BaseError, host: ArgumentsHost): import("rxjs").Observable<any>;
4
+ catch(exception: any, host: ArgumentsHost): import("rxjs").Observable<any>;
6
5
  }
7
6
  //# sourceMappingURL=base-error-rpc.filter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base-error-rpc.filter.d.ts","sourceRoot":"","sources":["../../src/filters/base-error-rpc.filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAS,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAgB,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,qBACa,kBAAmB,SAAQ,sBAAsB;IAC5D,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa;CAWhD"}
1
+ {"version":3,"file":"base-error-rpc.filter.d.ts","sourceRoot":"","sources":["../../src/filters/base-error-rpc.filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAS,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAgB,MAAM,uBAAuB,CAAC;AAE7E,qBACa,kBAAmB,SAAQ,sBAAsB;IAC5D,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa;CA+B1C"}
@@ -10,21 +10,36 @@ exports.BaseErrorRpcFilter = void 0;
10
10
  // @saihu/common/src/filters/base-error-rpc.filter.ts
11
11
  const common_1 = require("@nestjs/common");
12
12
  const microservices_1 = require("@nestjs/microservices");
13
- const base_res_dto_1 = require("../dto/base-res.dto");
14
13
  let BaseErrorRpcFilter = class BaseErrorRpcFilter extends microservices_1.BaseRpcExceptionFilter {
15
14
  catch(exception, host) {
16
15
  var _a;
17
- // Wrap your BaseError into RpcException payload
18
- const payload = {
19
- code: exception.code,
20
- msg: exception.message,
21
- data: (_a = exception.data) !== null && _a !== void 0 ? _a : null,
22
- };
23
- // Delegate to the base filter with a proper RpcException
16
+ // Only transform for RPC
17
+ if (host.getType() !== 'rpc') {
18
+ return super.catch(exception, host);
19
+ }
20
+ // If it's already RpcException, pass through
21
+ if (exception instanceof microservices_1.RpcException) {
22
+ return super.catch(exception, host);
23
+ }
24
+ // Duck-type check for your BaseError shape
25
+ const isBaseErrorLike = ((exception === null || exception === void 0 ? void 0 : exception.name) === 'BaseError' ||
26
+ typeof (exception === null || exception === void 0 ? void 0 : exception.code) === 'number') &&
27
+ typeof (exception === null || exception === void 0 ? void 0 : exception.message) === 'string';
28
+ const payload = isBaseErrorLike
29
+ ? {
30
+ code: Number(exception.code) || 500,
31
+ msg: exception.message,
32
+ data: (_a = exception.data) !== null && _a !== void 0 ? _a : null,
33
+ }
34
+ : {
35
+ code: 500,
36
+ msg: 'Internal server error',
37
+ data: null,
38
+ };
24
39
  return super.catch(new microservices_1.RpcException(payload), host);
25
40
  }
26
41
  };
27
42
  exports.BaseErrorRpcFilter = BaseErrorRpcFilter;
28
43
  exports.BaseErrorRpcFilter = BaseErrorRpcFilter = __decorate([
29
- (0, common_1.Catch)(base_res_dto_1.BaseError)
44
+ (0, common_1.Catch)() // <-- catch everything (not just BaseError)
30
45
  ], BaseErrorRpcFilter);
@@ -1,4 +1,4 @@
1
1
  export * from './base-error.filter';
2
- export * from './validation-exception.filter';
3
2
  export * from './base-error-rpc.filter';
3
+ export * from './validation-exception.filter';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/filters/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/filters/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC"}
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./base-error.filter"), exports);
18
- __exportStar(require("./validation-exception.filter"), exports);
19
18
  __exportStar(require("./base-error-rpc.filter"), exports);
19
+ __exportStar(require("./validation-exception.filter"), exports);
@@ -6,18 +6,18 @@ class SaihuLogger {
6
6
  if (!context)
7
7
  return false;
8
8
  const hiddenContexts = [
9
- // 'InstanceLoader',
10
- // 'RoutesResolver',
11
- // 'RouterExplorer',
12
- // 'NestFactory',
13
- // 'NestApplication',
14
- // 'ClientProxy',
15
- // 'NestMicroservice',
9
+ 'InstanceLoader',
10
+ 'RoutesResolver',
11
+ 'RouterExplorer',
12
+ 'NestFactory',
13
+ 'NestApplication',
14
+ 'ClientProxy',
15
+ 'NestMicroservice',
16
16
  'AmqpConnection',
17
- // 'MicroserviceConfiguration',
18
- // 'RabbitMQModule',
19
- // 'WebSocketsController',
20
- // 'ExceptionsHandler', // ← Add this
17
+ 'MicroserviceConfiguration',
18
+ 'RabbitMQModule',
19
+ 'WebSocketsController',
20
+ 'ExceptionsHandler', // ← Add this
21
21
  ];
22
22
  return hiddenContexts.some((hidden) => context.includes(hidden));
23
23
  }
@@ -93,7 +93,7 @@ exports.ExchangeTypes = {
93
93
  [Exchanges.IM_DATA]: 'topic',
94
94
  [Exchanges.IM_INVENTORY]: 'topic',
95
95
  [Exchanges.MASTER_DATA]: 'topic',
96
- [Exchanges.OPER_LOG_EXCHANGE]: 'topic',
96
+ [Exchanges.OPER_LOG_EXCHANGE]: 'direct',
97
97
  [Exchanges.IM_SALES_ORDER]: 'topic',
98
98
  [Exchanges.SCM_DATA]: 'topic',
99
99
  [Exchanges.IM_PROCUREMENT_ORDER_DLX]: 'topic',
@@ -1 +1 @@
1
- {"version":3,"file":"rabbitmq.service.d.ts","sourceRoot":"","sources":["../../src/services/rabbitmq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGlE,qBACa,mBACX,YAAW,eAAe,EAAE,YAAY,EAAE,eAAe;IAUvD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAR1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAU;gBAIR,OAAO,EAAE,mBAAmB;IAKzC,YAAY;IAMZ,eAAe;IAIf,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA6BxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;CAkBrD"}
1
+ {"version":3,"file":"rabbitmq.service.d.ts","sourceRoot":"","sources":["../../src/services/rabbitmq.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EACZ,eAAe,EAGhB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAMtE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,qBACa,mBACX,YAAW,eAAe,EAAE,YAAY,EAAE,eAAe;IAUvD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAR1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAU;gBAIR,OAAO,EAAE,mBAAmB;IAKzC,YAAY;IAMZ,eAAe;IAIf,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA6BxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;CAkBrD"}
@@ -50,7 +50,6 @@ exports.RabbitmqServiceImpl = void 0;
50
50
  const common_1 = require("@nestjs/common");
51
51
  const amqp = __importStar(require("amqplib"));
52
52
  const common_consts_1 = require("../consts/common.consts");
53
- const messaging_1 = require("../messaging");
54
53
  let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
55
54
  constructor(options) {
56
55
  this.options = options;
@@ -111,7 +110,7 @@ let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
111
110
  }
112
111
  try {
113
112
  const messageBuffer = Buffer.from(JSON.stringify(message));
114
- return this.channel.publish(messaging_1.Exchanges.OPER_LOG_EXCHANGE, messaging_1.RoutingKeys[messaging_1.Exchanges.OPER_LOG_EXCHANGE].OPER_LOG_CREATED, messageBuffer);
113
+ return this.channel.publish(common_consts_1.OPER_LOG_EXCHANGE, common_consts_1.OPER_LOG_QUEUE, messageBuffer);
115
114
  }
116
115
  catch (error) {
117
116
  this.logger.error('Failed to publish message to RabbitMQ:', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saihu/common",
3
- "version": "1.1.60",
3
+ "version": "1.1.62",
4
4
  "description": "Common utilities for NestJS applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -33,7 +33,6 @@
33
33
  "@nestjs/config": "^4.0.2",
34
34
  "@nestjs/core": "^11.1.1",
35
35
  "@nestjs/jwt": "^11.0.0",
36
- "@nestjs/microservices": "^11.1.6",
37
36
  "amqp-connection-manager": "^5.0.0",
38
37
  "amqplib": "^0.10.9",
39
38
  "class-transformer": "^0.5.1",