kmod-cli 1.4.8 → 1.4.9

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.
@@ -217,16 +217,23 @@ class DataProvider {
217
217
  private options: Required<DataProviderOptions>;
218
218
 
219
219
  constructor(
220
- apiUrl: string,
221
- httpClient: AxiosInstance = axios,
220
+ httpClient: AxiosInstance = axios.create(),
222
221
  options: DataProviderOptions = {}
223
222
  ) {
224
- this.apiUrl = apiUrl.endsWith('/') ? apiUrl.slice(0, -1) : apiUrl;
225
223
  this.httpClient = httpClient;
224
+
225
+ // Lấy baseURL từ httpClient
226
+ const baseURL = httpClient.defaults.baseURL || '';
227
+ this.apiUrl = baseURL.endsWith('/') ? baseURL.slice(0, -1) : baseURL;
228
+
229
+ if (!this.apiUrl) {
230
+ console.warn('[DataProvider] No baseURL found in httpClient. Please set baseURL when creating httpClient.');
231
+ }
232
+
226
233
  this.cache = new Map();
227
234
  this.options = {
228
235
  cacheTime: 5 * 60 * 1000,
229
- retryCount: 3,
236
+ retryCount: 1,
230
237
  retryDelay: 1000,
231
238
  debug: false,
232
239
  ...options
@@ -653,11 +660,12 @@ class DataProvider {
653
660
  if (!url) throw this.handleError("No url provided");
654
661
  try {
655
662
  return await this.retryRequest(async () => {
656
- const fullUrl = url.startsWith('http') ? url : `${this.apiUrl}${url}`;
657
- this.log(`${method.toUpperCase()} ${fullUrl}`, { payload, query });
658
-
663
+ // if url is not absolute, assume it's a relative path
664
+ const requestUrl = url.startsWith('http') ? url : url;
665
+ this.log(`${method.toUpperCase()} ${requestUrl}`, { payload, query });
666
+
659
667
  const response = await this.httpClient<T>({
660
- url: fullUrl,
668
+ url: requestUrl,
661
669
  method,
662
670
  data: payload,
663
671
  params: query,
@@ -1199,7 +1207,7 @@ export const cookiesProvider = {
1199
1207
  // });
1200
1208
 
1201
1209
  // const { data, isLoading, error } = useCustom<DataResponse>({
1202
- // url: '/route_name',
1210
+ // url: '/route_name or api_url/route/...',
1203
1211
  // method: 'post',
1204
1212
  // payload: {},
1205
1213
  // });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kmod-cli",
3
- "version": "1.4.8",
3
+ "version": "1.4.9",
4
4
  "description": "Stack components utilities fast setup in projects",
5
5
  "author": "kumo_d",
6
6
  "license": "MIT",