@xrystal/core 3.28.1 → 3.28.2
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 +1 -1
- package/source/loader/kafka/index.js +3 -2
- package/source/loader/logger/index.js +3 -2
- package/source/utils/models/classes/class.dtos.d.ts +44 -0
- package/source/utils/models/classes/class.dtos.js +36 -0
- package/source/utils/models/index.d.ts +3 -2
- package/source/utils/models/index.js +3 -2
- /package/source/utils/models/classes/{class.client.d.ts → class.clients.d.ts} +0 -0
- /package/source/utils/models/classes/{class.client.js → class.clients.js} +0 -0
package/package.json
CHANGED
|
@@ -72,8 +72,9 @@ export default class KafkaForCore {
|
|
|
72
72
|
])
|
|
73
73
|
],
|
|
74
74
|
};
|
|
75
|
-
if (isKafkaPassive === true || !kafkaBrokers)
|
|
75
|
+
if (isKafkaPassive === true || !kafkaBrokers) {
|
|
76
76
|
return;
|
|
77
|
+
}
|
|
77
78
|
const topicsToCreate = Array.isArray(kafkaTopics) ? kafkaTopics : [];
|
|
78
79
|
if (topicsToCreate.length === 0)
|
|
79
80
|
return;
|
|
@@ -96,7 +97,7 @@ export default class KafkaForCore {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
catch (error) {
|
|
99
|
-
console.log('
|
|
100
|
+
//console.log('Core kafka error', error)
|
|
100
101
|
}
|
|
101
102
|
finally {
|
|
102
103
|
await admin.disconnect();
|
|
@@ -5,6 +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 { LogDto } from "../../utils";
|
|
8
9
|
class KafkaTransport extends Transport {
|
|
9
10
|
service;
|
|
10
11
|
constructor(opts, service) {
|
|
@@ -153,7 +154,7 @@ export default class Logger {
|
|
|
153
154
|
await this.kafkaProducer.send({
|
|
154
155
|
topic: this.kafkaLogsTopic,
|
|
155
156
|
messages: [{
|
|
156
|
-
value: JSON.stringify({
|
|
157
|
+
value: JSON.stringify(LogDto.getSchema({
|
|
157
158
|
level,
|
|
158
159
|
service: this.serviceName,
|
|
159
160
|
message,
|
|
@@ -162,7 +163,7 @@ export default class Logger {
|
|
|
162
163
|
timestamp: new Date().toISOString(),
|
|
163
164
|
id: id || null,
|
|
164
165
|
env: this.#configs.all.env
|
|
165
|
-
}, this.safeReplacer)
|
|
166
|
+
}), this.safeReplacer)
|
|
166
167
|
}],
|
|
167
168
|
acks: 1
|
|
168
169
|
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { NodeEnvEnum } from "../enums";
|
|
2
|
+
export interface ILogDto {
|
|
3
|
+
level: string;
|
|
4
|
+
service: string;
|
|
5
|
+
message: string;
|
|
6
|
+
payload?: Record<string, any>;
|
|
7
|
+
code: string | number;
|
|
8
|
+
timestamp: string;
|
|
9
|
+
id?: string | number;
|
|
10
|
+
env: NodeEnvEnum;
|
|
11
|
+
}
|
|
12
|
+
export declare class LogDto {
|
|
13
|
+
static getSchema({ level, service, message, payload, code, timestamp, id, env }: ILogDto): {
|
|
14
|
+
level: string;
|
|
15
|
+
service: string;
|
|
16
|
+
message: string;
|
|
17
|
+
payload: Record<string, any>;
|
|
18
|
+
code: string | number;
|
|
19
|
+
timestamp: string;
|
|
20
|
+
id: string | number;
|
|
21
|
+
env: NodeEnvEnum;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface MetadataDto<M = any> {
|
|
25
|
+
source: string;
|
|
26
|
+
eventType: string;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
correlationId: string;
|
|
29
|
+
userId?: string;
|
|
30
|
+
extra?: M;
|
|
31
|
+
}
|
|
32
|
+
export interface IQueueDto<P = any, M = any> {
|
|
33
|
+
source: string;
|
|
34
|
+
eventType: string;
|
|
35
|
+
userId?: string;
|
|
36
|
+
payload: P;
|
|
37
|
+
metadata?: M;
|
|
38
|
+
}
|
|
39
|
+
export declare class QueueDto {
|
|
40
|
+
static getSchema<P, M>(data: IQueueDto<P, M>): {
|
|
41
|
+
metadata: MetadataDto<M>;
|
|
42
|
+
payload: P;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export class LogDto {
|
|
2
|
+
static getSchema({ level, service, message, payload, code, timestamp, id, env }) {
|
|
3
|
+
if (!level || !service || !message || !timestamp || !env) {
|
|
4
|
+
throw new Error("Missing data other data required!");
|
|
5
|
+
}
|
|
6
|
+
return {
|
|
7
|
+
level,
|
|
8
|
+
service,
|
|
9
|
+
message,
|
|
10
|
+
payload,
|
|
11
|
+
code,
|
|
12
|
+
timestamp,
|
|
13
|
+
id,
|
|
14
|
+
env
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class QueueDto {
|
|
19
|
+
static getSchema(data) {
|
|
20
|
+
if (!data.source || !data.eventType) {
|
|
21
|
+
throw new Error("Source and eventType are required");
|
|
22
|
+
}
|
|
23
|
+
const metadata = {
|
|
24
|
+
source: data.source,
|
|
25
|
+
eventType: data.eventType,
|
|
26
|
+
timestamp: Date.now(),
|
|
27
|
+
correlationId: Math.random().toString(36).substring(7),
|
|
28
|
+
userId: data.userId,
|
|
29
|
+
extra: data.metadata
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
metadata,
|
|
33
|
+
payload: data.payload
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -2,9 +2,10 @@ import _ from 'lodash';
|
|
|
2
2
|
import x from './classes/class.x';
|
|
3
3
|
import locator from './classes/class.service-locator';
|
|
4
4
|
export * from './classes/class.tmp-file-loader';
|
|
5
|
-
export * from './classes/class.response';
|
|
6
|
-
export * from './classes/class.client';
|
|
7
5
|
export * from './classes/class.interfaces';
|
|
6
|
+
export * from './classes/class.dtos';
|
|
7
|
+
export * from './classes/class.response';
|
|
8
|
+
export * from './classes/class.clients';
|
|
8
9
|
export * from './types';
|
|
9
10
|
export * from './enums';
|
|
10
11
|
export { x, locator, _ };
|
|
@@ -2,9 +2,10 @@ import _ from 'lodash';
|
|
|
2
2
|
import x from './classes/class.x';
|
|
3
3
|
import locator from './classes/class.service-locator';
|
|
4
4
|
export * from './classes/class.tmp-file-loader';
|
|
5
|
-
export * from './classes/class.response';
|
|
6
|
-
export * from './classes/class.client';
|
|
7
5
|
export * from './classes/class.interfaces';
|
|
6
|
+
export * from './classes/class.dtos';
|
|
7
|
+
export * from './classes/class.response';
|
|
8
|
+
export * from './classes/class.clients';
|
|
8
9
|
export * from './types';
|
|
9
10
|
export * from './enums';
|
|
10
11
|
export { x, locator, _ };
|
|
File without changes
|
|
File without changes
|