@sparkvault/sdk-js 11.0.1 → 11.0.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.
@@ -1,13 +1,20 @@
1
1
  /**
2
2
  * The one browser transfer for a signed ingot download link: fetch it into a
3
- * Blob under liveness bounds. `sv.ingots.download` uses it, and so can a caller
3
+ * Blob under liveness bounds, resuming from the bytes it holds when the caller
4
+ * can mint another link. `sv.ingots.download` uses it, and so can a caller
4
5
  * that mints its own link (`createDownloadLink`, or its own authenticated
5
- * call) and needs cancellation, byte progress or the published revision.
6
+ * call) and needs cancellation, byte progress, resumption or the published
7
+ * revision.
6
8
  */
7
9
  export interface FetchDownloadOptions {
8
- /** Cancels the transfer; the returned promise rejects with the signal's reason. */
10
+ /** Cancels the transfer, a wait between attempts included; the returned promise rejects with the signal's reason. */
9
11
  signal?: AbortSignal;
10
- /** Bytes received so far and the declared length (0 when the server declared none). */
12
+ /**
13
+ * Bytes received so far and the file's declared length (0 when the server
14
+ * declared none). A resumed transfer counts the bytes it already held; one
15
+ * that has to start over (the file was replaced meanwhile, or the server
16
+ * named nothing to resume against) counts from 0 again.
17
+ */
11
18
  onProgress?: (loaded: number, total: number) => void;
12
19
  /**
13
20
  * The published revision the caller read. A response naming another one is
@@ -18,9 +25,25 @@ export interface FetchDownloadOptions {
18
25
  /**
19
26
  * The hosts a download link may name (handed the lowercased host name);
20
27
  * SparkVault's own hosts when omitted. `sv.ingots.download` passes the
21
- * client's `allowedDownloadHostPatterns`.
28
+ * client's `allowedDownloadHostPatterns`. A minted link is held to it too.
22
29
  */
23
30
  isAllowedHost?: (hostname: string) => boolean;
31
+ /**
32
+ * Mints a fresh download link for the same ingot, resolving to its URL. A
33
+ * link is single-use: Forge claims it the moment the request arrives, so a
34
+ * second fetch answers 401 even after a first whose answer never came back.
35
+ * Given this, a failed transfer is retried under the platform's transfer
36
+ * policy (`@sparkvault/app-sdk/transfer-retry`) on a link minted first:
37
+ * from the first byte it lacks (`Range`, conditioned by `If-Range` on the
38
+ * publication's ETag) once bytes have arrived from a response that named a
39
+ * strong ETag and `Accept-Ranges: bytes`, and from the first byte otherwise.
40
+ * A mint that rejects with a `SparkVaultError` is read by its `statusCode`
41
+ * and `retryAfterMs` as a transfer answer is, so a mint the server refuses
42
+ * ends the download and one it throttles is retried no sooner than its
43
+ * `Retry-After`; any other rejection is taken for a request that got no
44
+ * answer, and retried. Without it, any failure is final.
45
+ */
46
+ remint?: () => Promise<string>;
24
47
  }
