@xrystal/core 3.11.5 → 3.11.7

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.11.5",
4
+ "version": "3.11.7",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -1,10 +1,11 @@
1
- import ConfigsService from '../configs';
2
- export default class ClientsService {
1
+ import { IService } from "source/utils";
2
+ import ConfigsService from "../configs";
3
+ export default class ClientsService implements IService {
3
4
  #private;
5
+ private _instances;
4
6
  constructor({ configsService }: {
5
7
  configsService: ConfigsService;
6
8
  });
7
- static get instances(): Record<string, any>;
8
- static set instances(value: Record<string, any>);
9
- load({}: {}): Promise<void>;
9
+ load(): Promise<void>;
10
+ get instances(): Record<string, any>;
10
11
  }
@@ -1,21 +1,18 @@
1
- import { BaseApiClient, CoreServiceEnum } from '../../utils/index';
1
+ import { BaseApiClient, CoreServiceEnum } from "source/utils";
2
2
  export default class ClientsService {
3
- static #services = {};
4
- #configs;
3
+ _instances = {};
4
+ #configsService;
5
5
  constructor({ configsService }) {
6
- this.#configs = configsService;
6
+ this.#configsService = configsService;
7
7
  }
8
- static get instances() {
9
- return this.#services;
10
- }
11
- static set instances(value) {
12
- this.#services = { ...this.#services, ...value };
13
- }
14
- async load({}) {
8
+ async load() {
15
9
  const baseClient = new BaseApiClient({
16
10
  clientName: CoreServiceEnum.BASE_API_CLIENT,
17
- baseURL: this.#configs.all.baseApiUri || ''
11
+ baseURL: this.#configsService.all.baseApiUri || ''
18
12
  });
19
- ClientsService.instances[CoreServiceEnum.BASE_API_CLIENT] = baseClient;
13
+ this._instances[CoreServiceEnum.BASE_API_CLIENT] = baseClient;
14
+ }
15
+ get instances() {
16
+ return this._instances;
20
17
  }
21
18
  }
@@ -1,5 +1,6 @@
1
1
  import SystemService from '../system/index';
2
- export default class ConfigsService {
2
+ import { IService } from '../../utils';
3
+ export default class ConfigsService implements IService {
3
4
  #private;
4
5
  private config;
5
6
  publicFolderName: string;
@@ -18,6 +18,8 @@ export default class ConfigsService {
18
18
  port: process.env.PORT || rawConfigs.port || 3000,
19
19
  systemStaticFolderPath: path.resolve(rawConfigs.rootFolderPath, this.publicFolderName),
20
20
  baseApiUri: process.env.HTTPS === 'true' ? process.env.SYSTEM_HTTPS_BASE_API_URI : process.env.SYSTEM_BASE_API_URI,
21
+ internalSecret: process.env.INTERNAL_SECRET,
22
+ secret: process.env.SECRET,
21
23
  env: process.env.NODE_ENV,
22
24
  ...rawConfigs
23
25
  };
@@ -1,5 +1,6 @@
1
+ import { IService } from '../../utils/index';
1
2
  import LoggerService from '../logger/index';
2
- export default class EventsService {
3
+ export default class EventsService implements IService {
3
4
  #private;
4
5
  constructor({ loggerService }: {
5
6
  loggerService: LoggerService;
@@ -1,4 +1,5 @@
1
- export default class LocalizationsService {
1
+ import { IService } from "../../utils";
2
+ export default class LocalizationsService implements IService {
2
3
  _instance: any;
3
4
  load: ({ loadPath, fallbackLang, preloadLang, }: {
4
5
  loadPath: string;
@@ -2,11 +2,12 @@ import winston from "winston";
2
2
  import "winston-daily-rotate-file";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import ConfigsService from "../configs";
5
+ import { IService } from "../../utils";
5
6
  interface CustomLogger extends winston.Logger {
6
7
  critical: winston.LeveledLogMethod;
7
8
  http: winston.LeveledLogMethod;
8
9
  }
9
- export default class LoggerService {
10
+ export default class LoggerService implements IService {
10
11
  #private;
11
12
  static readonly storage: AsyncLocalStorage<Map<string, string>>;
12
13
  private serviceName;
@@ -16,12 +17,12 @@ export default class LoggerService {
16
17
  constructor({ configsService }: {
17
18
  configsService: ConfigsService;
18
19
  });
20
+ load: (config: Record<string, any>) => Promise<void>;
19
21
  private safeReplacer;
20
22
  private getTracingFormat;
21
23
  private getConsoleFormat;
22
24
  winston: CustomLogger;
23
25
  runWithId: <T>(id: string, callback: () => T) => T;
24
- load: (config: Record<string, any>) => Promise<void>;
25
26
  winstonLoader: ({ loadPath, loggerLevel }: {
26
27
  loadPath: string;
27
28
  loggerLevel: string;
@@ -42,6 +42,38 @@ export default class LoggerService {
42
42
  this.#configsService = configsService;
43
43
  winston.addColors(customColors);
44
44
  }
45
+ load = async (config) => {
46
+ this.serviceName = config?.serviceName || "service";
47
+ this.kafkaTopic = config?.kafkaTopic || "logs";
48
+ const rawBrokers = config?.kafkaBrokers;
49
+ const brokers = rawBrokers ? String(rawBrokers).split(",").map((b) => b.trim()) : [];
50
+ if (brokers.length > 0) {
51
+ const kafka = new Kafka({
52
+ clientId: this.serviceName,
53
+ brokers: brokers,
54
+ logLevel: logLevel.NOTHING
55
+ });
56
+ this.kafkaProducer = kafka.producer({
57
+ createPartitioner: Partitioners.DefaultPartitioner,
58
+ retry: { initialRetryTime: 500, retries: 5 }
59
+ });
60
+ const connectKafka = async () => {
61
+ try {
62
+ await this.kafkaProducer?.connect();
63
+ this.isKafkaReady = true;
64
+ }
65
+ catch (err) {
66
+ this.isKafkaReady = false;
67
+ setTimeout(connectKafka, 10000);
68
+ }
69
+ };
70
+ connectKafka();
71
+ }
72
+ this.winstonLoader({
73
+ loadPath: config?.loadPath || "./logs",
74
+ loggerLevel: config?.loggerLevel || "debug"
75
+ });
76
+ };
45
77
  safeReplacer = (key, value) => {
46
78
  if (value instanceof Headers)
47
79
  return Object.fromEntries(value.entries());
@@ -81,38 +113,6 @@ export default class LoggerService {
81
113
  store.set("correlationId", id);
82
114
  return LoggerService.storage.run(store, callback);
83
115
  };
84
- load = async (config) => {
85
- this.serviceName = config?.serviceName || "service";
86
- this.kafkaTopic = config?.kafkaTopic || "logs";
87
- const rawBrokers = config?.kafkaBrokers;
88
- const brokers = rawBrokers ? String(rawBrokers).split(",").map((b) => b.trim()) : [];
89
- if (brokers.length > 0) {
90
- const kafka = new Kafka({
91
- clientId: this.serviceName,
92
- brokers: brokers,
93
- logLevel: logLevel.NOTHING
94
- });
95
- this.kafkaProducer = kafka.producer({
96
- createPartitioner: Partitioners.DefaultPartitioner,
97
- retry: { initialRetryTime: 500, retries: 5 }
98
- });
99
- const connectKafka = async () => {
100
- try {
101
- await this.kafkaProducer?.connect();
102
- this.isKafkaReady = true;
103
- }
104
- catch (err) {
105
- this.isKafkaReady = false;
106
- setTimeout(connectKafka, 10000);
107
- }
108
- };
109
- connectKafka();
110
- }
111
- this.winstonLoader({
112
- loadPath: config?.loadPath || "./logs",
113
- loggerLevel: config?.loggerLevel || "debug"
114
- });
115
- };
116
116
  winstonLoader = ({ loadPath, loggerLevel }) => {
117
117
  const { combine, timestamp, json, errors } = format;
118
118
  const tracing = this.getTracingFormat();
@@ -1,4 +1,5 @@
1
- export default class SystemService {
1
+ import { IService } from "../../utils";
2
+ export default class SystemService implements IService {
2
3
  _tmp: Record<string, any>;
3
4
  load: ({ tmp, }: {
4
5
  tmp: any;
@@ -24,8 +24,9 @@ const coreLoader = async ({}) => {
24
24
  LocalizationsService,
25
25
  ClientsService
26
26
  ];
27
- x.registerServices(services);
28
- x.initialize([
27
+ x
28
+ .registerServices(services)
29
+ .initialize([
29
30
  {
30
31
  service: SystemService,
31
32
  props: {
@@ -0,0 +1,3 @@
1
+ export declare class IService {
2
+ load({}: {}): void;
3
+ }
@@ -0,0 +1,4 @@
1
+ export class IService {
2
+ load({}) {
3
+ }
4
+ }
@@ -4,6 +4,7 @@ export * from './classes/class.tmp-file-loader';
4
4
  export * from './classes/class.controller';
5
5
  export * from './classes/class.response';
6
6
  export * from './classes/class.services';
7
+ export * from './classes/class.interfaces';
7
8
  export * from './types';
8
9
  export * from './enums';
9
10
  export { x, X, locator, Locator };
@@ -4,6 +4,7 @@ export * from './classes/class.tmp-file-loader';
4
4
  export * from './classes/class.controller';
5
5
  export * from './classes/class.response';
6
6
  export * from './classes/class.services';
7
+ export * from './classes/class.interfaces';
7
8
  export * from './types';
8
9
  export * from './enums';
9
10
  export { x, X, locator, Locator };