@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/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
|
@@ -4,15 +4,26 @@
|
|
|
4
4
|
* API client for vault upload operations.
|
|
5
5
|
*/
|
|
6
6
|
import { type ResolvedConfig } from '../../config';
|
|
7
|
+
import { type TransferOutcome, type TransferVerdict } from '@sparkvault/app-sdk/transfer-retry';
|
|
7
8
|
import { SparkVaultApi } from '../../api-base';
|
|
8
9
|
import { SparkVaultError } from '../../errors';
|
|
9
10
|
import type { VaultUploadConfig, VaultUploadInfoResponse } from './types';
|
|
10
11
|
/**
|
|
11
12
|
* Error class for upload API errors. Inherits `code` and `statusCode` from
|
|
12
13
|
* SparkVaultError — no duplicate `httpStatus` field.
|
|
14
|
+
*
|
|
15
|
+
* A failed transfer request also carries what the transfer policy
|
|
16
|
+
* (`@sparkvault/app-sdk/transfer-retry`) makes of its answer, read where the
|
|
17
|
+
* answer arrived: its `verdict` and its `Upload-Offset` (`serverOffset`),
|
|
18
|
+
* beside the `Retry-After` every SDK error carries (`retryAfterMs`). They are
|
|
19
|
+
* the retry loop's bookkeeping, so they ride on the instance, never in
|
|
20
|
+
* `details`. Every other failure (a cancel, a refused URL, a protocol
|
|
21
|
+
* violation) is `refused`: nothing retries it.
|
|
13
22
|
*/
|
|
14
23
|
export declare class UploadApiError extends SparkVaultError {
|
|
15
|
-
|
|
24
|
+
readonly verdict: TransferVerdict;
|
|
25
|
+
readonly serverOffset: number | null;
|
|
26
|
+
constructor(message: string, code: string, statusCode: number, details?: Record<string, unknown>, outcome?: TransferOutcome);
|
|
16
27
|
}
|
|
17
28
|
/** The widget's upload configuration, read from a vault's upload info answer. */
|
|
18
29
|
export declare function mapVaultUploadInfo(wire: VaultUploadInfoResponse): VaultUploadConfig;
|
|
@@ -28,7 +39,15 @@ export declare class UploadApi extends SparkVaultApi {
|
|
|
28
39
|
*/
|
|
29
40
|
private readonly vaultInfoMemo;
|
|
30
41
|
constructor(config: ResolvedConfig);
|
|
31
|
-
|
|
42
|
+
/**
|
|
43
|
+
* The shared transport's errors. It raises a request that got no answer (a
|
|
44
|
+
* dropped connection, a timeout) with status 0, which the transfer policy
|
|
45
|
+
* retries, a cancel aside; a refused API call it raises with its status is
|
|
46
|
+
* Core's verdict, never a transfer's, so of the policy's reading it carries
|
|
47
|
+
* only the floor Core named (`retryAfterMs`), for whoever acts on the
|
|
48
|
+
* refusal.
|
|
49
|
+
*/
|
|
50
|
+
protected makeError(message: string, code: string, statusCode: number, details?: Record<string, unknown>, retryAfterMs?: number | null): UploadApiError;
|
|
32
51
|
/**
|
|
33
52
|
* Issue a request to a Core route and unwrap the standard `{ data, meta }`
|
|
34
53
|
* envelope.
|
|
@@ -78,15 +97,49 @@ export declare class UploadApi extends SparkVaultApi {
|
|
|
78
97
|
* every server-reported offset, and honors the session abort signal plus
|
|
79
98
|
* per-request timeouts.
|
|
80
99
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
100
|
+
* Every answer is read through the transfer policy
|
|
101
|
+
* (`@sparkvault/app-sdk/transfer-retry`) and every retry spends one budget
|
|
102
|
+
* ({@link TusTransfer}). A chunk that fails in transit is resent only from
|
|
103
|
+
* an offset the server just named — a 409's own `Upload-Offset` at once,
|
|
104
|
+
* otherwise a HEAD after the backoff ({@link offsetAfterFailure}); a session
|
|
105
|
+
* the server no longer holds throws `session_gone`, which only a new upload
|
|
106
|
+
* recovers from (any code of Core's the server named rides
|
|
107
|
+
* `details.coreCode`); an upload Core refused for good (a full storage pool,
|
|
108
|
+
* a later upload that replaced it) throws `upload_refused` in Core's words,
|
|
109
|
+
* which no new upload recovers from. While the browser is offline, the loop
|
|
110
|
+
* waits for the network instead of spending attempts.
|
|
84
111
|
*
|
|
85
112
|
* Resolves only once the server has confirmed finalization
|
|
86
113
|
* ({@link confirmServerFinalized}), so a caller that gets a resolved promise
|
|
87
|
-
* is always looking at a published ingot
|
|
114
|
+
* is always looking at a published ingot; a publication the server still
|
|
115
|
+
* defers at the idle limit throws `upload_received_publishing`.
|
|
88
116
|
*/
|
|
89
117
|
uploadFileToForge(file: File | Blob, forgeUrl: string, onProgress?: (bytesUploaded: number, bytesTotal: number) => void): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Where the upload stands after a failed chunk PATCH, in the server's words:
|
|
120
|
+
* a 409's own `Upload-Offset` at once, otherwise the session's HEAD after
|
|
121
|
+
* the backoff. The failed chunk may have landed with its answer lost, and a
|
|
122
|
+
* PATCH at the client's stale offset is refused, so no chunk is ever sent
|
|
123
|
+
* again at an offset the server did not just name. The blip that killed the
|
|
124
|
+
* PATCH is also the likeliest thing to kill the HEAD moments later, so the
|
|
125
|
+
* HEAD is retried the same way, out of the same budget.
|
|
126
|
+
*/
|
|
127
|
+
private offsetAfterFailure;
|
|
128
|
+
/**
|
|
129
|
+
* Continue from the offset a 409 named, at once and without a HEAD: the
|
|
130
|
+
* server just said where the session stands. Past what this client sent,
|
|
131
|
+
* the server holds more than it knew, which is progress; anywhere else the
|
|
132
|
+
* answer contradicts the request, so it spends the budget like any failure
|
|
133
|
+
* and repeating it ends the upload.
|
|
134
|
+
*/
|
|
135
|
+
private resyncedOffset;
|
|
136
|
+
/**
|
|
137
|
+
* Wait out the backoff of a failed or deferred request to the upload's
|
|
138
|
+
* session ({@link waitToRetry}, keyed by the session URL), or throw: a gone
|
|
139
|
+
* session as `session_gone`, an answer no retry follows as it is, and the
|
|
140
|
+
* last failure, or the deferral, once the budget is spent.
|
|
141
|
+
*/
|
|
142
|
+
private backOff;
|
|
90
143
|
/**
|
|
91
144
|
* Confirm the server finalized a fully received upload — the one receipt
|
|
92
145
|
* every transfer ends on.
|
|
@@ -99,15 +152,29 @@ export declare class UploadApi extends SparkVaultApi {
|
|
|
99
152
|
* re-drive — it short-circuits to 204 on an already-finalized session, and
|
|
100
153
|
* on a received-but-unfinalized one it answers only after publication.
|
|
101
154
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
155
|
+
* While another request finalizes the receipt answers 409 with
|
|
156
|
+
* `Retry-After`, polled again after the policy's backoff as a failure; while
|
|
157
|
+
* the publication is deferred it answers 503 with `Retry-After`, a deferral
|
|
158
|
+
* the receipt is polled through without spending a failure, each ask after
|
|
159
|
+
* a longer backoff, until the idle limit throws
|
|
160
|
+
* `upload_received_publishing`: every byte is on the server, which finishes
|
|
161
|
+
* the publication on its own. A 503 naming no `Retry-After` is no deferral
|
|
162
|
+
* of Forge's, so it is polled as a failure. A 400 is the server's verdict
|
|
163
|
+
* and fails immediately, as does the refusal Core decided
|
|
164
|
+
* (`upload_refused`); a 409 naming an earlier offset means bytes are
|
|
165
|
+
* missing, and the upload continues from there.
|
|
106
166
|
*/
|
|
107
167
|
private confirmServerFinalized;
|
|
108
168
|
/**
|
|
109
|
-
* Read the offset a failed chunk should resume from
|
|
110
|
-
*
|
|
169
|
+
* Read the offset a failed chunk should resume from, from the session's
|
|
170
|
+
* HEAD. At the full offset it proves receipt only, published or not, so the
|
|
171
|
+
* loop then takes the receipt.
|
|
172
|
+
*/
|
|
173
|
+
private readResumeOffset;
|
|
174
|
+
/**
|
|
175
|
+
* Judge an offset the server named for the upload to resume from — a HEAD's,
|
|
176
|
+
* or a 409's `Upload-Offset` — the one place a server-reported resume point
|
|
177
|
+
* is judged.
|
|
111
178
|
*
|
|
112
179
|
* Forge commits a chunk before it answers, so a PATCH that died in transit
|
|
113
180
|
* may have landed in full or not at all (never in part — the chunk object
|
|
@@ -115,30 +182,45 @@ export declare class UploadApi extends SparkVaultApi {
|
|
|
115
182
|
* persisted offset knows which, and the client's arithmetic is worthless
|
|
116
183
|
* here.
|
|
117
184
|
*
|
|
118
|
-
* Two contracts disqualify an answer. TUS sanity: an
|
|
119
|
-
* declared total would end the loop early and report a
|
|
120
|
-
* complete, the same trap {@link patchChunk} guards
|
|
121
|
-
* offset. Forge chunk granularity: a session
|
|
122
|
-
* committed chunks, so an offset that is neither
|
|
123
|
-
* end is a corrupt session, and resuming from it
|
|
124
|
-
* non-final chunk Forge rejects anyway.
|
|
185
|
+
* Two contracts disqualify an answer (`resumeOffsetProblem`). TUS sanity: an
|
|
186
|
+
* offset past the declared total would end the loop early and report a
|
|
187
|
+
* partial upload as complete, the same trap {@link patchChunk} guards
|
|
188
|
+
* against on a PATCH's own offset. Forge chunk granularity: a session
|
|
189
|
+
* advances only in whole committed chunks, so an offset that is neither
|
|
190
|
+
* chunk-aligned nor the file end is a corrupt session, and resuming from it
|
|
191
|
+
* would send a short non-final chunk Forge rejects anyway.
|
|
125
192
|
*/
|
|
126
|
-
private
|
|
193
|
+
private checkResumeOffset;
|
|
127
194
|
/**
|
|
128
195
|
* Create the TUS upload session. Forge reads only `Tus-Resumable`,
|
|
129
196
|
* `Upload-Length`, and `X-ISTK` on create, and returns the session URL in
|
|
130
197
|
* `Location` (possibly relative) plus its chunk size in `X-Chunk-Size`.
|
|
198
|
+
*
|
|
199
|
+
* A create the transfer policy calls RETRY (no answer, 408, 425, 429, a 5xx)
|
|
200
|
+
* is sent again under the upload's budget: Forge refuses such a create
|
|
201
|
+
* before it claims the token, or hands the claim back on a transient
|
|
202
|
+
* key-service failure (503 + `Retry-After`), so the same ISTK opens the
|
|
203
|
+
* session on a later attempt. Every other answer is final, a 401 included:
|
|
204
|
+
* the token was already used, by an earlier attempt whose answer was lost,
|
|
205
|
+
* and no `Location` survives to continue that session from. No session URL
|
|
206
|
+
* exists yet to spread the retries by, and the ISTK never feeds one, so
|
|
207
|
+
* they spread by a key of the endpoint (`transferJitterKey`).
|
|
131
208
|
*/
|
|
132
209
|
private createTusSession;
|
|
133
210
|
/**
|
|
134
211
|
* PATCH one chunk with XMLHttpRequest (fetch exposes no upload progress).
|
|
135
|
-
* Resolves with the server-confirmed offset for the next iteration
|
|
212
|
+
* Resolves with the server-confirmed offset for the next iteration; a
|
|
213
|
+
* failure carries the transfer policy's verdict on its answer, read here.
|
|
136
214
|
*
|
|
137
215
|
* The server's `Upload-Offset` is validated, never trusted: it must be a
|
|
138
|
-
*
|
|
216
|
+
* whole number that strictly advances past this chunk's start (this client
|
|
139
217
|
* never sends an empty chunk, so a non-advancing 2xx would loop forever)
|
|
140
218
|
* and never exceeds the file size (an inflated offset would skip real
|
|
141
219
|
* chunks and report a partial upload as success).
|
|
220
|
+
*
|
|
221
|
+
* Bytes leaving are a sign of life: they restart the transfer's idle clock
|
|
222
|
+
* (never its failure count, which only the server's confirmation resets), so
|
|
223
|
+
* a slow chunk is never counted as idle time.
|
|
142
224
|
*/
|
|
143
225
|
private patchChunk;
|
|
144
226
|
/**
|
|
@@ -156,7 +238,9 @@ export declare class UploadApi extends SparkVaultApi {
|
|
|
156
238
|
* Uses the raw response rather than the JSON envelope helper: TUS responses
|
|
157
239
|
* carry an empty body and surface state in headers. Runs through the one SDK
|
|
158
240
|
* transport (session close signal, deadline, failure classification) and
|
|
159
|
-
* resolves only on a 2xx
|
|
241
|
+
* resolves only on a 2xx, with the transfer policy's reading of it, so no
|
|
242
|
+
* caller has to re-check `response.ok`; a non-2xx throws carrying the
|
|
243
|
+
* policy's verdict on its answer.
|
|
160
244
|
*
|
|
161
245
|
* @param check - Which caller this request serves; shapes the failure copy.
|
|
162
246
|
*/
|