25
48
  export interface FetchedDownload {
26
49
  blob: Blob;
@@ -39,10 +62,17 @@ export interface FetchedDownload {
39
62
  export declare function assertDownloadUrl(url: string, isAllowedHost?: (hostname: string) => boolean): void;
40
63
  /**
41
64
  * Fetch a signed download URL as a Blob under liveness bounds: one deadline
42
- * for the response headers, then an idle deadline rearmed on every body chunk.
43
- * Nothing caps the transfer as a whole, so file size never decides whether a
44
- * download can finish. The link is single-use: a caller that retries mints a
45
- * fresh one first. A link that is not a Forge decrypt URL on an allowed host is
46
- * refused before anything is sent (assertDownloadUrl).
65
+ * for each response's headers, then an idle deadline rearmed on every body
66
+ * chunk. Nothing caps the transfer as a whole, so file size never decides
67
+ * whether a download can finish. The link is single-use, so a failed transfer
68
+ * is retried only through `options.remint`, on a link minted for the retry. A
69
+ * link that is not a Forge decrypt URL on an allowed host, the first or a
70
+ * minted one, is refused before anything is sent to it (assertDownloadUrl).
47
71
  */
48
72
  export declare function fetchDownload(url: string, options?: FetchDownloadOptions): Promise<FetchedDownload>;
73
+ /**
74
+ * {@link fetchDownload} for a caller whose every link is minted, the first
75
+ * included: a mint that fails before any byte has moved is retried under the
76
+ * same policy as any other failure. `sv.ingots.download` runs this.
77
+ */
78
+ export declare function fetchMintedDownload(mint: () => Promise<string>, options?: Omit<FetchDownloadOptions, 'remint'>): Promise<FetchedDownload>;
@@ -21,7 +21,10 @@ export declare class IngotsModule {
21
21
  *
22
22
  * Reserves the ingot record and returns the Forge upload URL (carrying the
23
23
  * ISTK upload session token). Use this when you want to drive the TUS
24
- * transfer yourself; otherwise prefer {@link upload}.
24
+ * transfer yourself; otherwise prefer {@link upload}. A create another
25
+ * upload of the same file superseded before its token was issued rejects
26
+ * with code `upload_refused` (`details.coreCode` UPLOAD_SUPERSEDED): the
27
+ * later upload is the one kept, so a new upload is no remedy.
25
28
  *
26
29
  * @example
27
30
  * const session = await sv.ingots.createUpload({
@@ -38,6 +41,18 @@ export declare class IngotsModule {
38
41
  * published, so a resolved promise never stands for a stored file whose
39
42
  * ingot never went live.
40
43
  *
44
+ * Transient failures are retried inside the transfer; a session the server
45
+ * no longer holds (it expired, was cancelled, or its ingot was removed)
46
+ * rejects with code `session_gone`, and only a new upload session — a new
47
+ * {@link createUpload}, or {@link upload} again — can store the file. An
48
+ * upload the server refused for good (the account's storage pool cannot
49
+ * take it, or a later upload replaced it) rejects with code
50
+ * `upload_refused`, its message the server's own sentence and its code in
51
+ * `details.coreCode`: a new upload is no remedy. A publication the server
52
+ * still defers at the transfer's idle limit rejects with code
53
+ * `upload_received_publishing`: every byte is received, and the server
54
+ * finishes the publication on its own, so never upload the file again.
55
+ *
41
56
  * @param options.signal - Cancels this transfer (it rejects with code
42
57
  * `cancelled`); other transfers carry on.
43
58
  * @param options.onProgress - Bytes sent so far and the file size; never runs backwards.
@@ -52,7 +67,10 @@ export declare class IngotsModule {
52
67
  * Upload a file as a new ingot (high-level flow).
53
68
  *
54
69
  * Creates the upload session, streams the file to Forge over TUS, then
55
- * confirms the server finalized the upload before resolving.
70
+ * confirms the server finalized the upload before resolving. A file the
71
+ * server refused for good — another upload of it superseded this one, at
72
+ * its create or while it streamed, or the storage pool cannot take it —
73
+ * rejects with code `upload_refused`, as {@link sendUpload} does.
56
74
  *
57
75
  * @example
58
76
  * const ingot = await sv.ingots.upload(unsealed, {
@@ -61,7 +79,9 @@ export declare class IngotsModule {
61
79
  */
62
80
  upload(vault: UnsealedVault, options: UploadIngotOptions): Promise<CreatedIngot>;
63
81
  /**
64
- * Replace an existing ingot's content (high-level flow).
82
+ * Replace an existing ingot's content (high-level flow). Rejects as
83
+ * {@link upload} does, a replacement another upload of the same ingot
84
+ * superseded included (`upload_refused`).
65
85
  *
66
86
  * @example
67
87
  * await sv.ingots.replace(unsealed, 'ing_abc', { file: updatedFile });
@@ -122,24 +142,32 @@ export declare class IngotsModule {
122
142
  * Create a signed download link for an ingot (discrete primitive).
123
143
  *
124
144
  * Validates the returned URL against the download-host allowlist. Use this
125
- * when you want the URL itself; otherwise prefer {@link download}.
145
+ * when you want the URL itself; otherwise prefer {@link download}. The link
146
+ * is single-use: Forge claims it the moment a request arrives, so a retry or
147
+ * a resume needs a link of its own (`fetchDownload`'s `remint`).
126
148
  *
127
149
  * @example
128
150
  * const link = await sv.ingots.createDownloadLink(unsealed, 'ing_abc');
129
- * window.location.href = link.downloadUrl;
151
+ * const { blob } = await fetchDownload(link.downloadUrl, {
152
+ * remint: async () => (await sv.ingots.createDownloadLink(unsealed, 'ing_abc')).downloadUrl,
153
+ * });
130
154
  */
131
155
  createDownloadLink(vault: UnsealedVault, ingotId: string): Promise<IngotDownloadLink>;
132
156
  /**
133
157
  * Download an ingot as a Blob (high-level flow).
134
158
  *
135
- * Requests a fresh signed link on every attempt (server URLs are
136
- * short-lived) and retries transient transport failures with exponential
137
- * backoff. Validation failures (bad host, non-HTTPS) are never retried.
138
- *
139
- * Each attempt is bounded by liveness, never by total duration: a deadline
140
- * on the response headers, then an idle deadline rearmed on every body
141
- * chunk. A stalled transfer restarts from byte zero: this path requests no
142
- * byte range, so a full retry is the only recovery.
159
+ * Every attempt fetches a signed link minted for it ({@link createDownloadLink}:
160
+ * a link is single-use), under liveness bounds, never a cap on total
161
+ * duration: a deadline on the response headers, then an idle deadline
162
+ * rearmed on every body chunk. A failure the platform's transfer policy
163
+ * retries (`@sparkvault/app-sdk/transfer-retry`: no answer, 408, 425, 429 or
164
+ * a 5xx, a mint's included) is retried after the policy's backoff, never
165
+ * sooner than `Retry-After`, until its budget ends. Once bytes have arrived
166
+ * the retry resumes from the first byte it lacks, conditioned on the
167
+ * publication's ETag (`If-Range`), so a stall at 90% fetches only the rest;
168
+ * a file replaced meanwhile starts over as its new content, and one served
169
+ * with no strong ETag starts over from its first byte. Any other refusal,
170
+ * and a link that is not a Forge decrypt URL on an allowed host, is final.
143
171
  *
144
172
  * @example
145
173
  * const blob = await sv.ingots.download(unsealed, 'ing_abc');
@@ -14,7 +14,7 @@ export declare class IdentityApi extends SparkVaultApi {
14
14
  private configCache;
15
15
  constructor(config: ResolvedConfig, timeoutMs?: number);
16
16
  private get baseUrl();
17
- protected makeError(message: string, code: string, statusCode: number, details?: Record<string, unknown>): IdentityApiError;
17
+ protected makeError(message: string, code: string, statusCode: number, details?: Record<string, unknown>, retryAfterMs?: number | null): IdentityApiError;
18
18
  private request;
19
19
  /**
20
20
  * Fetch SDK configuration (branding, enabled methods).
@@ -184,5 +184,5 @@ export declare function parseSparkLinkEvent(raw: unknown): SparkLinkOutcome | nu
184
184
  */
185
185
  export declare function mapRecommendations(raw: unknown): Recommendation[] | undefined;
186
186
  export declare class IdentityApiError extends SparkVaultError {
187
- constructor(message: string, code: string, statusCode: number, details?: Record<string, unknown>);
187
+ constructor(message: string, code: string, statusCode: number, details?: Record<string, unknown>, retryAfterMs?: number | null);
188
188
  }