whio-api-sdk 1.1.3 → 1.1.4
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.
|
@@ -44,14 +44,9 @@ export class BaseClient {
|
|
|
44
44
|
}
|
|
45
45
|
fetchConfig(url) {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.baseUrl = conf.baseUrl || this.baseUrl;
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
throw new Error(`Failed to fetch config from ${url}`);
|
|
54
|
-
}
|
|
47
|
+
const response = yield axios.get(url);
|
|
48
|
+
const conf = response.data;
|
|
49
|
+
this.baseUrl = conf.baseUrl || this.baseUrl;
|
|
55
50
|
});
|
|
56
51
|
}
|
|
57
52
|
getToken() {
|
|
@@ -72,7 +67,6 @@ export class BaseClient {
|
|
|
72
67
|
});
|
|
73
68
|
}
|
|
74
69
|
request(endpoint, method = 'GET', body, headers = {}, noToken = false) {
|
|
75
|
-
var _a, _b, _c;
|
|
76
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
71
|
const url = `${this.baseUrl}${endpoint}`;
|
|
78
72
|
const defaultHeaders = {
|
|
@@ -85,22 +79,14 @@ export class BaseClient {
|
|
|
85
79
|
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
86
80
|
}
|
|
87
81
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return response.data;
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
const axiosError = error;
|
|
100
|
-
const errorMessage = ((_b = (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) ||
|
|
101
|
-
`Request failed with status ${((_c = axiosError.response) === null || _c === void 0 ? void 0 : _c.status) || 'unknown'}`;
|
|
102
|
-
throw new Error(errorMessage);
|
|
103
|
-
}
|
|
82
|
+
const response = yield axios({
|
|
83
|
+
url,
|
|
84
|
+
method,
|
|
85
|
+
headers: Object.assign(Object.assign({}, defaultHeaders), headers),
|
|
86
|
+
data: body,
|
|
87
|
+
timeout: 5000,
|
|
88
|
+
});
|
|
89
|
+
return response.data;
|
|
104
90
|
});
|
|
105
91
|
}
|
|
106
92
|
fileUploadRequest(endpoint, body, headers = {}, onProgress) {
|
|
@@ -160,7 +146,6 @@ export class BaseClient {
|
|
|
160
146
|
});
|
|
161
147
|
}
|
|
162
148
|
downloadRequest(endpoint) {
|
|
163
|
-
var _a, _b, _c;
|
|
164
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
165
150
|
const url = `${this.baseUrl}${endpoint}`;
|
|
166
151
|
const defaultHeaders = {
|
|
@@ -170,25 +155,16 @@ export class BaseClient {
|
|
|
170
155
|
if (token) {
|
|
171
156
|
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
172
157
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return response.data;
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
const axiosError = error;
|
|
184
|
-
const errorMessage = ((_b = (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) ||
|
|
185
|
-
`Download failed with status ${((_c = axiosError.response) === null || _c === void 0 ? void 0 : _c.status) || 'unknown'}`;
|
|
186
|
-
throw new Error(errorMessage);
|
|
187
|
-
}
|
|
158
|
+
const response = yield axios({
|
|
159
|
+
url,
|
|
160
|
+
method: 'GET',
|
|
161
|
+
headers: defaultHeaders,
|
|
162
|
+
responseType: 'blob',
|
|
163
|
+
});
|
|
164
|
+
return response.data;
|
|
188
165
|
});
|
|
189
166
|
}
|
|
190
167
|
textRequest(endpoint) {
|
|
191
|
-
var _a, _b, _c;
|
|
192
168
|
return __awaiter(this, void 0, void 0, function* () {
|
|
193
169
|
const url = `${this.baseUrl}${endpoint}`;
|
|
194
170
|
const defaultHeaders = {
|
|
@@ -198,22 +174,14 @@ export class BaseClient {
|
|
|
198
174
|
if (token) {
|
|
199
175
|
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
200
176
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return response.data;
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
const axiosError = error;
|
|
213
|
-
const errorMessage = ((_b = (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) ||
|
|
214
|
-
`Text request failed with status ${((_c = axiosError.response) === null || _c === void 0 ? void 0 : _c.status) || 'unknown'}`;
|
|
215
|
-
throw new Error(errorMessage);
|
|
216
|
-
}
|
|
177
|
+
const response = yield axios({
|
|
178
|
+
url,
|
|
179
|
+
method: 'GET',
|
|
180
|
+
headers: defaultHeaders,
|
|
181
|
+
responseType: 'text',
|
|
182
|
+
timeout: 5000,
|
|
183
|
+
});
|
|
184
|
+
return response.data;
|
|
217
185
|
});
|
|
218
186
|
}
|
|
219
187
|
clearAuth() {
|
package/package.json
CHANGED
|
@@ -39,13 +39,9 @@ export class BaseClient {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
public async fetchConfig(url: string): Promise<void> {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.baseUrl = conf.baseUrl || this.baseUrl;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
throw new Error(`Failed to fetch config from ${url}`);
|
|
48
|
-
}
|
|
42
|
+
const response = await axios.get(url);
|
|
43
|
+
const conf = response.data;
|
|
44
|
+
this.baseUrl = conf.baseUrl || this.baseUrl;
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
protected async getToken() {
|
|
@@ -84,22 +80,15 @@ export class BaseClient {
|
|
|
84
80
|
}
|
|
85
81
|
}
|
|
86
82
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
83
|
+
const response = await axios({
|
|
84
|
+
url,
|
|
85
|
+
method,
|
|
86
|
+
headers: { ...defaultHeaders, ...headers },
|
|
87
|
+
data: body,
|
|
88
|
+
timeout: 5000,
|
|
89
|
+
});
|
|
95
90
|
|
|
96
|
-
|
|
97
|
-
} catch (error) {
|
|
98
|
-
const axiosError = error as AxiosError<{ message?: string }>;
|
|
99
|
-
const errorMessage = axiosError.response?.data?.message ||
|
|
100
|
-
`Request failed with status ${axiosError.response?.status || 'unknown'}`;
|
|
101
|
-
throw new Error(errorMessage);
|
|
102
|
-
}
|
|
91
|
+
return response.data;
|
|
103
92
|
}
|
|
104
93
|
|
|
105
94
|
protected async fileUploadRequest<T>(
|
|
@@ -179,21 +168,14 @@ export class BaseClient {
|
|
|
179
168
|
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
180
169
|
}
|
|
181
170
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
});
|
|
171
|
+
const response = await axios({
|
|
172
|
+
url,
|
|
173
|
+
method: 'GET',
|
|
174
|
+
headers: defaultHeaders,
|
|
175
|
+
responseType: 'blob',
|
|
176
|
+
});
|
|
189
177
|
|
|
190
|
-
|
|
191
|
-
} catch (error) {
|
|
192
|
-
const axiosError = error as AxiosError<{ message?: string }>;
|
|
193
|
-
const errorMessage = axiosError.response?.data?.message ||
|
|
194
|
-
`Download failed with status ${axiosError.response?.status || 'unknown'}`;
|
|
195
|
-
throw new Error(errorMessage);
|
|
196
|
-
}
|
|
178
|
+
return response.data;
|
|
197
179
|
}
|
|
198
180
|
|
|
199
181
|
protected async textRequest(endpoint: string): Promise<string> {
|
|
@@ -208,22 +190,15 @@ export class BaseClient {
|
|
|
208
190
|
defaultHeaders['Authorization'] = `Bearer ${token}`;
|
|
209
191
|
}
|
|
210
192
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
});
|
|
193
|
+
const response = await axios({
|
|
194
|
+
url,
|
|
195
|
+
method: 'GET',
|
|
196
|
+
headers: defaultHeaders,
|
|
197
|
+
responseType: 'text',
|
|
198
|
+
timeout: 5000,
|
|
199
|
+
});
|
|
219
200
|
|
|
220
|
-
|
|
221
|
-
} catch (error) {
|
|
222
|
-
const axiosError = error as AxiosError<{ message?: string }>;
|
|
223
|
-
const errorMessage = axiosError.response?.data?.message ||
|
|
224
|
-
`Text request failed with status ${axiosError.response?.status || 'unknown'}`;
|
|
225
|
-
throw new Error(errorMessage);
|
|
226
|
-
}
|
|
201
|
+
return response.data;
|
|
227
202
|
}
|
|
228
203
|
|
|
229
204
|
protected async clearAuth(): Promise<void> {
|