@saihu/common 1.1.68 → 1.1.70
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/consts/common.consts.d.ts +1 -1
- package/dist/consts/common.consts.d.ts.map +1 -1
- package/dist/consts/common.consts.js +1 -1
- package/dist/consts/index.d.ts +1 -1
- package/dist/filters/index.d.ts +0 -1
- package/dist/filters/index.d.ts.map +1 -1
- package/dist/filters/index.js +0 -1
- package/dist/interceptors/operlog.interceptor.d.ts +5 -5
- package/dist/interceptors/operlog.interceptor.d.ts.map +1 -1
- package/dist/interceptors/operlog.interceptor.js +14 -14
- package/dist/logger/saihu-logger.service.js +1 -1
- package/dist/messaging/topology.js +1 -1
- package/dist/services/rabbitmq.service.d.ts.map +1 -1
- package/dist/services/rabbitmq.service.js +2 -1
- package/package.json +2 -1
|
@@ -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 = "
|
|
6
|
+
export declare const OPER_LOG_QUEUE = "q.oper.log.created.im-id";
|
|
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":"
|
|
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"}
|
|
@@ -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 = '
|
|
9
|
+
exports.OPER_LOG_QUEUE = 'q.oper.log.created.im-id';
|
|
10
10
|
exports.OPER_LOG_EXCHANGE = 'oper_log_exchange';
|
package/dist/consts/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './common.consts';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/filters/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/filters/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/filters/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC"}
|
package/dist/filters/index.js
CHANGED
|
@@ -15,5 +15,4 @@ 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("./base-error-rpc.filter"), exports);
|
|
19
18
|
__exportStar(require("./validation-exception.filter"), exports);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { NestInterceptor, ExecutionContext, CallHandler } from
|
|
2
|
-
import { Reflector } from
|
|
3
|
-
import { Observable } from
|
|
4
|
-
import { CommonModuleOptions } from
|
|
5
|
-
import { RabbitmqService } from
|
|
1
|
+
import { NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import { CommonModuleOptions } from '../interfaces/options.interface';
|
|
5
|
+
import { RabbitmqService } from '../interfaces/service.interface';
|
|
6
6
|
export declare class OperlogInterceptor implements NestInterceptor {
|
|
7
7
|
private reflector;
|
|
8
8
|
private readonly rabbitmqService;
|
|
@@ -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;
|
|
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"}
|
|
@@ -38,7 +38,7 @@ let OperlogInterceptor = OperlogInterceptor_1 = class OperlogInterceptor {
|
|
|
38
38
|
return next.handle();
|
|
39
39
|
}
|
|
40
40
|
// 首先检查是否是 HTTP 请求
|
|
41
|
-
if (context.getType() !==
|
|
41
|
+
if (context.getType() !== 'http') {
|
|
42
42
|
return next.handle();
|
|
43
43
|
}
|
|
44
44
|
const startTime = Date.now();
|
|
@@ -59,21 +59,21 @@ let OperlogInterceptor = OperlogInterceptor_1 = class OperlogInterceptor {
|
|
|
59
59
|
return next.handle();
|
|
60
60
|
}
|
|
61
61
|
const method = request.method;
|
|
62
|
-
const userAgent = request.get(
|
|
62
|
+
const userAgent = request.get('user-agent') || '';
|
|
63
63
|
const requestParams = this.getRequestParams(request);
|
|
64
64
|
const operLog = {
|
|
65
65
|
title: this.options.name,
|
|
66
|
-
method: controllerClass +
|
|
66
|
+
method: controllerClass + '.' + handler.name,
|
|
67
67
|
request_method: method,
|
|
68
68
|
user_agent: userAgent,
|
|
69
|
-
oper_name: (user === null || user === void 0 ? void 0 : user.name) || (user === null || user === void 0 ? void 0 : user.moniker) ||
|
|
70
|
-
dept_name: (user === null || user === void 0 ? void 0 : user.dept_id) ||
|
|
69
|
+
oper_name: (user === null || user === void 0 ? void 0 : user.name) || (user === null || user === void 0 ? void 0 : user.moniker) || '',
|
|
70
|
+
dept_name: (user === null || user === void 0 ? void 0 : user.dept_id) || '',
|
|
71
71
|
oper_url: url,
|
|
72
72
|
oper_ip: clientIp,
|
|
73
73
|
oper_param: JSON.stringify(requestParams),
|
|
74
|
-
json_result:
|
|
74
|
+
json_result: '',
|
|
75
75
|
status: 0,
|
|
76
|
-
error_msg:
|
|
76
|
+
error_msg: '',
|
|
77
77
|
oper_time: startTime,
|
|
78
78
|
cost_time: 0,
|
|
79
79
|
};
|
|
@@ -95,9 +95,9 @@ let OperlogInterceptor = OperlogInterceptor_1 = class OperlogInterceptor {
|
|
|
95
95
|
getClientIp(request) {
|
|
96
96
|
try {
|
|
97
97
|
// 尝试从多个可能的头部获取 IP 地址
|
|
98
|
-
const possibleHeaders = [
|
|
98
|
+
const possibleHeaders = ['x-forwarded-for'];
|
|
99
99
|
let clientIp = request.ip ||
|
|
100
|
-
(request.connection ? request.connection.remoteAddress ||
|
|
100
|
+
(request.connection ? request.connection.remoteAddress || '' : '');
|
|
101
101
|
// 检查各种可能的头部
|
|
102
102
|
for (const header of possibleHeaders) {
|
|
103
103
|
if (request.headers[header]) {
|
|
@@ -106,18 +106,18 @@ let OperlogInterceptor = OperlogInterceptor_1 = class OperlogInterceptor {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
// 处理 IP 数组(如 x-forwarded-for: client, proxy1, proxy2)
|
|
109
|
-
if (clientIp && typeof clientIp ===
|
|
110
|
-
clientIp = clientIp.split(
|
|
109
|
+
if (clientIp && typeof clientIp === 'string' && clientIp.includes(',')) {
|
|
110
|
+
clientIp = clientIp.split(',')[0].trim();
|
|
111
111
|
}
|
|
112
112
|
// 移除 IPv6 前缀(如果存在)
|
|
113
|
-
if (clientIp && clientIp.substr(0, 7) ===
|
|
113
|
+
if (clientIp && clientIp.substr(0, 7) === '::ffff:') {
|
|
114
114
|
clientIp = clientIp.substr(7);
|
|
115
115
|
}
|
|
116
116
|
return clientIp;
|
|
117
117
|
}
|
|
118
118
|
catch (error) {
|
|
119
|
-
this.logger.error(
|
|
120
|
-
return
|
|
119
|
+
this.logger.error('Failed to get client IP:', error);
|
|
120
|
+
return '';
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
@@ -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]: '
|
|
96
|
+
[Exchanges.OPER_LOG_EXCHANGE]: 'topic',
|
|
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;
|
|
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"}
|
|
@@ -50,6 +50,7 @@ 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");
|
|
53
54
|
let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
|
|
54
55
|
constructor(options) {
|
|
55
56
|
this.options = options;
|
|
@@ -110,7 +111,7 @@ let RabbitmqServiceImpl = RabbitmqServiceImpl_1 = class RabbitmqServiceImpl {
|
|
|
110
111
|
}
|
|
111
112
|
try {
|
|
112
113
|
const messageBuffer = Buffer.from(JSON.stringify(message));
|
|
113
|
-
return this.channel.publish(
|
|
114
|
+
return this.channel.publish(messaging_1.Exchanges.OPER_LOG_EXCHANGE, messaging_1.RoutingKeys[messaging_1.Exchanges.OPER_LOG_EXCHANGE].OPER_LOG_CREATED, messageBuffer);
|
|
114
115
|
}
|
|
115
116
|
catch (error) {
|
|
116
117
|
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.
|
|
3
|
+
"version": "1.1.70",
|
|
4
4
|
"description": "Common utilities for NestJS applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -33,6 +33,7 @@
|
|
|
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",
|
|
36
37
|
"amqp-connection-manager": "^5.0.0",
|
|
37
38
|
"amqplib": "^0.10.9",
|
|
38
39
|
"class-transformer": "^0.5.1",
|