@sparkvault/sdk-js 11.0.1 → 11.0.2

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.d.ts CHANGED
@@ -158,6 +158,14 @@ declare class HttpClient {
158
158
  private getAccessToken;
159
159
  request<T = unknown>(path: ApiPath, options?: RequestOptions): Promise<ApiResponse<T>>;
160
160
  private parseResponse;
161
+ /**
162
+ * The SDK error for a failed answer, typed by its status: the gates a host
163
+ * page branches on get their own class, and every other answer is the base
164
+ * error under the service's own code. Each carries the answer's
165
+ * `Retry-After` (`retryAfterMs`), the floor for whoever retries it — the
166
+ * SDK's own transfers when the answer is a download link's mint, and the
167
+ * host page otherwise.
168
+ */
161
169
  private createErrorFromResponse;
162
170
  private unwrapApiResponse;
163
171
  /**
@@ -364,16 +372,24 @@ declare class SparkVaultError extends Error {
364
372
  readonly code: string;
365
373
  readonly statusCode?: number;
366
374
  readonly details?: Record<string, unknown>;
367
- constructor(message: string, code: string, statusCode?: number, details?: Record<string, unknown>);
375
+ /**
376
+ * The answer's `Retry-After`, in ms from the answer, read as the platform's
377
+ * transfer policy reads it (RFC 9110 §10.2.3: delay-seconds or an
378
+ * HTTP-date): the earliest a next attempt can expect another answer, which
379
+ * every retry the SDK makes waits out as a floor. Null when the answer
380
+ * carried none the policy could read, or no answer arrived.
381
+ */
382
+ readonly retryAfterMs: number | null;
383
+ constructor(message: string, code: string, statusCode?: number, details?: Record<string, unknown>, retryAfterMs?: number | null);
368
384
  }
369
385
  declare class AuthenticationError extends SparkVaultError {
370
- constructor(message: string, details?: Record<string, unknown>);
386
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
371
387
  }
372
388
  declare class AuthorizationError extends SparkVaultError {
373
- constructor(message: string, details?: Record<string, unknown>);
389
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
374
390
  }
375
391
  declare class ValidationError extends SparkVaultError {
376
- constructor(message: string, details?: Record<string, unknown>);
392
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
377
393
  }
378
394
  /**
379
395
  * The pooled-capacity resource a quota gate refers to. Only the byte pools
@@ -388,7 +404,7 @@ type QuotaResource = 'storage' | 'bandwidth';
388
404
  * to admins, or "ask your account admin" to members.
389
405
  */
390
406
  declare class PlanRequiredError extends SparkVaultError {
391
- constructor(message: string, details?: Record<string, unknown>);
407
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
392
408
  }
393
409
  /**
394
410
  * Quota exceeded gate (402 QUOTA_EXCEEDED) — a pooled-capacity limit is
@@ -397,7 +413,7 @@ declare class PlanRequiredError extends SparkVaultError {
397
413
  */
398
414
  declare class QuotaExceededError extends SparkVaultError {
399
415
  readonly resource?: QuotaResource;
400
- constructor(message: string, details?: Record<string, unknown>);
416
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
401
417
  }
402
418
  /**
403
419
  * Notify subscription gate (403 NOTIFY_SUBSCRIPTION_REQUIRED) — the account has
@@ -406,7 +422,7 @@ declare class QuotaExceededError extends SparkVaultError {
406
422
  * nothing, so surface a subscribe CTA rather than a sign-in prompt.
407
423
  */
408
424
  declare class NotifySubscriptionRequiredError extends SparkVaultError {
409
- constructor(message: string, details?: Record<string, unknown>);
425
+ constructor(message: string, details?: Record<string, unknown>, retryAfterMs?: number | null);
410
426
  }
