@xrystal/core 3.28.2 → 3.28.3
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/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import path from "node:path";
|
|
|
5
5
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
6
|
import { Partitioners } from "kafkajs";
|
|
7
7
|
import { LoggerLayerEnum } from '../../utils/models/enums/index';
|
|
8
|
-
import {
|
|
8
|
+
import { LogDTO } from "../../utils";
|
|
9
9
|
class KafkaTransport extends Transport {
|
|
10
10
|
service;
|
|
11
11
|
constructor(opts, service) {
|
|
@@ -154,7 +154,7 @@ export default class Logger {
|
|
|
154
154
|
await this.kafkaProducer.send({
|
|
155
155
|
topic: this.kafkaLogsTopic,
|
|
156
156
|
messages: [{
|
|
157
|
-
value: JSON.stringify(
|
|
157
|
+
value: JSON.stringify(LogDTO.getSchema({
|
|
158
158
|
level,
|
|
159
159
|
service: this.serviceName,
|
|
160
160
|
message,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NodeEnvEnum } from "../enums";
|
|
2
|
-
export interface
|
|
2
|
+
export interface ILogDTO {
|
|
3
3
|
level: string;
|
|
4
4
|
service: string;
|
|
5
5
|
message: string;
|
|
@@ -9,8 +9,8 @@ export interface ILogDto {
|
|
|
9
9
|
id?: string | number;
|
|
10
10
|
env: NodeEnvEnum;
|
|
11
11
|
}
|
|
12
|
-
export declare class
|
|
13
|
-
static getSchema({ level, service, message, payload, code, timestamp, id, env }:
|
|
12
|
+
export declare class LogDTO {
|
|
13
|
+
static getSchema({ level, service, message, payload, code, timestamp, id, env }: ILogDTO): {
|
|
14
14
|
level: string;
|
|
15
15
|
service: string;
|
|
16
16
|
message: string;
|
|
@@ -21,24 +21,27 @@ export declare class LogDto {
|
|
|
21
21
|
env: NodeEnvEnum;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
export interface
|
|
24
|
+
export interface IMetadata<E = any> {
|
|
25
25
|
source: string;
|
|
26
26
|
eventType: string;
|
|
27
27
|
timestamp: number;
|
|
28
28
|
correlationId: string;
|
|
29
29
|
userId?: string;
|
|
30
|
-
|
|
30
|
+
extraData?: E;
|
|
31
31
|
}
|
|
32
|
-
export interface
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
export interface IMessageInput<P = any, E = any> {
|
|
33
|
+
metadata: {
|
|
34
|
+
source: string;
|
|
35
|
+
eventType: string;
|
|
36
|
+
userId?: string;
|
|
37
|
+
correlationId?: string;
|
|
38
|
+
extraData?: E;
|
|
39
|
+
};
|
|
36
40
|
payload: P;
|
|
37
|
-
metadata?: M;
|
|
38
41
|
}
|
|
39
|
-
export declare class
|
|
40
|
-
static getSchema<P,
|
|
41
|
-
metadata:
|
|
42
|
+
export declare class QueueDTO {
|
|
43
|
+
static getSchema<P, E>(input: IMessageInput<P, E>): {
|
|
44
|
+
metadata: IMetadata<E>;
|
|
42
45
|
payload: P;
|
|
43
46
|
};
|
|
44
47
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class LogDTO {
|
|
2
2
|
static getSchema({ level, service, message, payload, code, timestamp, id, env }) {
|
|
3
3
|
if (!level || !service || !message || !timestamp || !env) {
|
|
4
4
|
throw new Error("Missing data other data required!");
|
|
@@ -15,22 +15,22 @@ export class LogDto {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
export class
|
|
19
|
-
static getSchema(
|
|
20
|
-
if (!
|
|
21
|
-
throw new Error("Source and eventType are required");
|
|
18
|
+
export class QueueDTO {
|
|
19
|
+
static getSchema(input) {
|
|
20
|
+
if (!input.metadata.source || !input.metadata.eventType) {
|
|
21
|
+
throw new Error("Source and eventType are required inside metadata");
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
source:
|
|
25
|
-
eventType:
|
|
23
|
+
const finalMetadata = {
|
|
24
|
+
source: input.metadata.source,
|
|
25
|
+
eventType: input.metadata.eventType,
|
|
26
26
|
timestamp: Date.now(),
|
|
27
|
-
correlationId: Math.random().toString(36).substring(7),
|
|
28
|
-
userId:
|
|
29
|
-
|
|
27
|
+
correlationId: input.metadata.correlationId || Math.random().toString(36).substring(7),
|
|
28
|
+
userId: input.metadata.userId,
|
|
29
|
+
extraData: input.metadata.extraData
|
|
30
30
|
};
|
|
31
31
|
return {
|
|
32
|
-
metadata,
|
|
33
|
-
payload:
|
|
32
|
+
metadata: finalMetadata,
|
|
33
|
+
payload: input.payload
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
}
|