@spacelr/sdk 0.19.2 → 0.19.3

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/dist/index.js CHANGED
@@ -2711,6 +2711,19 @@ var AuthModule = class _AuthModule {
2711
2711
  };
2712
2712
 
2713
2713
  // libs/sdk/src/modules/storage.module.ts
2714
+ var THROTTLE_RETRY_MS = 6e4;
2715
+ var THROTTLE_MAX_RETRIES = 2;
2716
+ async function retryThrottled(call) {
2717
+ for (let attempt = 0; ; attempt++) {
2718
+ try {
2719
+ return await call();
2720
+ } catch (error) {
2721
+ const throttled = error instanceof SpacelrError && error.statusCode === 429;
2722
+ if (!throttled || attempt >= THROTTLE_MAX_RETRIES) throw error;
2723
+ await new Promise((resolve) => setTimeout(resolve, THROTTLE_RETRY_MS));
2724
+ }
2725
+ }
2726
+ }
2714
2727
  var StorageModule = class {
2715
2728
  constructor(http, tokenManager, config) {
2716
2729
  this.http = http;
@@ -2780,10 +2793,12 @@ var StorageModule = class {
2780
2793
  percentage: fileSize > 0 ? Math.min(100, Math.round(totalLoaded / fileSize * 100)) : 0
2781
2794
  });
2782
2795
  } : void 0;
2783
- const result = await this.http.uploadForm(
2784
- `/storage/files/${fileId}/multipart/upload-part`,
2785
- formData,
2786
- partProgress
2796
+ const result = await retryThrottled(
2797
+ () => this.http.uploadForm(
2798
+ `/storage/files/${fileId}/multipart/upload-part`,
2799
+ formData,
2800
+ partProgress
2801
+ )
2787
2802
  );
2788
2803
  partProgressMap.delete(partNumber);
2789
2804
  completedBytes += chunkSize;
@@ -2803,11 +2818,10 @@ var StorageModule = class {
2803
2818
  partProgressMap.clear();
2804
2819
  }
2805
2820
  completedParts.sort((a, b) => a.partNumber - b.partNumber);
2806
- await this.completeMultipartUpload(fileId, completedParts);
2807
- return this.getFileInfo(fileId);
2821
+ return await retryThrottled(() => this.completeMultipartUpload(fileId, completedParts));
2808
2822
  } catch (error) {
2809
2823
  try {
2810
- await this.abortMultipartUpload(fileId);
2824
+ await retryThrottled(() => this.abortMultipartUpload(fileId));
2811
2825
  } catch {
2812
2826
  }
2813
2827
  throw error;