@xrystal/core 3.28.1 → 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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.28.1",
4
+ "version": "3.28.3",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -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('comming', error);
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,47 @@
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 IMetadata<E = any> {
25
+ source: string;
26
+ eventType: string;
27
+ timestamp: number;
28
+ correlationId: string;
29
+ userId?: string;
30
+ extraData?: E;
31
+ }
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
+ };
40
+ payload: P;
41
+ }
42
+ export declare class QueueDTO {
43
+ static getSchema<P, E>(input: IMessageInput<P, E>): {
44
+ metadata: IMetadata<E>;
45
+ payload: P;
46
+ };
47
+ }
@@ -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(input) {
20
+ if (!input.metadata.source || !input.metadata.eventType) {
21
+ throw new Error("Source and eventType are required inside metadata");
22
+ }
23
+ const finalMetadata = {
24
+ source: input.metadata.source,
25
+ eventType: input.metadata.eventType,
26
+ timestamp: Date.now(),
27
+ correlationId: input.metadata.correlationId || Math.random().toString(36).substring(7),
28
+ userId: input.metadata.userId,
29
+ extraData: input.metadata.extraData
30
+ };
31
+ return {
32
+ metadata: finalMetadata,
33
+ payload: input.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, _ };