@mondart/nestjs-common-module 2.6.6 → 2.6.8
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/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/decorators/kafka-timestamp.decorator.d.ts +1 -0
- package/dist/decorators/kafka-timestamp.decorator.js +28 -0
- package/dist/dto/response/iam-context.dto.js +1 -0
- package/dist/filters/global-exception.filter.js +2 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.js +49 -0
- package/package.json +2 -2
package/dist/decorators/index.js
CHANGED
|
@@ -21,3 +21,4 @@ __exportStar(require("./get-agent.decorator"), exports);
|
|
|
21
21
|
__exportStar(require("./get-store-id.decorator"), exports);
|
|
22
22
|
__exportStar(require("./get-user.decorator"), exports);
|
|
23
23
|
__exportStar(require("./iam-context.decorator"), exports);
|
|
24
|
+
__exportStar(require("./kafka-timestamp.decorator"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function CheckKafkaTimestamp(timeoutInSeconds?: number): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CheckKafkaTimestamp = CheckKafkaTimestamp;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
function CheckKafkaTimestamp(timeoutInSeconds = 30) {
|
|
6
|
+
return (0, common_1.applyDecorators)((0, common_1.UseInterceptors)({
|
|
7
|
+
intercept: async (context, next) => {
|
|
8
|
+
const logger = new common_1.Logger('CheckKafkaTimestamp');
|
|
9
|
+
const kafkaCtx = context.getArgByIndex(1);
|
|
10
|
+
if (kafkaCtx && typeof kafkaCtx.getMessage === 'function') {
|
|
11
|
+
const message = kafkaCtx.getMessage();
|
|
12
|
+
const nowTimeInServer = new Date().getTime();
|
|
13
|
+
const messageTimestamp = Number(message.timestamp);
|
|
14
|
+
const diffTime = nowTimeInServer - messageTimestamp;
|
|
15
|
+
if (diffTime > timeoutInSeconds * 1000) {
|
|
16
|
+
logger.debug({
|
|
17
|
+
nowTimeInServer,
|
|
18
|
+
messageTimestamp,
|
|
19
|
+
diffTime,
|
|
20
|
+
message,
|
|
21
|
+
});
|
|
22
|
+
throw new common_1.BadRequestException(`Message is too old to process. Current time: ${nowTimeInServer}, Message timestamp: ${messageTimestamp}, Difference: ${diffTime}ms`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return next.handle();
|
|
26
|
+
},
|
|
27
|
+
}), (0, common_1.SetMetadata)('kafka-timestamp-check', true));
|
|
28
|
+
}
|
|
@@ -16,6 +16,7 @@ const crypto_1 = require("crypto");
|
|
|
16
16
|
class IamContextDto {
|
|
17
17
|
constructor(init) {
|
|
18
18
|
this.ip = init?.ip;
|
|
19
|
+
this.isAgent = init?.isAgent;
|
|
19
20
|
this.agentId = init?.agent ? init?.agent?.agentId : undefined;
|
|
20
21
|
this.agent = init?.agent;
|
|
21
22
|
this.userId = init?.user ? init?.user?.userId : undefined;
|
|
@@ -54,7 +54,8 @@ let GlobalExceptionFilter = class GlobalExceptionFilter {
|
|
|
54
54
|
if (type === 'http') {
|
|
55
55
|
const response = context.getResponse();
|
|
56
56
|
try {
|
|
57
|
-
|
|
57
|
+
const exceptionsName = Object.values(exceptions).map((exception) => exception.name);
|
|
58
|
+
if (exceptionsName.includes(exception.name)) {
|
|
58
59
|
const status = exception?.getStatus();
|
|
59
60
|
const result = exception.getResponse();
|
|
60
61
|
const message = typeof result?.message === 'string'
|