411
427
  declare class NetworkError extends SparkVaultError {
412
428
  constructor(message: string, details?: Record<string, unknown>);
@@ -2616,14 +2632,21 @@ interface HashCheckResponse {
2616
2632
 
2617
2633
  /**
2618
2634
  * The one browser transfer for a signed ingot download link: fetch it into a
2619
- * Blob under liveness bounds. `sv.ingots.download` uses it, and so can a caller
2635
+ * Blob under liveness bounds, resuming from the bytes it holds when the caller
2636
+ * can mint another link. `sv.ingots.download` uses it, and so can a caller
2620
2637
  * that mints its own link (`createDownloadLink`, or its own authenticated
2621
- * call) and needs cancellation, byte progress or the published revision.
2638
+ * call) and needs cancellation, byte progress, resumption or the published
2639
+ * revision.
2622
2640
  */
2623
2641
  interface FetchDownloadOptions {
2624
- /** Cancels the transfer; the returned promise rejects with the signal's reason. */
2642
+ /** Cancels the transfer, a wait between attempts included; the returned promise rejects with the signal's reason. */
2625
2643
  signal?: AbortSignal;
2626
- /** Bytes received so far and the declared length (0 when the server declared none). */
2644
+ /**
2645
+ * Bytes received so far and the file's declared length (0 when the server
2646
+ * declared none). A resumed transfer counts the bytes it already held; one
2647
+ * that has to start over (the file was replaced meanwhile, or the server
2648
+ * named nothing to resume against) counts from 0 again.
2649
+ */
2627
2650
  onProgress?: (loaded: number, total: number) => void;
2628
2651
  /**
2629
2652
  * The published revision the caller read. A response naming another one is
@@ -2634,9 +2657,25 @@ interface FetchDownloadOptions {
2634
2657
  /**
2635
2658
  * The hosts a download link may name (handed the lowercased host name);
2636
2659
  * SparkVault's own hosts when omitted. `sv.ingots.download` passes the
2637
- * client's `allowedDownloadHostPatterns`.
2660
+ * client's `allowedDownloadHostPatterns`. A minted link is held to it too.
2638
2661
  */
2639
2662
  isAllowedHost?: (hostname: string) => boolean;
2663
+ /**
2664
+ * Mints a fresh download link for the same ingot, resolving to its URL. A
2665
+ * link is single-use: Forge claims it the moment the request arrives, so a
2666
+ * second fetch answers 401 even after a first whose answer never came back.
2667
+ * Given this, a failed transfer is retried under the platform's transfer
2668
+ * policy (`@sparkvault/app-sdk/transfer-retry`) on a link minted first:
2669
+ * from the first byte it lacks (`Range`, conditioned by `If-Range` on the
2670
+ * publication's ETag) once bytes have arrived from a response that named a
2671
+ * strong ETag and `Accept-Ranges: bytes`, and from the first byte otherwise.
2672
+ * A mint that rejects with a `SparkVaultError` is read by its `statusCode`
2673
+ * and `retryAfterMs` as a transfer answer is, so a mint the server refuses
2674
+ * ends the download and one it throttles is retried no sooner than its
2675
+ * `Retry-After`; any other rejection is taken for a request that got no
2676
+ * answer, and retried. Without it, any failure is final.
2677
+ */
2678
+ remint?: () => Promise<string>;
2640
2679
  }
2641
2680
  interface FetchedDownload {
2642
2681
  blob: Blob;
@@ -2645,11 +2684,12 @@ interface FetchedDownload {
2645
2684
  }
2646
2685
  /**
2647
2686
  * Fetch a signed download URL as a Blob under liveness bounds: one deadline
2648
- * for the response headers, then an idle deadline rearmed on every body chunk.
2649
- * Nothing caps the transfer as a whole, so file size never decides whether a
2650
- * download can finish. The link is single-use: a caller that retries mints a
2651
- * fresh one first. A link that is not a Forge decrypt URL on an allowed host is
2652
- * refused before anything is sent (assertDownloadUrl).
2687
+ * for each response's headers, then an idle deadline rearmed on every body
2688
+ * chunk. Nothing caps the transfer as a whole, so file size never decides
2689
+ * whether a download can finish. The link is single-use, so a failed transfer
2690
+ * is retried only through `options.remint`, on a link minted for the retry. A
2691
+ * link that is not a Forge decrypt URL on an allowed host, the first or a
2692
+ * minted one, is refused before anything is sent to it (assertDownloadUrl).
2653
2693
  */
2654
2694
  declare function fetchDownload(url: string, options?: FetchDownloadOptions): Promise<FetchedDownload>;
2655
2695
 
@@ -2691,6 +2731,18 @@ declare class IngotsModule {
2691
2731
  * published, so a resolved promise never stands for a stored file whose
2692
2732
  * ingot never went live.
2693
2733
  *
2734
+ * Transient failures are retried inside the transfer; a session the server
2735
+ * no longer holds (it expired, was cancelled, or its ingot was removed)
2736
+ * rejects with code `session_gone`, and only a new upload session — a new
2737
+ * {@link createUpload}, or {@link upload} again — can store the file. An
2738
+ * upload the server refused for good (the account's storage pool cannot
2739
+ * take it, or a later upload replaced it) rejects with code
2740
+ * `upload_refused`, its message the server's own sentence and its code in
2741
+ * `details.coreCode`: a new upload is no remedy. A publication the server
2742
+ * still defers at the transfer's idle limit rejects with code
2743
+ * `upload_received_publishing`: every byte is received, and the server
2744
+ * finishes the publication on its own, so never upload the file again.
2745
+ *
2694
2746
  * @param options.signal - Cancels this transfer (it rejects with code
2695
2747
  * `cancelled`); other transfers carry on.
2696
2748
  * @param options.onProgress - Bytes sent so far and the file size; never runs backwards.
@@ -2775,24 +2827,32 @@ declare class IngotsModule {
2775
2827
  * Create a signed download link for an ingot (discrete primitive).
2776
2828
  *
2777
2829
  * Validates the returned URL against the download-host allowlist. Use this
2778
- * when you want the URL itself; otherwise prefer {@link download}.
2830
+ * when you want the URL itself; otherwise prefer {@link download}. The link
2831
+ * is single-use: Forge claims it the moment a request arrives, so a retry or
2832
+ * a resume needs a link of its own (`fetchDownload`'s `remint`).
2779
2833
  *
2780
2834
  * @example
2781
2835
  * const link = await sv.ingots.createDownloadLink(unsealed, 'ing_abc');
2782
- * window.location.href = link.downloadUrl;
2836
+ * const { blob } = await fetchDownload(link.downloadUrl, {
2837
+ * remint: async () => (await sv.ingots.createDownloadLink(unsealed, 'ing_abc')).downloadUrl,
2838
+ * });
2783
2839
  */
2784
2840
  createDownloadLink(vault: UnsealedVault, ingotId: string): Promise<IngotDownloadLink>;
2785
2841
  /**
2786
2842
  * Download an ingot as a Blob (high-level flow).
2787
2843
  *
2788
- * Requests a fresh signed link on every attempt (server URLs are
2789
- * short-lived) and retries transient transport failures with exponential
2790
- * backoff. Validation failures (bad host, non-HTTPS) are never retried.
2791
- *
2792
- * Each attempt is bounded by liveness, never by total duration: a deadline
2793
- * on the response headers, then an idle deadline rearmed on every body
2794
- * chunk. A stalled transfer restarts from byte zero: this path requests no
2795
- * byte range, so a full retry is the only recovery.
2844
+ * Every attempt fetches a signed link minted for it ({@link createDownloadLink}:
2845
+ * a link is single-use), under liveness bounds, never a cap on total
2846
+ * duration: a deadline on the response headers, then an idle deadline
2847
+ * rearmed on every body chunk. A failure the platform's transfer policy
2848
+ * retries (`@sparkvault/app-sdk/transfer-retry`: no answer, 408, 425, 429 or
2849
+ * a 5xx, a mint's included) is retried after the policy's backoff, never
2850
+ * sooner than `Retry-After`, until its budget ends. Once bytes have arrived
2851
+ * the retry resumes from the first byte it lacks, conditioned on the
2852
+ * publication's ETag (`If-Range`), so a stall at 90% fetches only the rest;
2853
+ * a file replaced meanwhile starts over as its new content, and one served
2854
+ * with no strong ETag starts over from its first byte. Any other refusal,
2855
+ * and a link that is not a Forge decrypt URL on an allowed host, is final.
2796
2856
  *
2797
2857
  * @example
2798
2858
  * const blob = await sv.ingots.download(unsealed, 'ing_abc');