@rws-framework/client 2.26.0 → 2.26.2
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.
|
@@ -7,7 +7,7 @@ const packageNames = [
|
|
|
7
7
|
];
|
|
8
8
|
|
|
9
9
|
async function loadAliases(packageDir, tsConfig, nodeModulesPath, executionDir){
|
|
10
|
-
|
|
10
|
+
console.log({packageDir, tsConfig, nodeModulesPath, executionDir})
|
|
11
11
|
const tsPaths = {}
|
|
12
12
|
|
|
13
13
|
for(const aliasKey of Object.keys(tsConfig.config.compilerOptions.paths)){
|
|
@@ -18,16 +18,10 @@ async function loadAliases(packageDir, tsConfig, nodeModulesPath, executionDir){
|
|
|
18
18
|
for(const pkgName of packageNames){
|
|
19
19
|
const symlinkPath = path.join(nodeModulesPath, '@rws-framework', pkgName);
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
const pkgDirStat = fs.lstatSync(symlinkPath);
|
|
23
|
-
|
|
24
|
-
if(pkgDirStat.isSymbolicLink()){
|
|
25
|
-
const targetPath = await fs.promises.realpath(symlinkPath);
|
|
21
|
+
const targetPath = await fs.promises.realpath(symlinkPath);
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
}
|
|
23
|
+
tsPaths['@rws-framework/' + pkgName + '/*'] = targetPath + '/*';
|
|
24
|
+
tsPaths['@rws-framework/' + pkgName] = targetPath + '/src/index.ts';
|
|
31
25
|
}
|
|
32
26
|
|
|
33
27
|
return {
|
package/package.json
CHANGED
|
@@ -18,22 +18,22 @@ interface IAPIOptions {
|
|
|
18
18
|
headers?: Headers,
|
|
19
19
|
routeParams?: {
|
|
20
20
|
[key: string]: string
|
|
21
|
-
},
|
|
21
|
+
},
|
|
22
22
|
queryParams?: {
|
|
23
23
|
[key: string]: string
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
interface IHTTProute<P = {[key: string]: any}> {
|
|
27
|
+
interface IHTTProute<P = { [key: string]: any }> {
|
|
28
28
|
name: string;
|
|
29
|
-
path: string | string[];
|
|
29
|
+
path: string | string[];
|
|
30
30
|
method: string;
|
|
31
31
|
noParams?: boolean;
|
|
32
32
|
options?: any;
|
|
33
33
|
plugins?: P
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
interface IPrefixedHTTProutes<P = {[key: string]: any}> {
|
|
36
|
+
interface IPrefixedHTTProutes<P = { [key: string]: any }> {
|
|
37
37
|
prefix: string;
|
|
38
38
|
controllerName: string;
|
|
39
39
|
exportAutoRoutes?: boolean,
|
|
@@ -49,16 +49,9 @@ interface UploadFunctionOptions {
|
|
|
49
49
|
onProgress?: (progress: number) => void;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
interface UploadResponse {
|
|
53
|
-
success: boolean;
|
|
54
|
-
data?: any;
|
|
55
|
-
error?: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
52
|
class ApiService extends TheService {
|
|
60
53
|
static _DEFAULT: boolean = true;
|
|
61
|
-
public token?: string;
|
|
54
|
+
public token?: string;
|
|
62
55
|
|
|
63
56
|
private defaultUploadOptions: () => UploadFunctionOptions = () => ({
|
|
64
57
|
headers: this.token ? { Authorization: `Bearer ${this.token}` } : {},
|
|
@@ -67,76 +60,65 @@ class ApiService extends TheService {
|
|
|
67
60
|
});
|
|
68
61
|
|
|
69
62
|
constructor(@ConfigService public config: ConfigServiceInstance) {
|
|
70
|
-
super();
|
|
63
|
+
super();
|
|
71
64
|
}
|
|
72
65
|
|
|
73
|
-
public setToken(token: string)
|
|
74
|
-
{
|
|
66
|
+
public setToken(token: string) {
|
|
75
67
|
this.token = token;
|
|
76
68
|
}
|
|
77
69
|
|
|
78
|
-
|
|
70
|
+
|
|
79
71
|
|
|
80
72
|
public async isGetTargetReachable(url: string, options: IAPIOptions = {}): Promise<boolean> {
|
|
81
|
-
try {
|
|
73
|
+
try {
|
|
82
74
|
return !!(await calls.pureGet.bind(this)(url, options));
|
|
83
75
|
} catch (error) {
|
|
84
76
|
return false;
|
|
85
77
|
}
|
|
86
|
-
}
|
|
78
|
+
}
|
|
87
79
|
|
|
88
|
-
async
|
|
89
|
-
{
|
|
80
|
+
async uploadFiles<T = any, P = any>(url: string, files: Record<string, File>, payload: P = undefined, uploadOptions: UploadFunctionOptions = this.defaultUploadOptions()): Promise<T> {
|
|
90
81
|
const formData = new FormData();
|
|
91
|
-
|
|
82
|
+
|
|
92
83
|
// Add files to FormData
|
|
93
84
|
Object.entries(files).forEach(([key, file]) => {
|
|
94
85
|
formData.append(key, file);
|
|
95
86
|
});
|
|
96
|
-
|
|
87
|
+
|
|
97
88
|
// Add payload data to FormData
|
|
98
|
-
|
|
89
|
+
if(payload){
|
|
90
|
+
Object.entries(payload).forEach(([key, value]) => {
|
|
99
91
|
if (value !== undefined && value !== null) {
|
|
100
92
|
formData.append(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
|
|
101
93
|
}
|
|
102
94
|
});
|
|
103
|
-
|
|
95
|
+
}
|
|
96
|
+
|
|
104
97
|
const options = {
|
|
105
98
|
...this.defaultUploadOptions(),
|
|
106
99
|
...uploadOptions
|
|
107
100
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
const method = options.method || 'POST';
|
|
104
|
+
|
|
105
|
+
const axiosConfig = {
|
|
106
|
+
method: method.toLowerCase() as any,
|
|
107
|
+
url,
|
|
108
|
+
data: formData,
|
|
109
|
+
headers: {
|
|
110
|
+
'Content-Type': 'multipart/form-data',
|
|
111
|
+
...options.headers
|
|
112
|
+
},
|
|
113
|
+
onUploadProgress: (progressEvent: any) => {
|
|
114
|
+
if (options.onProgress && progressEvent.total) {
|
|
115
|
+
const progress = Math.round((progressEvent.loaded * 100) / progressEvent.total);
|
|
116
|
+
options.onProgress(progress);
|
|
125
117
|
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
success: true,
|
|
132
|
-
data: result.data
|
|
133
|
-
};
|
|
134
|
-
} catch (error: any) {
|
|
135
|
-
return {
|
|
136
|
-
success: false,
|
|
137
|
-
error: error.response?.data?.message || error.message || 'Upload failed'
|
|
138
|
-
};
|
|
139
|
-
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return (await axios(axiosConfig)).data;
|
|
140
122
|
}
|
|
141
123
|
|
|
142
124
|
public pureGet = calls.pureGet;
|
|
@@ -150,15 +132,14 @@ class ApiService extends TheService {
|
|
|
150
132
|
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>,
|
|
151
133
|
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>,
|
|
152
134
|
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>,
|
|
153
|
-
|
|
135
|
+
uploadFiles: async <T = any, P = any>(routeName: string, files: Record<string, File>, payload: P = undefined, uploadOptions: UploadFunctionOptions = this.defaultUploadOptions(), options: IAPIOptions = {}): Promise<T> => this.uploadFiles<T, P>(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), files, payload, uploadOptions),
|
|
154
136
|
};
|
|
155
137
|
|
|
156
|
-
async getResource(resourceName: string): Promise<ITypesResponse>
|
|
157
|
-
{
|
|
138
|
+
async getResource(resourceName: string): Promise<ITypesResponse> {
|
|
158
139
|
return calls.get.bind(this)(`${this.config.get('backendUrl')}${this.config.get('apiPrefix') || ''}/api/rws/resource/${resourceName}`) as Promise<ITypesResponse>
|
|
159
140
|
}
|
|
160
141
|
|
|
161
|
-
getBackendUrl: (routeName: string, params?: {[key: string]: string}, queryParams?: {[key: string]: string}) => string = backend.getBackendUrl.bind(this);
|
|
142
|
+
getBackendUrl: (routeName: string, params?: { [key: string]: string }, queryParams?: { [key: string]: string }) => string = backend.getBackendUrl.bind(this);
|
|
162
143
|
}
|
|
163
144
|
|
|
164
145
|
export default ApiService.getSingleton();
|