@hashrytech/quick-components-kit 0.15.6 → 0.15.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @hashrytech/quick-components-kit
2
2
 
3
+ ## 0.15.7
4
+
5
+ ### Patch Changes
6
+
7
+ - refactor: uploadFileWithProgress updated
8
+
3
9
  ## 0.15.6
4
10
 
5
11
  ### Patch Changes
@@ -241,7 +241,7 @@ export declare class FetchClient {
241
241
  * @returns A Promise resolving to the typed response from the server.
242
242
  * @template T - Expected shape of the server's JSON response.
243
243
  */
244
- uploadFileWithProgress<T>(endpoint: string, file: File | Blob, onProgress: (percent: number) => void, fieldName?: string, options?: RequestOptions): Promise<T>;
244
+ uploadFileWithProgress<T>(endpoint: string, data: FormData, method?: "POST" | "PATCH", onProgress?: (percent: number) => void, options?: RequestOptions): Promise<T>;
245
245
  /**
246
246
  * Downloads a file from the specified endpoint while reporting progress.
247
247
  *
@@ -399,10 +399,9 @@ export class FetchClient {
399
399
  * @returns A Promise resolving to the typed response from the server.
400
400
  * @template T - Expected shape of the server's JSON response.
401
401
  */
402
- async uploadFileWithProgress(endpoint, file, onProgress, fieldName = 'file', options = {}) {
403
- const url = new URL(endpoint, this.baseURL).toString();
404
- const formData = new FormData();
405
- formData.append(fieldName, file);
402
+ async uploadFileWithProgress(endpoint, data, method = "POST", onProgress, options = {}) {
403
+ //const url = new URL(endpoint, this.baseURL).toString();
404
+ const url = this.baseURL ? new URL(endpoint, this.baseURL).toString() : endpoint; // Resolve endpoint relative to baseURL
406
405
  const token = this.accessToken;
407
406
  const headers = new Headers(this.defaultHeaders);
408
407
  // Merge user-supplied headers
@@ -412,7 +411,7 @@ export class FetchClient {
412
411
  }
413
412
  return new Promise((resolve, reject) => {
414
413
  const xhr = new XMLHttpRequest();
415
- xhr.open('POST', url, true);
414
+ xhr.open(method, url, true);
416
415
  // Add Authorization if not skipped
417
416
  if (!options.skipAuth && token) {
418
417
  xhr.setRequestHeader('Authorization', `Bearer ${token}`);
@@ -426,7 +425,7 @@ export class FetchClient {
426
425
  });
427
426
  xhr.upload.onprogress = (event) => {
428
427
  if (event.lengthComputable) {
429
- onProgress(Math.round((event.loaded / event.total) * 100));
428
+ onProgress?.(Math.round((event.loaded / event.total) * 100));
430
429
  }
431
430
  };
432
431
  xhr.onload = () => {
@@ -451,7 +450,7 @@ export class FetchClient {
451
450
  }
452
451
  };
453
452
  xhr.onerror = () => reject(new Error('Upload failed'));
454
- xhr.send(formData);
453
+ xhr.send(data);
455
454
  });
456
455
  }
457
456
  /**
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/hashrytech/quick-components-kit.git"
7
7
  },
8
- "version": "0.15.6",
8
+ "version": "0.15.7",
9
9
  "license": "MIT",
10
10
  "author": "Hashry Tech",
11
11
  "files": [