@xrystal/core 3.8.5 → 3.8.8
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/clients/index.d.ts +3 -5
- package/source/loader/clients/index.js +7 -35
- package/source/loader/index.d.ts +2 -1
- package/source/loader/index.js +2 -1
- package/source/project/index.js +3 -4
- package/source/utils/models/classes/class.services.d.ts +2 -3
- package/source/utils/models/classes/class.services.js +2 -3
package/package.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { ApiClient } from '../../utils/index';
|
|
2
1
|
import ConfigsService from '../configs';
|
|
3
2
|
export default class ClientsService {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
load({ configs
|
|
3
|
+
static services: Record<string, any>;
|
|
4
|
+
baseApiClientName: string;
|
|
5
|
+
load({ configs }: {
|
|
7
6
|
configs: ConfigsService;
|
|
8
|
-
tmp: any;
|
|
9
7
|
}): Promise<void>;
|
|
10
8
|
}
|
|
@@ -1,40 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ApiClient, clientRegistry } from '../../utils/index';
|
|
1
|
+
import { BaseApiClient } from '../../utils/index';
|
|
3
2
|
export default class ClientsService {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
async load({ configs
|
|
7
|
-
|
|
8
|
-
clientName: this.
|
|
3
|
+
static services = {};
|
|
4
|
+
baseApiClientName = 'base-api-client';
|
|
5
|
+
async load({ configs }) {
|
|
6
|
+
const baseApiClient = new BaseApiClient({
|
|
7
|
+
clientName: this.baseApiClientName,
|
|
9
8
|
baseURL: configs.all.baseApiUri || ''
|
|
10
9
|
});
|
|
11
|
-
|
|
12
|
-
const loaderConfig = tmp?.configs?.loaders?.clients;
|
|
13
|
-
if (!loaderConfig)
|
|
14
|
-
return;
|
|
15
|
-
const { loadPath, list } = loaderConfig;
|
|
16
|
-
let serviceMap = {};
|
|
17
|
-
if (loadPath) {
|
|
18
|
-
try {
|
|
19
|
-
const resolvedPath = path.resolve(process.cwd(), loadPath);
|
|
20
|
-
serviceMap = await import(resolvedPath);
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
//
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (list) {
|
|
27
|
-
for (const [instanceName, className] of Object.entries(list)) {
|
|
28
|
-
const ServiceClass = serviceMap[className];
|
|
29
|
-
if (ServiceClass) {
|
|
30
|
-
clientRegistry[instanceName] = new ServiceClass({
|
|
31
|
-
clientName: instanceName,
|
|
32
|
-
baseURL: configs.all[`${instanceName}Uri`] || configs.all.baseApiUri || '',
|
|
33
|
-
version: configs.all[`${instanceName}Version`] || 'v1',
|
|
34
|
-
timeout: configs.all[`${instanceName}Timeout`] || 15000
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
10
|
+
ClientsService.services[this.baseApiClientName] = baseApiClient;
|
|
39
11
|
}
|
|
40
12
|
}
|
package/source/loader/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import ConfigsService from "./configs";
|
|
|
3
3
|
import LoggerService from "./logger";
|
|
4
4
|
import EventsService from "./events";
|
|
5
5
|
import LocalizationsService from "./localizations";
|
|
6
|
-
|
|
6
|
+
import ClientsService from "./clients";
|
|
7
|
+
export { SystemService, ConfigsService, LoggerService, EventsService, LocalizationsService, ClientsService };
|
package/source/loader/index.js
CHANGED
|
@@ -3,4 +3,5 @@ import ConfigsService from "./configs";
|
|
|
3
3
|
import LoggerService from "./logger";
|
|
4
4
|
import EventsService from "./events";
|
|
5
5
|
import LocalizationsService from "./localizations";
|
|
6
|
-
|
|
6
|
+
import ClientsService from "./clients";
|
|
7
|
+
export { SystemService, ConfigsService, LoggerService, EventsService, LocalizationsService, ClientsService };
|
package/source/project/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// => import dependencies
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import { SystemService, ConfigsService, LoggerService, EventsService, LocalizationsService } from '../loader/index';
|
|
3
|
+
import { SystemService, ConfigsService, LoggerService, EventsService, LocalizationsService, ClientsService } from '../loader/index';
|
|
4
4
|
import { packageName, tmpFileDefaultName, tmpFileDefaultExt, findFileRecursively, TmpFileLoader, x, kafkaBrokers, systemLoggerLayer, } from '../utils/index';
|
|
5
|
-
import ClientsService from 'source/loader/clients';
|
|
6
5
|
//
|
|
7
6
|
let coreHasRun = false;
|
|
8
7
|
export const coreInit = async (params) => {
|
|
@@ -27,7 +26,8 @@ const coreLoader = async ({}) => {
|
|
|
27
26
|
ConfigsService,
|
|
28
27
|
LoggerService,
|
|
29
28
|
EventsService,
|
|
30
|
-
LocalizationsService
|
|
29
|
+
LocalizationsService,
|
|
30
|
+
ClientsService
|
|
31
31
|
];
|
|
32
32
|
services.forEach(service => x.set({ service, reference: service }));
|
|
33
33
|
const system = x.get(SystemService);
|
|
@@ -62,7 +62,6 @@ const coreLoader = async ({}) => {
|
|
|
62
62
|
});
|
|
63
63
|
await clientsService.load({
|
|
64
64
|
configs: configService,
|
|
65
|
-
tmp: r,
|
|
66
65
|
});
|
|
67
66
|
coreHasRun = true;
|
|
68
67
|
return { _: r };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import nodemailer from 'nodemailer';
|
|
2
2
|
import { ConfigsService, LoggerService } from 'source/loader';
|
|
3
|
-
export declare const clientRegistry: Record<string, any>;
|
|
4
3
|
export declare abstract class Service {
|
|
5
4
|
protected configService: ConfigsService;
|
|
6
5
|
protected logger: LoggerService;
|
|
@@ -23,7 +22,7 @@ export declare abstract class Service {
|
|
|
23
22
|
length?: number;
|
|
24
23
|
}) => string;
|
|
25
24
|
}
|
|
26
|
-
export declare class
|
|
25
|
+
export declare class BaseApiClient extends Service {
|
|
27
26
|
constructor(config: {
|
|
28
27
|
clientName: string;
|
|
29
28
|
baseURL: string;
|
|
@@ -32,7 +31,7 @@ export declare class ApiClient extends Service {
|
|
|
32
31
|
});
|
|
33
32
|
request(path: string, options?: RequestInit): Promise<Response>;
|
|
34
33
|
}
|
|
35
|
-
export declare abstract class AuthenticatedApiClient extends
|
|
34
|
+
export declare abstract class AuthenticatedApiClient extends BaseApiClient {
|
|
36
35
|
accessToken?: string;
|
|
37
36
|
constructor(config: {
|
|
38
37
|
clientName: string;
|
|
@@ -5,7 +5,6 @@ import hbs from 'nodemailer-express-handlebars';
|
|
|
5
5
|
import soap from 'soap';
|
|
6
6
|
import { ConfigsService, LoggerService } from 'source/loader';
|
|
7
7
|
import { TokensEnum, x } from '..';
|
|
8
|
-
export const clientRegistry = {};
|
|
9
8
|
export class Service {
|
|
10
9
|
configService = x.get(ConfigsService);
|
|
11
10
|
logger = x.get(LoggerService);
|
|
@@ -31,7 +30,7 @@ export class Service {
|
|
|
31
30
|
return result;
|
|
32
31
|
};
|
|
33
32
|
}
|
|
34
|
-
export class
|
|
33
|
+
export class BaseApiClient extends Service {
|
|
35
34
|
constructor(config) {
|
|
36
35
|
super(config);
|
|
37
36
|
}
|
|
@@ -61,7 +60,7 @@ export class ApiClient extends Service {
|
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
|
-
export class AuthenticatedApiClient extends
|
|
63
|
+
export class AuthenticatedApiClient extends BaseApiClient {
|
|
65
64
|
accessToken;
|
|
66
65
|
constructor(config) {
|
|
67
66
|
super(config);
|