@sparkvault/sdk-js 11.0.0 → 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/api-base.d.ts +14 -5
- package/dist/errors.d.ts +32 -16
- package/dist/http.d.ts +8 -0
- package/dist/index.cjs +1509 -352
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +87 -27
- package/dist/index.mjs +1509 -352
- package/dist/index.mjs.map +1 -1
- package/dist/ingots/fetch-download.d.ts +40 -10
- package/dist/ingots/index.d.ts +30 -10
- package/dist/products/identity/api.d.ts +2 -2
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/upload/api.d.ts +107 -23
- package/package.json +1 -1
|
@@ -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
|
|
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
|
|
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
|
-
/**
|
|
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
|
|
43
|
-
* Nothing caps the transfer as a whole, so file size never decides
|
|
44
|
-
* download can finish. The link is single-use
|
|
45
|
-
*
|
|
46
|
-
*
|
|
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>;
|
package/dist/ingots/index.d.ts
CHANGED
|
@@ -38,6 +38,18 @@ export declare class IngotsModule {
|
|
|
38
38
|
* published, so a resolved promise never stands for a stored file whose
|
|
39
39
|
* ingot never went live.
|
|
40
40
|
*
|
|
41
|
+
* Transient failures are retried inside the transfer; a session the server
|
|
42
|
+
* no longer holds (it expired, was cancelled, or its ingot was removed)
|
|
43
|
+
* rejects with code `session_gone`, and only a new upload session — a new
|
|
44
|
+
* {@link createUpload}, or {@link upload} again — can store the file. An
|
|
45
|
+
* upload the server refused for good (the account's storage pool cannot
|
|
46
|
+
* take it, or a later upload replaced it) rejects with code
|
|
47
|
+
* `upload_refused`, its message the server's own sentence and its code in
|
|
48
|
+
* `details.coreCode`: a new upload is no remedy. A publication the server
|
|
49
|
+
* still defers at the transfer's idle limit rejects with code
|
|
50
|
+
* `upload_received_publishing`: every byte is received, and the server
|
|
51
|
+
* finishes the publication on its own, so never upload the file again.
|
|
52
|
+
*
|
|
41
53
|
* @param options.signal - Cancels this transfer (it rejects with code
|
|
42
54
|
* `cancelled`); other transfers carry on.
|
|
43
55
|
* @param options.onProgress - Bytes sent so far and the file size; never runs backwards.
|
|
@@ -122,24 +134,32 @@ export declare class IngotsModule {
|
|
|
122
134
|
* Create a signed download link for an ingot (discrete primitive).
|
|
123
135
|
*
|
|
124
136
|
* Validates the returned URL against the download-host allowlist. Use this
|
|
125
|
-
* when you want the URL itself; otherwise prefer {@link download}.
|
|
137
|
+
* when you want the URL itself; otherwise prefer {@link download}. The link
|
|
138
|
+
* is single-use: Forge claims it the moment a request arrives, so a retry or
|
|
139
|
+
* a resume needs a link of its own (`fetchDownload`'s `remint`).
|
|
126
140
|
*
|
|
127
141
|
* @example
|
|
128
142
|
* const link = await sv.ingots.createDownloadLink(unsealed, 'ing_abc');
|
|
129
|
-
*
|
|
143
|
+
* const { blob } = await fetchDownload(link.downloadUrl, {
|
|
144
|
+
* remint: async () => (await sv.ingots.createDownloadLink(unsealed, 'ing_abc')).downloadUrl,
|
|
145
|
+
* });
|
|
130
146
|
*/
|
|
131
147
|
createDownloadLink(vault: UnsealedVault, ingotId: string): Promise<IngotDownloadLink>;
|
|
132
148
|
/**
|
|
133
149
|
* Download an ingot as a Blob (high-level flow).
|
|
134
150
|
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
151
|
+
* Every attempt fetches a signed link minted for it ({@link createDownloadLink}:
|
|
152
|
+
* a link is single-use), under liveness bounds, never a cap on total
|
|
153
|
+
* duration: a deadline on the response headers, then an idle deadline
|
|
154
|
+
* rearmed on every body chunk. A failure the platform's transfer policy
|
|
155
|
+
* retries (`@sparkvault/app-sdk/transfer-retry`: no answer, 408, 425, 429 or
|
|
156
|
+
* a 5xx, a mint's included) is retried after the policy's backoff, never
|
|
157
|
+
* sooner than `Retry-After`, until its budget ends. Once bytes have arrived
|
|
158
|
+
* the retry resumes from the first byte it lacks, conditioned on the
|
|
159
|
+
* publication's ETag (`If-Range`), so a stall at 90% fetches only the rest;
|
|
160
|
+
* a file replaced meanwhile starts over as its new content, and one served
|
|
161
|
+
* with no strong ETag starts over from its first byte. Any other refusal,
|
|
162
|
+
* and a link that is not a Forge decrypt URL on an allowed host, is final.
|
|
143
163
|
*
|
|
144
164
|
* @example
|
|
145
165
|
* 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
|
|
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
|
}
|