@xrystal/core 3.10.1 → 3.10.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.10.1",
4
+ "version": "3.10.3",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -1,4 +1,4 @@
1
- export declare const getTmpFile: () => {
1
+ export declare const core: {
2
2
  _: any;
3
3
  };
4
4
  export declare const coreInit: (params: {
@@ -1,19 +1,10 @@
1
1
  // => import dependencies
2
2
  import path from 'path';
3
3
  import { SystemService, ConfigsService, LoggerService, EventsService, LocalizationsService, ClientsService } from '../loader/index';
4
- import { packageName, tmpFileDefaultName, tmpFileDefaultExt, findFileRecursively, x, kafkaBrokers, systemLoggerLayer, getTmpConfig, } from '../utils/index';
4
+ import { packageName, x, kafkaBrokers, systemLoggerLayer, getTmp, } from '../utils/index';
5
5
  //
6
6
  let coreHasRun = false;
7
- export const getTmpFile = () => {
8
- const ownerTmpFilePath = findFileRecursively(".", tmpFileDefaultName, tmpFileDefaultExt);
9
- if (!ownerTmpFilePath) {
10
- throw new Error(`${tmpFileDefaultName} file not found`);
11
- }
12
- const tmpFileObject = getTmpConfig({});
13
- return {
14
- _: tmpFileObject
15
- };
16
- };
7
+ export const core = getTmp();
17
8
  export const coreInit = async (params) => {
18
9
  const { locales } = params;
19
10
  if (locales)
@@ -23,12 +14,7 @@ const coreLoader = async ({}) => {
23
14
  if (coreHasRun)
24
15
  return {};
25
16
  try {
26
- const ownerTmpFilePath = findFileRecursively(".", tmpFileDefaultName, tmpFileDefaultExt);
27
- if (!ownerTmpFilePath) {
28
- throw new Error(`${tmpFileDefaultName} file not found`);
29
- }
30
- const tmpFileObject = getTmpConfig({});
31
- const { configs } = tmpFileObject;
17
+ const { configs } = core._;
32
18
  const rootFolderPath = configs.rootFolderPath;
33
19
  const services = [
34
20
  SystemService,
@@ -46,10 +32,10 @@ const coreLoader = async ({}) => {
46
32
  const i18n = x.get(LocalizationsService);
47
33
  const clientsService = x.get(ClientsService);
48
34
  await system.load({
49
- tmp: tmpFileObject
35
+ tmp: core._
50
36
  });
51
37
  configService.load({
52
- tmp: tmpFileObject,
38
+ tmp: core._,
53
39
  systemService: system,
54
40
  ...(configs.loaders.configs.globalEnvFileName && { globalEnvFileName: configs.loaders.configs.globalEnvFileName })
55
41
  });
@@ -1,3 +1,6 @@
1
+ export declare const getTmp: () => {
2
+ _: any;
3
+ };
1
4
  export declare const getTmpConfig: ({ root, tmpFileName, ext }: {
2
5
  root?: string;
3
6
  tmpFileName?: string;
@@ -1,7 +1,17 @@
1
1
  import path from "path";
2
2
  import fs from 'fs';
3
3
  import Handlebars from 'handlebars';
4
- import { SupportFileExtensionsEnum, tmpFileDefaultName, TmpFileLoader } from "../../index.js";
4
+ import { SupportFileExtensionsEnum, tmpFileDefaultExt, tmpFileDefaultName, TmpFileLoader } from "../../index.js";
5
+ export const getTmp = () => {
6
+ const ownerTmpFilePath = findFileRecursively(".", tmpFileDefaultName, tmpFileDefaultExt);
7
+ if (!ownerTmpFilePath) {
8
+ throw new Error(`${tmpFileDefaultName} file not found`);
9
+ }
10
+ const tmpFileObject = getTmpConfig({});
11
+ return {
12
+ _: tmpFileObject
13
+ };
14
+ };
5
15
  export const getTmpConfig = ({ root = '.', tmpFileName = tmpFileDefaultName, ext = '.yml' }) => {
6
16
  const path = findFileRecursively(root, tmpFileName, ext);
7
17
  if (!path) {
@@ -1,4 +1,10 @@
1
1
  import { ConfigsService, LoggerService } from '../../../loader';
2
+ type CustomRequestOptions = Omit<RequestInit, 'body'> & {
3
+ body?: any;
4
+ version?: string;
5
+ retries?: number;
6
+ debug?: boolean;
7
+ };
2
8
  export declare class ClientStore {
3
9
  private static _store;
4
10
  static get(clientName: string): any;
@@ -30,11 +36,7 @@ export declare abstract class Client {
30
36
  }
31
37
  export declare class BaseApiClient extends Client {
32
38
  constructor(config: any);
33
- request(path: string, options?: RequestInit & {
34
- version?: string;
35
- retries?: number;
36
- debug?: boolean;
37
- }): Promise<Response>;
39
+ request(path: string, options?: CustomRequestOptions): Promise<Response>;
38
40
  private _execute;
39
41
  }
40
42
  export declare abstract class AuthenticatedApiClient extends BaseApiClient {
@@ -53,3 +55,4 @@ export declare class SoapClient extends Client {
53
55
  constructor(config: any);
54
56
  call(methodName: string, args: any): Promise<any>;
55
57
  }
58
+ export {};
@@ -105,21 +105,21 @@ export class BaseApiClient extends Client {
105
105
  headers.set('x-internal-client', this.clientName);
106
106
  }
107
107
  const isDebugMode = options.debug !== undefined ? options.debug : this.debug;
108
+ const { version, retries, debug, ...fetchOptions } = options;
109
+ if (fetchOptions.body && typeof fetchOptions.body === 'object' && !(fetchOptions.body instanceof FormData)) {
110
+ fetchOptions.body = JSON.stringify(fetchOptions.body);
111
+ }
108
112
  if (isDebugMode) {
109
113
  const logPayload = {
110
114
  method: options.method || 'GET',
111
115
  url,
112
116
  headers: Object.fromEntries(headers.entries()),
113
- body: options.body ? (typeof options.body === 'string' ? JSON.parse(options.body) : options.body) : null
117
+ body: options.body
114
118
  };
115
119
  this.logger.winston.info(`${this.clientName} Request Details: ${JSON.stringify(logPayload, null, 2)}`);
116
120
  }
117
121
  const controller = new AbortController();
118
122
  const timeoutId = setTimeout(() => controller.abort(), this.timeout);
119
- const { version, retries, debug, ...fetchOptions } = options;
120
- if (fetchOptions.body && typeof fetchOptions.body === 'object') {
121
- fetchOptions.body = JSON.stringify(fetchOptions.body);
122
- }
123
123
  const response = await fetch(url, { ...fetchOptions, headers, signal: controller.signal });
124
124
  clearTimeout(timeoutId);
125
125
  return response;