@xrystal/core 3.8.5 → 3.8.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,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseApiClient } from '../../utils/index';
|
|
2
2
|
import ConfigsService from '../configs';
|
|
3
3
|
export default class ClientsService {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
static services: Record<string, any>;
|
|
5
|
+
apiClient: BaseApiClient;
|
|
6
|
+
baseApiClientName: string;
|
|
7
|
+
load({ configs }: {
|
|
7
8
|
configs: ConfigsService;
|
|
8
|
-
tmp: any;
|
|
9
9
|
}): Promise<void>;
|
|
10
10
|
}
|
|
@@ -1,40 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ApiClient, clientRegistry } from '../../utils/index';
|
|
1
|
+
import { BaseApiClient } from '../../utils/index';
|
|
3
2
|
export default class ClientsService {
|
|
3
|
+
static services = {};
|
|
4
4
|
apiClient;
|
|
5
|
-
|
|
6
|
-
async load({ configs
|
|
7
|
-
this.apiClient = new
|
|
8
|
-
clientName: this.
|
|
5
|
+
baseApiClientName = 'base-api-client';
|
|
6
|
+
async load({ configs }) {
|
|
7
|
+
this.apiClient = new BaseApiClient({
|
|
8
|
+
clientName: this.baseApiClientName,
|
|
9
9
|
baseURL: configs.all.baseApiUri || ''
|
|
10
10
|
});
|
|
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
|
-
}
|
|
11
|
+
ClientsService.services[this.baseApiClientName] = this.apiClient;
|
|
39
12
|
}
|
|
40
13
|
}
|
package/source/project/index.js
CHANGED
|
@@ -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);
|