@rws-framework/client 2.22.0 → 2.23.0

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.
@@ -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
- routes = [...routes, ...item.routes.map((subRouteItem: IHTTProute): IHTTProute => {
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 `${config.get('backendUrl')}${config.get('apiPrefix') || ''}${apiPath}`;
108
+ return finalUrl;
77
109
  },
78
110
  checkPrefixedRouteName(routeName: string, prefixName: string){
79
111
  let finalRoute = routeName;
@@ -1,9 +1,9 @@
1
- import { ViewTemplate } from '@microsoft/fast-element';
1
+ import { FASTElement, ViewTemplate } from '@microsoft/fast-element';
2
2
  import { DOMOutputType } from '../services/DOMService';
3
3
 
4
4
  type IAssetShowOptions = Record<string, any>;
5
5
 
6
- interface IRWSViewComponent extends Node {
6
+ interface IRWSViewComponent extends FASTElement {
7
7
  __isLoading: boolean;
8
8
  routeParams: Record<string, string>;
9
9
  trashIterator: number;
@@ -1,12 +0,0 @@
1
- export interface IKDBTypeInfo {
2
- fieldName: string;
3
- type: string;
4
- boundModel?: string
5
- }
6
-
7
- export interface IKDBTypesResponse {
8
- success: boolean;
9
- data: {
10
- types: IKDBTypeInfo[];
11
- };
12
- }
@@ -1,5 +0,0 @@
1
- export interface IRWSResourceQuery {
2
- fieldName: string,
3
- type: String,
4
- boundModel: string
5
- }
@@ -1,5 +0,0 @@
1
- export interface IReFormerField {
2
- name: string,
3
- defaultValue?: any,
4
- setForm: (field: string, value: any) => Promise<void>
5
- }