@spacelr/sdk 0.19.1 → 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.mjs CHANGED
@@ -2664,6 +2664,19 @@ var AuthModule = class _AuthModule {
2664
2664
  };
2665
2665
 
2666
2666
  // libs/sdk/src/modules/storage.module.ts
2667
+ var THROTTLE_RETRY_MS = 6e4;
2668
+ var THROTTLE_MAX_RETRIES = 2;
2669
+ async function retryThrottled(call) {
2670
+ for (let attempt = 0; ; attempt++) {
2671
+ try {
2672
+ return await call();
2673
+ } catch (error) {
2674
+ const throttled = error instanceof SpacelrError && error.statusCode === 429;
2675
+ if (!throttled || attempt >= THROTTLE_MAX_RETRIES) throw error;
2676
+ await new Promise((resolve) => setTimeout(resolve, THROTTLE_RETRY_MS));
2677
+ }
2678
+ }
2679
+ }
2667
2680
  var StorageModule = class {
2668
2681
  constructor(http, tokenManager, config) {
2669
2682
  this.http = http;
@@ -2733,10 +2746,12 @@ var StorageModule = class {
2733
2746
  percentage: fileSize > 0 ? Math.min(100, Math.round(totalLoaded / fileSize * 100)) : 0
2734
2747
  });
2735
2748
  } : void 0;
2736
- const result = await this.http.uploadForm(
2737
- `/storage/files/${fileId}/multipart/upload-part`,
2738
- formData,
2739
- partProgress
2749
+ const result = await retryThrottled(
2750
+ () => this.http.uploadForm(
2751
+ `/storage/files/${fileId}/multipart/upload-part`,
2752
+ formData,
2753
+ partProgress
2754
+ )
2740
2755
  );
2741
2756
  partProgressMap.delete(partNumber);
2742
2757
  completedBytes += chunkSize;
@@ -2756,11 +2771,10 @@ var StorageModule = class {
2756
2771
  partProgressMap.clear();
2757
2772
  }
2758
2773
  completedParts.sort((a, b) => a.partNumber - b.partNumber);
2759
- await this.completeMultipartUpload(fileId, completedParts);
2760
- return this.getFileInfo(fileId);
2774
+ return await retryThrottled(() => this.completeMultipartUpload(fileId, completedParts));
2761
2775
  } catch (error) {
2762
2776
  try {
2763
- await this.abortMultipartUpload(fileId);
2777
+ await retryThrottled(() => this.abortMultipartUpload(fileId));
2764
2778
  } catch {
2765
2779
  }
2766
2780
  throw error;
@@ -4310,7 +4324,8 @@ var NotificationsModule = class _NotificationsModule {
4310
4324
  if (!stored) return;
4311
4325
  await this.deleteSubscription(
4312
4326
  stored.subscription.platform,
4313
- _NotificationsModule.identifierOf(stored.subscription)
4327
+ _NotificationsModule.identifierOf(stored.subscription),
4328
+ true
4314
4329
  ).catch(() => void 0);
4315
4330
  });
4316
4331
  let timer;
@@ -4327,7 +4342,7 @@ var NotificationsModule = class _NotificationsModule {
4327
4342
  this.pushQueue = run.catch(() => void 0);
4328
4343
  return run;
4329
4344
  }
4330
- deleteSubscription(platform, identifier) {
4345
+ deleteSubscription(platform, identifier, skipAuthRefresh = false) {
4331
4346
  const body = { platform };
4332
4347
  if (platform === "web") {
4333
4348
  body["endpoint"] = identifier;
@@ -4338,7 +4353,8 @@ var NotificationsModule = class _NotificationsModule {
4338
4353
  method: "DELETE",
4339
4354
  path: "/notifications/subscribe",
4340
4355
  body,
4341
- authenticated: true
4356
+ authenticated: true,
4357
+ skipAuthRefresh
4342
4358
  });
4343
4359
  }
4344
4360
  /** The value `unsubscribe()` identifies a subscription by: endpoint for web, token otherwise. */