@spacelr/sdk 0.19.2 → 0.19.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.
package/dist/index.mjs CHANGED
@@ -577,16 +577,20 @@ var TokenManager = class {
577
577
  * gateway) surfaced as `SpacelrNetworkError`/`SpacelrTimeoutError` (#759);
578
578
  * - a 5xx server response — e.g. a 503 the gateway returns when oauth-service
579
579
  * is momentarily down (#760/#762) — which is retryable infrastructure, not
580
- * a token rejection.
581
- * A real auth rejection (401/invalid_grant) or any other non-5xx server error
582
- * is NOT transient and is treated as a server-confirmed loss.
580
+ * a token rejection;
581
+ * - a 429 or 408 (#1080) — the rate limit is per IP, so it is shared by
582
+ * everyone behind one NAT, and a 408 never completed. Neither judged the
583
+ * refresh token.
584
+ * A real auth rejection (401/invalid_grant) or any other 4xx server error is
585
+ * NOT transient and is treated as a server-confirmed loss.
583
586
  */
584
587
  isTransientTransportError(error) {
585
588
  if (error instanceof SpacelrNetworkError || error instanceof SpacelrTimeoutError) {
586
589
  return true;
587
590
  }
588
591
  if (error instanceof SpacelrError && typeof error.statusCode === "number") {
589
- return error.statusCode >= 500 && error.statusCode <= 599;
592
+ const status = error.statusCode;
593
+ return status === 429 || status === 408 || status >= 500 && status <= 599;
590
594
  }
591
595
  return false;
592
596
  }
@@ -2664,6 +2668,19 @@ var AuthModule = class _AuthModule {
2664
2668
  };
2665
2669
 
2666
2670
  // libs/sdk/src/modules/storage.module.ts
2671
+ var THROTTLE_RETRY_MS = 6e4;
2672
+ var THROTTLE_MAX_RETRIES = 2;
2673
+ async function retryThrottled(call) {
2674
+ for (let attempt = 0; ; attempt++) {
2675
+ try {
2676
+ return await call();
2677
+ } catch (error) {
2678
+ const throttled = error instanceof SpacelrError && error.statusCode === 429;
2679
+ if (!throttled || attempt >= THROTTLE_MAX_RETRIES) throw error;
2680
+ await new Promise((resolve) => setTimeout(resolve, THROTTLE_RETRY_MS));
2681
+ }
2682
+ }
2683
+ }
2667
2684
  var StorageModule = class {
2668
2685
  constructor(http, tokenManager, config) {
2669
2686
  this.http = http;
@@ -2733,10 +2750,12 @@ var StorageModule = class {
2733
2750
  percentage: fileSize > 0 ? Math.min(100, Math.round(totalLoaded / fileSize * 100)) : 0
2734
2751
  });
2735
2752
  } : void 0;
2736
- const result = await this.http.uploadForm(
2737
- `/storage/files/${fileId}/multipart/upload-part`,
2738
- formData,
2739
- partProgress
2753
+ const result = await retryThrottled(
2754
+ () => this.http.uploadForm(
2755
+ `/storage/files/${fileId}/multipart/upload-part`,
2756
+ formData,
2757
+ partProgress
2758
+ )
2740
2759
  );
2741
2760
  partProgressMap.delete(partNumber);
2742
2761
  completedBytes += chunkSize;
@@ -2756,11 +2775,10 @@ var StorageModule = class {
2756
2775
  partProgressMap.clear();
2757
2776
  }
2758
2777
  completedParts.sort((a, b) => a.partNumber - b.partNumber);
2759
- await this.completeMultipartUpload(fileId, completedParts);
2760
- return this.getFileInfo(fileId);
2778
+ return await retryThrottled(() => this.completeMultipartUpload(fileId, completedParts));
2761
2779
  } catch (error) {
2762
2780
  try {
2763
- await this.abortMultipartUpload(fileId);
2781
+ await retryThrottled(() => this.abortMultipartUpload(fileId));
2764
2782
  } catch {
2765
2783
  }
2766
2784
  throw error;