@xrystal/core 3.10.4 → 3.10.6

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.10.4",
4
+ "version": "3.10.6",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -1,5 +1,5 @@
1
1
  import path from 'node:path';
2
- import { publicFolderName } from 'source/utils';
2
+ import { publicFolderName } from '../../utils';
3
3
  export default class ConfigsService {
4
4
  config = {};
5
5
  publicFolderName = publicFolderName;
@@ -1,3 +1,4 @@
1
+ import { LoggerService } from '../../../loader';
1
2
  import { ProtocolEnum } from '../../index';
2
3
  export interface CustomRequest {
3
4
  accounts?: any;
@@ -16,15 +17,16 @@ export interface CustomResponse {
16
17
  locals: Record<string, any>;
17
18
  }
18
19
  declare abstract class Controller {
19
- private logger;
20
+ protected loggerService: LoggerService;
20
21
  protected protocol: ProtocolEnum | null;
21
22
  protected req: CustomRequest | null;
22
23
  protected res: CustomResponse | null;
23
- constructor({ protocol, req, res, ctx }: {
24
+ constructor({ protocol, req, res, ctx, loggerService }: {
24
25
  protocol: ProtocolEnum;
25
26
  req?: any;
26
27
  res?: any;
27
28
  ctx?: any;
29
+ loggerService: LoggerService;
28
30
  });
29
31
  protected responseProtocolSwitch: ({ res, resStatus, context, req }: any) => Promise<any>;
30
32
  protected parsedQuerys: (url: string) => Record<string, any>;
@@ -1,13 +1,13 @@
1
1
  import qs from 'qs';
2
- import { LoggerService } from '../../../loader';
3
- import { ProtocolEnum, responseMessageHelper, ResponseSchema, x } from '../../index';
2
+ import { ProtocolEnum, responseMessageHelper, ResponseSchema } from '../../index';
4
3
  class Controller {
5
- logger = x.get(LoggerService);
4
+ loggerService;
6
5
  protocol = null;
7
6
  req = null;
8
7
  res = null;
9
- constructor({ protocol, req, res, ctx }) {
8
+ constructor({ protocol, req, res, ctx, loggerService }) {
10
9
  this.protocol = protocol;
10
+ this.loggerService = loggerService;
11
11
  if (ctx) {
12
12
  this.req = {
13
13
  url: ctx.request?.url || '',
@@ -11,14 +11,14 @@ export declare class ClientStore {
11
11
  static set(clientName: string, data: Record<string, any>): void;
12
12
  }
13
13
  export declare abstract class Client {
14
- protected configService: ConfigsService;
15
- protected logger: LoggerService;
16
14
  clientName: string;
17
15
  protected baseURL: string;
18
16
  protected version: string | null;
19
17
  protected timeout: number;
20
18
  protected debug: boolean;
21
19
  protected authConfigs: any;
20
+ protected loggerService: LoggerService;
21
+ protected configsService: ConfigsService;
22
22
  protected breaker: {
23
23
  failures: number;
24
24
  lastFailure: number;
@@ -26,7 +26,7 @@ export declare abstract class Client {
26
26
  threshold: number;
27
27
  cooldown: number;
28
28
  };
29
- constructor({ clientName, baseURL, version, timeout, auth, debug }: any);
29
+ constructor({ loggerService, configsService, clientName, baseURL, version, timeout, auth, debug }: any);
30
30
  protected resolvePath(obj: any, path: string): any;
31
31
  static cryptoHashGenerate: ({ algorithm, input, digest }: {
32
32
  algorithm: string;
@@ -1,7 +1,7 @@
1
1
  import { createHash, createHmac } from 'node:crypto';
2
2
  import soap from 'soap';
3
- import { ConfigsService, LoggerService } from '../../../loader';
4
- import { LoggerLayerEnum, x } from '../../index';
3
+ import { LoggerService } from '../../../loader';
4
+ import { LoggerLayerEnum } from '../../index';
5
5
  export class ClientStore {
6
6
  static _store = {};
7
7
  static get(clientName) { return this._store[clientName] || {}; }
@@ -10,14 +10,14 @@ export class ClientStore {
10
10
  }
11
11
  }
12
12
  export class Client {
13
- configService = x.get(ConfigsService);
14
- logger = x.get(LoggerService);
15
13
  clientName;
16
14
  baseURL;
17
15
  version = null;
18
16
  timeout = 15000;
19
- debug = Number(this.configService.all.debug) >= LoggerLayerEnum.DEBUG;
17
+ debug = false;
20
18
  authConfigs;
19
+ loggerService;
20
+ configsService;
21
21
  breaker = {
22
22
  failures: 0,
23
23
  lastFailure: 0,
@@ -25,12 +25,15 @@ export class Client {
25
25
  threshold: 5,
26
26
  cooldown: 30000
27
27
  };
28
- constructor({ clientName, baseURL, version, timeout, auth, debug }) {
28
+ constructor({ loggerService, configsService, clientName, baseURL, version, timeout, auth, debug }) {
29
+ this.loggerService = loggerService;
30
+ this.configsService = configsService;
31
+ this.debug = Number(this.configsService.all.debug) >= LoggerLayerEnum.DEBUG;
32
+ this.debug = debug ?? this.debug;
29
33
  this.clientName = clientName;
30
34
  this.baseURL = baseURL;
31
35
  this.version = version || null;
32
36
  this.authConfigs = auth;
33
- this.debug = debug ?? this.debug;
34
37
  if (timeout)
35
38
  this.timeout = timeout;
36
39
  if (auth?.token)
@@ -94,7 +97,7 @@ export class BaseApiClient extends Client {
94
97
  headers.set('Content-Type', 'application/json');
95
98
  if (correlationId)
96
99
  headers.set('x-correlation-id', correlationId);
97
- const systemSecret = this.configService.all.internalSecret || process.env.INTERNAL_SECRET;
100
+ const systemSecret = this.configsService.all.internalSecret || process.env.INTERNAL_SECRET;
98
101
  if (systemSecret) {
99
102
  const timestamp = Date.now().toString();
100
103
  const signature = createHmac('sha256', systemSecret)
@@ -116,7 +119,7 @@ export class BaseApiClient extends Client {
116
119
  headers: Object.fromEntries(headers.entries()),
117
120
  body: options.body
118
121
  };
119
- this.logger.winston.info(`${this.clientName} Request Details: ${JSON.stringify(logPayload, null, 2)}`);
122
+ this.loggerService.winston.info(`${this.clientName} Request Details: ${JSON.stringify(logPayload, null, 2)}`);
120
123
  }
121
124
  const controller = new AbortController();
122
125
  const timeoutId = setTimeout(() => controller.abort(), this.timeout);
@@ -189,7 +192,7 @@ export class SoapClient extends Client {
189
192
  return result[0];
190
193
  }
191
194
  catch (error) {
192
- this.logger.winston.error(`${this.clientName} SOAP Error: ${error.message}`);
195
+ this.loggerService.winston.error(`${this.clientName} SOAP Error: ${error.message}`);
193
196
  return null;
194
197
  }
195
198
  }