@rws-framework/client 2.21.5 → 2.22.1
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ITypesResponse } from '../../../components/src/types/IBackendCore';
|
|
2
2
|
import TheService from './_service';
|
|
3
3
|
|
|
4
4
|
//@4DI
|
|
@@ -20,11 +20,14 @@ interface IAPIOptions {
|
|
|
20
20
|
routeParams?: {
|
|
21
21
|
[key: string]: string
|
|
22
22
|
},
|
|
23
|
+
queryParams?: {
|
|
24
|
+
[key: string]: string
|
|
25
|
+
}
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
interface IHTTProute<P = {[key: string]: any}> {
|
|
26
29
|
name: string;
|
|
27
|
-
path: string;
|
|
30
|
+
path: string | string[];
|
|
28
31
|
method: string;
|
|
29
32
|
noParams?: boolean;
|
|
30
33
|
options?: any;
|
|
@@ -89,16 +92,16 @@ class ApiService extends TheService {
|
|
|
89
92
|
public delete = calls.delete;
|
|
90
93
|
|
|
91
94
|
public back = {
|
|
92
|
-
get: async <T>(routeName: string, options?: IAPIOptions, token?: string): Promise<T> => calls.get.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), options) as Promise<T>,
|
|
93
|
-
post: async <T, P extends object = object>(routeName: string, payload?: P, options?: IAPIOptions): Promise<T> => calls.post.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), payload, options) as Promise<T>,
|
|
94
|
-
put: async <T, P extends object = object>(routeName: string, payload: P, options?: IAPIOptions): Promise<T> => calls.put.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), payload, options) as Promise<T>,
|
|
95
|
-
delete: async <T>(routeName: string, options?: IAPIOptions): Promise<T> => calls.delete.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), options) as Promise<T>,
|
|
95
|
+
get: async <T>(routeName: string, options?: IAPIOptions, token?: string): Promise<T> => calls.get.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams, options?.queryParams), options) as Promise<T>,
|
|
96
|
+
post: async <T, P extends object = object>(routeName: string, payload?: P, options?: IAPIOptions): Promise<T> => calls.post.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams, options?.queryParams), payload, options) as Promise<T>,
|
|
97
|
+
put: async <T, P extends object = object>(routeName: string, payload: P, options?: IAPIOptions): Promise<T> => calls.put.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams, options?.queryParams), payload, options) as Promise<T>,
|
|
98
|
+
delete: async <T>(routeName: string, options?: IAPIOptions): Promise<T> => calls.delete.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams, options?.queryParams), options) as Promise<T>,
|
|
96
99
|
uploadFile: async (routeName: string, file: File, onProgress: (progress: number) => void, options: IAPIOptions = {}, payload: any = {}): Promise<UploadResponse> => this.uploadFile(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), file, onProgress, payload),
|
|
97
100
|
};
|
|
98
101
|
|
|
99
|
-
async getResource(resourceName: string): Promise<
|
|
102
|
+
async getResource(resourceName: string): Promise<ITypesResponse>
|
|
100
103
|
{
|
|
101
|
-
return calls.get.bind(this)(`${this.config.get('backendUrl')}${this.config.get('apiPrefix') || ''}/api/rws/resource/${resourceName}`) as Promise<
|
|
104
|
+
return calls.get.bind(this)(`${this.config.get('backendUrl')}${this.config.get('apiPrefix') || ''}/api/rws/resource/${resourceName}`) as Promise<ITypesResponse>
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
|
|
@@ -2,7 +2,7 @@ import { ApiServiceInstance, IBackendRoute, IHTTProute } from "../ApiService";
|
|
|
2
2
|
import { ConfigServiceInstance } from "../ConfigService";
|
|
3
3
|
|
|
4
4
|
export const backend = {
|
|
5
|
-
getBackendUrl(this: ApiServiceInstance, routeName: string, params: {[key: string]: string} = {}): string
|
|
5
|
+
getBackendUrl(this: ApiServiceInstance, routeName: string, params: {[key: string]: string} = {}, queryParams: {[key: string]: string} = {}): string
|
|
6
6
|
{
|
|
7
7
|
const config = this.config;
|
|
8
8
|
const routesPackage = config.get('backendRoutes');
|
|
@@ -43,13 +43,12 @@ export const backend = {
|
|
|
43
43
|
];
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
routes = [...routes, ...item.routes.map((subRouteItem: IHTTProute): IHTTProute => {
|
|
47
47
|
const subRoute: IHTTProute = {
|
|
48
|
-
path: item.prefix + subRouteItem.path,
|
|
48
|
+
path: Array.isArray(subRouteItem.path) ? subRouteItem.path.map(subPath => item.prefix + subPath) : item.prefix + subRouteItem.path,
|
|
49
49
|
name: backend.checkPrefixedRouteName(subRouteItem.name, item.controllerName),
|
|
50
50
|
method: subRouteItem.method || 'GET'
|
|
51
|
-
};
|
|
52
|
-
|
|
51
|
+
};
|
|
53
52
|
return subRoute;
|
|
54
53
|
})];
|
|
55
54
|
|
|
@@ -65,15 +64,48 @@ export const backend = {
|
|
|
65
64
|
throw new Error(`Backend route '${routeName}' does not exist.`);
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
let apiPath = route.path;
|
|
67
|
+
let apiPath: string | string[] = route.path;
|
|
68
|
+
|
|
69
|
+
if(Array.isArray(apiPath)){
|
|
70
|
+
const paramsLength = Object.keys(params).length;
|
|
71
|
+
if(paramsLength > 0){
|
|
72
|
+
for(const searchedPath of apiPath){
|
|
73
|
+
let foundParams = 0;
|
|
74
|
+
for(const p of Object.keys(params)){
|
|
75
|
+
if(searchedPath.indexOf(`:${p}`) !== -1){
|
|
76
|
+
foundParams++;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if(foundParams === paramsLength){
|
|
81
|
+
apiPath = searchedPath;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}else{
|
|
86
|
+
for(const searchedPath of apiPath){
|
|
87
|
+
if(!searchedPath.includes(':')){
|
|
88
|
+
apiPath = searchedPath;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
69
94
|
|
|
70
95
|
Object.keys(params).forEach((paramKey: string) => {
|
|
71
96
|
const paramValue = params[paramKey];
|
|
72
97
|
|
|
73
|
-
apiPath = apiPath.replace(`:${paramKey}`, paramValue);
|
|
74
|
-
});
|
|
98
|
+
apiPath = (apiPath as string).replace(`:${paramKey}`, paramValue);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
let finalUrl = `${config.get('backendUrl')}${config.get('apiPrefix') || ''}${apiPath}`;
|
|
102
|
+
|
|
103
|
+
if(Object.keys(queryParams).length > 0){
|
|
104
|
+
const queryString = new URLSearchParams(queryParams).toString();
|
|
105
|
+
finalUrl += `?${queryString}`;
|
|
106
|
+
}
|
|
75
107
|
|
|
76
|
-
return
|
|
108
|
+
return finalUrl;
|
|
77
109
|
},
|
|
78
110
|
checkPrefixedRouteName(routeName: string, prefixName: string){
|
|
79
111
|
let finalRoute = routeName;
|