@sparkvault/sdk-js 11.2.4 → 11.2.6
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.cjs +196 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -9
- package/dist/index.mjs +196 -75
- package/dist/index.mjs.map +1 -1
- package/dist/ingots/index.d.ts +16 -9
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/upload/api.d.ts +7 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -33,7 +33,9 @@ function isTransientHttpStatus(status) {
|
|
|
33
33
|
* The upload publication contract between Forge and Core's activation, and
|
|
34
34
|
* the facts of a transfer token both services spell: its shape, the
|
|
35
35
|
* publication it is bound to (a content version, and the one an ingot row
|
|
36
|
-
* names),
|
|
36
|
+
* names), Core's revocation of an upload's token, and the refusals of Core's
|
|
37
|
+
* a transfer's answer names (the header, and the lock of a vault scheduled
|
|
38
|
+
* for deletion).
|
|
37
39
|
*
|
|
38
40
|
* Forge stamps UPLOAD_PUBLICATION_PROTOCOL on every upload session it creates
|
|
39
41
|
* and on the final state it hands Core's activation (POST
|
|
@@ -114,10 +116,37 @@ const UPLOAD_TOKEN_REVOCATION = Object.freeze({
|
|
|
114
116
|
Object.values(UPLOAD_TOKEN_REVOCATION.reasons);
|
|
115
117
|
|
|
116
118
|
/**
|
|
117
|
-
* The
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
119
|
+
* The code Core refuses every use of a vault's content with (409) while the
|
|
120
|
+
* vault is scheduled for deletion, until a company admin cancels the
|
|
121
|
+
* deletion or it runs and the vault is gone: a transfer token's use, each
|
|
122
|
+
* request of a transfer (Forge asks Core before every one and relays the
|
|
123
|
+
* refusal naming this code), and an upload's activation, which Forge defers.
|
|
124
|
+
* The lock refuses an upload's requests and never ends its session, so a
|
|
125
|
+
* client keeps the session and reports the lock. The session still lapses
|
|
126
|
+
* on its own idle window (upload-expiry.js), which is shorter than the
|
|
127
|
+
* deletion's delay: an upload resumed after a cancelled deletion goes on from
|
|
128
|
+
* its offset while the session stands, and starts over once it has lapsed.
|
|
129
|
+
*/
|
|
130
|
+
const VAULT_DELETION_SCHEDULED = 'VAULT_DELETION_SCHEDULED';
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The words a vault scheduled for deletion refuses every use of its content
|
|
134
|
+
* in (VAULT_DELETION_SCHEDULED), whichever service or client meets it:
|
|
135
|
+
* Core's refusal, and a client's report of it from an answer with no body
|
|
136
|
+
* to carry Core's (a HEAD's, naming the code in UPLOAD_REFUSAL_HEADER alone).
|
|
137
|
+
*/
|
|
138
|
+
const VAULT_DELETION_SCHEDULED_MESSAGE =
|
|
139
|
+
'This vault is scheduled for deletion. Cancel its deletion in vault settings before accessing its contents.';
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The response header that names the code of a refusal Core decided: Forge
|
|
143
|
+
* sends it on every terminal answer to a tus request (a 404, 410 or 412) and
|
|
144
|
+
* on every answer relaying Core's decision about a transfer's vault (the 409
|
|
145
|
+
* VAULT_DELETION_SCHEDULED, a 404 naming the vault), a download's and a
|
|
146
|
+
* HEAD's (which has no body) included, so a
|
|
147
|
+
* client tells an upload the owner's pool cannot take from one a later
|
|
148
|
+
* upload superseded, and Core's lock from another request holding the
|
|
149
|
+
* session's lease, without reading a body.
|
|
121
150
|
*/
|
|
122
151
|
const UPLOAD_REFUSAL_HEADER = 'X-Upload-Refusal';
|
|
123
152
|
|
|
@@ -142,20 +171,29 @@ const UPLOAD_REFUSAL_HEADER = 'X-Upload-Refusal';
|
|
|
142
171
|
* both bounds start over whenever the server confirms progress.
|
|
143
172
|
*
|
|
144
173
|
* Forge's own answers beyond the general rule:
|
|
145
|
-
* -
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* of the
|
|
156
|
-
* for
|
|
157
|
-
*
|
|
158
|
-
*
|
|
174
|
+
* - an answer naming a refusal Core decided names Core's code: a terminal
|
|
175
|
+
* answer (a 404, 410 or 412) the code Core ended the upload with, and a 409
|
|
176
|
+
* relaying Core's refusal of the transfer the code Core refused it with.
|
|
177
|
+
* Its error envelope names it in `error.details.coreCode` (for the refusals
|
|
178
|
+
* Forge words itself and the ones it relays from Core's check of a
|
|
179
|
+
* transfer), and every one of them in `X-Upload-Refusal`, which is all a
|
|
180
|
+
* HEAD's answer, having no body, can carry; the body's code wins when both
|
|
181
|
+
* name one;
|
|
182
|
+
* - the 409, in three kinds: one carrying `Upload-Offset` names where the
|
|
183
|
+
* session stands (continue from there); one naming Core's code is Core's
|
|
184
|
+
* refusal of the transfer in its vault's current state, a vault scheduled
|
|
185
|
+
* for deletion (VAULT_DELETION_SCHEDULED), which keeps the session (until
|
|
186
|
+
* it lapses on its 72 h idle window, upload-expiry.js) and which neither
|
|
187
|
+
* the same request nor a new upload gets past until a person cancels the
|
|
188
|
+
* deletion, so it is reported, never retried; and one naming
|
|
189
|
+
* neither means another request holds the session's write lease, a chunk
|
|
190
|
+
* or the finalization (retry after its `Retry-After`);
|
|
191
|
+
* - a terminal answer's code decides its verdict: a full storage pool or a
|
|
192
|
+
* later upload that replaced this one is a refusal no new upload of the
|
|
193
|
+
* same file remedies, and any other code (the file the upload was for
|
|
194
|
+
* gone, a retired contract, a replacement base that moved on, a code this
|
|
195
|
+
* policy does not know) ends the session, which a new upload can start
|
|
196
|
+
* over;
|
|
159
197
|
* - a 503 carrying `Retry-After` to the receipt (the PATCH at the final
|
|
160
198
|
* offset) is a deferral: Forge holds every byte and is still publishing,
|
|
161
199
|
* and finishes without the client, so it is asked again, each time after a
|
|
@@ -182,10 +220,10 @@ const TRANSFER_VERDICT = Object.freeze({
|
|
|
182
220
|
/** 2xx: the request did what it asked. */
|
|
183
221
|
OK: 'ok',
|
|
184
222
|
/**
|
|
185
|
-
* No answer (a reset, a timeout), 408, 425, 429, a 5xx, or a 409
|
|
186
|
-
* `Upload-Offset`
|
|
187
|
-
* never sooner than `Retry-After`, then ask
|
|
188
|
-
* sending a chunk again.
|
|
223
|
+
* No answer (a reset, a timeout), 408, 425, 429, a 5xx, or a 409 naming
|
|
224
|
+
* neither an `Upload-Offset` nor a code of Core's (another request holds
|
|
225
|
+
* the session's lease): back off, never sooner than `Retry-After`, then ask
|
|
226
|
+
* the server's offset before sending a chunk again.
|
|
189
227
|
*/
|
|
190
228
|
RETRY: 'retry',
|
|
191
229
|
/** 409 with `Upload-Offset`: the session stands elsewhere; continue from that offset at once. */
|
|
@@ -204,10 +242,11 @@ const TRANSFER_VERDICT = Object.freeze({
|
|
|
204
242
|
*/
|
|
205
243
|
GONE: 'gone',
|
|
206
244
|
/**
|
|
207
|
-
* Any other status,
|
|
208
|
-
* (`coreCode`: UPLOAD_POOL_FULL, UPLOAD_SUPERSEDED)
|
|
209
|
-
*
|
|
210
|
-
*
|
|
245
|
+
* Any other status, a 404, 410 or 412 naming a final refusal of Core's
|
|
246
|
+
* (`coreCode`: UPLOAD_POOL_FULL, UPLOAD_SUPERSEDED), or a 409 naming any
|
|
247
|
+
* code of Core's (`coreCode`: VAULT_DELETION_SCHEDULED, whose session
|
|
248
|
+
* stands): the server's verdict on this request, which repeating it, or a
|
|
249
|
+
* new upload of the same file, earns again.
|
|
211
250
|
*/
|
|
212
251
|
REFUSED: 'refused'
|
|
213
252
|
});
|
|
@@ -227,6 +266,12 @@ const SERVICE_UNAVAILABLE = 503;
|
|
|
227
266
|
*/
|
|
228
267
|
const TERMINAL_STATUSES = new Set([404, 410, 412]);
|
|
229
268
|
|
|
269
|
+
/**
|
|
270
|
+
* Forge's 409: about where the session stands (`Upload-Offset`), another
|
|
271
|
+
* request's lease on it, or Core's refusal of the transfer, relayed.
|
|
272
|
+
*/
|
|
273
|
+
const CONFLICT = 409;
|
|
274
|
+
|
|
230
275
|
/** Core's error codes are upper-case words joined by underscores; anything else names no code. */
|
|
231
276
|
const CORE_CODE = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
232
277
|
|
|
@@ -267,12 +312,14 @@ const DEFAULT_MAX_CONSECUTIVE_FAILURES = 8;
|
|
|
267
312
|
* @property {number|null} retryAfterMs - The answer's `Retry-After`, in ms from
|
|
268
313
|
* the answer (an HTTP-date already past reads as 0); null when absent or unreadable
|
|
269
314
|
* @property {number|null} offset - The answer's `Upload-Offset`; null when absent or unreadable
|
|
270
|
-
* @property {string|null} coreCode - The code
|
|
271
|
-
*
|
|
272
|
-
* naming none, its `X-Upload-Refusal`): REFUSED for
|
|
273
|
-
* (`
|
|
274
|
-
* (`
|
|
275
|
-
*
|
|
315
|
+
* @property {string|null} coreCode - The code of the refusal Core decided, as
|
|
316
|
+
* the answer named it (a 404, 410 or 412, or a 409 naming no offset: its
|
|
317
|
+
* body's details or, those naming none, its `X-Upload-Refusal`): REFUSED for
|
|
318
|
+
* any code a 409 names (`VAULT_DELETION_SCHEDULED`) and for a terminal
|
|
319
|
+
* answer's final refusal (`UPLOAD_POOL_FULL`, `UPLOAD_SUPERSEDED`), GONE for
|
|
320
|
+
* any other code a terminal answer names (`NOT_FOUND`,
|
|
321
|
+
* `UPLOAD_PROTOCOL_RETIRED`, a 412's, one this policy does not know); null
|
|
322
|
+
* when the answer names none
|
|
276
323
|
*/
|
|
277
324
|
|
|
278
325
|
/**
|
|
@@ -311,7 +358,7 @@ function classifyTransferResponse({ status, headers = null, details = null, rece
|
|
|
311
358
|
}
|
|
312
359
|
const header = (name) => (headers === null ? null : headers(name));
|
|
313
360
|
const offset = readCount(header(UPLOAD_OFFSET_HEADER));
|
|
314
|
-
const coreCode =
|
|
361
|
+
const coreCode = mayNameCoreCode(status, offset)
|
|
315
362
|
? coreCodeIn(details) ?? coreCodeOf(header(UPLOAD_REFUSAL_HEADER))
|
|
316
363
|
: null;
|
|
317
364
|
const retryAfterMs = readRetryAfterMs(header(RETRY_AFTER_HEADER), now);
|
|
@@ -323,14 +370,28 @@ function classifyTransferResponse({ status, headers = null, details = null, rece
|
|
|
323
370
|
};
|
|
324
371
|
}
|
|
325
372
|
|
|
373
|
+
/**
|
|
374
|
+
* Whether an answer may name the code of a refusal Core decided: a terminal
|
|
375
|
+
* answer does, and so does a 409 naming no offset. A 409 carrying
|
|
376
|
+
* `Upload-Offset` is Forge's own, about where the session stands.
|
|
377
|
+
*/
|
|
378
|
+
function mayNameCoreCode(status, offset) {
|
|
379
|
+
return TERMINAL_STATUSES.has(status) || (status === CONFLICT && offset === null);
|
|
380
|
+
}
|
|
381
|
+
|
|
326
382
|
/**
|
|
327
383
|
* The verdict on a status that came with an answer: `offset` its readable
|
|
328
|
-
* `Upload-Offset`, `coreCode` the code of Core's
|
|
384
|
+
* `Upload-Offset`, `coreCode` the code of Core's the answer names,
|
|
329
385
|
* `deferral` whether it answered the receipt with a readable `Retry-After`.
|
|
330
386
|
*/
|
|
331
387
|
function verdictFor(status, { offset, coreCode, deferral }) {
|
|
332
388
|
if (status >= 200 && status < 300) return TRANSFER_VERDICT.OK;
|
|
333
|
-
if (status ===
|
|
389
|
+
if (status === CONFLICT) {
|
|
390
|
+
if (offset !== null) return TRANSFER_VERDICT.RESYNC;
|
|
391
|
+
// Core's 409 refuses the transfer in its vault's current state: the
|
|
392
|
+
// session stands, and the same request or a new upload earns it again.
|
|
393
|
+
return coreCode === null ? TRANSFER_VERDICT.RETRY : TRANSFER_VERDICT.REFUSED;
|
|
394
|
+
}
|
|
334
395
|
if (coreCode !== null) return UPLOAD_FINAL_REFUSAL_CODES.includes(coreCode) ? TRANSFER_VERDICT.REFUSED : TRANSFER_VERDICT.GONE;
|
|
335
396
|
if (status === 404 || status === 410) return TRANSFER_VERDICT.GONE;
|
|
336
397
|
if (deferral && status === SERVICE_UNAVAILABLE) return TRANSFER_VERDICT.DEFERRED;
|
|
@@ -11755,22 +11816,25 @@ const SESSION_GONE_MESSAGE = 'Upload could not be finished: the server has ended
|
|
|
11755
11816
|
*/
|
|
11756
11817
|
const RECEIVED_PUBLISHING_MESSAGE = 'The server received every byte of this file and is still saving it. It finishes on its own.';
|
|
11757
11818
|
/**
|
|
11758
|
-
* The copy a person reads for a
|
|
11759
|
-
*
|
|
11760
|
-
* `X-Upload-Refusal` alone): this SDK's own words for each
|
|
11819
|
+
* The copy a person reads for a refusal whose answer carried no sentence of
|
|
11820
|
+
* Core's (a HEAD's, which has no body, naming Core's code in
|
|
11821
|
+
* `X-Upload-Refusal` alone): this SDK's own words for each final refusal,
|
|
11822
|
+
* and Core's own for its lock of a vault scheduled for deletion, none of them
|
|
11761
11823
|
* asking for the file again.
|
|
11762
11824
|
*/
|
|
11763
11825
|
const REFUSAL_WORDING = new Map([
|
|
11764
11826
|
[UPLOAD_REFUSAL_CODES.UPLOAD_POOL_FULL, 'This upload could not be saved: the owner\'s storage cannot take the file.'],
|
|
11765
11827
|
[UPLOAD_REFUSAL_CODES.UPLOAD_SUPERSEDED, 'This upload was not saved: a newer upload of this file replaced it.'],
|
|
11828
|
+
[VAULT_DELETION_SCHEDULED, VAULT_DELETION_SCHEDULED_MESSAGE],
|
|
11766
11829
|
]);
|
|
11767
11830
|
/** The copy for a final refusal of a code this SDK has no words of its own for. */
|
|
11768
11831
|
const REFUSED_MESSAGE = 'This upload could not be saved: the server refused it.';
|
|
11769
11832
|
/**
|
|
11770
|
-
* The error of an upload Core refused
|
|
11771
|
-
*
|
|
11772
|
-
*
|
|
11773
|
-
*
|
|
11833
|
+
* The error of an upload Core refused (UPLOAD_FINAL_REFUSAL_CODES, or the 409
|
|
11834
|
+
* of a vault scheduled for deletion, VAULT_DELETION_SCHEDULED, whose session
|
|
11835
|
+
* stands): `upload_refused` in Core's own sentence, this SDK's for an answer
|
|
11836
|
+
* that carried none (a HEAD's), Core's code in `details.coreCode`; never
|
|
11837
|
+
* retried, and no new upload of the same file remedies it. The one reading of that
|
|
11774
11838
|
* verdict, whichever answer carries it: a transfer answer naming Core's code
|
|
11775
11839
|
* ({@link readTransferAnswer}), or Core's own refusal of the request that
|
|
11776
11840
|
* stages the upload ({@link stagingRefusal}).
|
|
@@ -12147,9 +12211,10 @@ class UploadApi extends SparkVaultApi {
|
|
|
12147
12211
|
* otherwise a HEAD after the backoff ({@link offsetAfterFailure}); a session
|
|
12148
12212
|
* the server no longer holds throws `session_gone`, which only a new upload
|
|
12149
12213
|
* recovers from (any code of Core's the server named rides
|
|
12150
|
-
* `details.coreCode`); an upload Core refused
|
|
12151
|
-
*
|
|
12152
|
-
*
|
|
12214
|
+
* `details.coreCode`); an upload Core refused (a full storage pool, a later
|
|
12215
|
+
* upload that replaced it, its vault scheduled for deletion, whose 409 names
|
|
12216
|
+
* Core's code) throws `upload_refused` in Core's words at once, which no new
|
|
12217
|
+
* upload recovers from. While the browser is offline, the loop
|
|
12153
12218
|
* waits for the network instead of spending attempts.
|
|
12154
12219
|
*
|
|
12155
12220
|
* Resolves only once the server has confirmed finalization
|
|
@@ -12359,8 +12424,9 @@ class UploadApi extends SparkVaultApi {
|
|
|
12359
12424
|
* the publication on its own. A 503 naming no `Retry-After` is no deferral
|
|
12360
12425
|
* of Forge's, so it is polled as a failure. A 400 is the server's verdict
|
|
12361
12426
|
* and fails immediately, as does the refusal Core decided
|
|
12362
|
-
* (`upload_refused
|
|
12363
|
-
* missing, and the upload continues from
|
|
12427
|
+
* (`upload_refused`, a 409 naming Core's code among them); a 409 naming an
|
|
12428
|
+
* earlier offset means bytes are missing, and the upload continues from
|
|
12429
|
+
* there.
|
|
12364
12430
|
*/
|
|
12365
12431
|
async confirmServerFinalized(transfer) {
|
|
12366
12432
|
let consecutiveTimeouts = 0;
|
|
@@ -14105,6 +14171,12 @@ function formatBytes(bytes, decimals = 1) {
|
|
|
14105
14171
|
* Orchestrates view state and rendering for vault upload flows.
|
|
14106
14172
|
* Manages the complete upload lifecycle: form, uploading, ceremony, completion.
|
|
14107
14173
|
*/
|
|
14174
|
+
/**
|
|
14175
|
+
* What an outside uploader reads when the vault is scheduled for deletion:
|
|
14176
|
+
* the vault takes no files now. Core's own sentence, which tells the vault's
|
|
14177
|
+
* admin how to cancel the deletion, is the console's, never this page's.
|
|
14178
|
+
*/
|
|
14179
|
+
const VAULT_NOT_ACCEPTING_MESSAGE = 'This vault isn\'t accepting files right now, so your file was not saved. Please contact the person who shared this upload page with you.';
|
|
14108
14180
|
/**
|
|
14109
14181
|
* Ceremony steps for the cryptographic visualization.
|
|
14110
14182
|
*/
|
|
@@ -14890,10 +14962,23 @@ class UploadRenderer {
|
|
|
14890
14962
|
statusCode: error.statusCode,
|
|
14891
14963
|
});
|
|
14892
14964
|
}
|
|
14965
|
+
else if (error.code === VAULT_DELETION_SCHEDULED || error.details?.coreCode === VAULT_DELETION_SCHEDULED) {
|
|
14966
|
+
// The vault is scheduled for deletion, refused at the upload's start
|
|
14967
|
+
// or while its bytes moved. Core's sentence tells the vault's admin
|
|
14968
|
+
// how to cancel the deletion; the person on this page is an outside
|
|
14969
|
+
// uploader, told only that the vault takes no files now.
|
|
14970
|
+
this.setState({
|
|
14971
|
+
view: 'error',
|
|
14972
|
+
title: 'Uploads Paused',
|
|
14973
|
+
message: VAULT_NOT_ACCEPTING_MESSAGE,
|
|
14974
|
+
code: error.code,
|
|
14975
|
+
statusCode: error.statusCode,
|
|
14976
|
+
});
|
|
14977
|
+
}
|
|
14893
14978
|
else if (error.code === 'upload_refused') {
|
|
14894
|
-
// Core refused the upload
|
|
14895
|
-
//
|
|
14896
|
-
//
|
|
14979
|
+
// Core refused the upload, in its own words (whom to contact about a
|
|
14980
|
+
// full storage pool, or the later upload that replaced this one): a
|
|
14981
|
+
// sentence that never asks for the file again.
|
|
14897
14982
|
this.setState({
|
|
14898
14983
|
view: 'error',
|
|
14899
14984
|
title: 'Upload Not Saved',
|
|
@@ -15704,21 +15789,35 @@ async function attemptWith(source, state, options) {
|
|
|
15704
15789
|
assertDownloadUrl(link, options.isAllowedHost);
|
|
15705
15790
|
}
|
|
15706
15791
|
catch (error) {
|
|
15707
|
-
|
|
15792
|
+
if (!(error instanceof SparkVaultError) || typeof error.statusCode !== 'number') {
|
|
15793
|
+
return { ok: false, error, outcome: UNANSWERED };
|
|
15794
|
+
}
|
|
15795
|
+
const outcome = mintOutcome(error, error.statusCode);
|
|
15796
|
+
return { ok: false, error: outcome.coreCode === null ? error : namingCoreCode(error, outcome.coreCode), outcome };
|
|
15708
15797
|
}
|
|
15709
15798
|
return attemptDownload(link, state, options);
|
|
15710
15799
|
}
|
|
15711
15800
|
/**
|
|
15712
|
-
* The transfer policy's reading of a
|
|
15713
|
-
* answer when it built the error: its status gives the verdict (a refused
|
|
15714
|
-
* is a 400, so final) and the `Retry-After` it named rides on the error
|
|
15801
|
+
* The transfer policy's reading of a mint Core refused. The HTTP client read
|
|
15802
|
+
* the answer when it built the error: its status gives the verdict (a refused
|
|
15803
|
+
* link is a 400, so final) and the `Retry-After` it named rides on the error
|
|
15715
15804
|
* (`retryAfterMs`), so a mint Core defers waits out Core's floor exactly as a
|
|
15716
|
-
* deferred Forge answer does.
|
|
15805
|
+
* deferred Forge answer does. Core's lock of a vault scheduled for deletion
|
|
15806
|
+
* (409 VAULT_DELETION_SCHEDULED) is read by its code, as the policy reads
|
|
15807
|
+
* Forge's relay of it on the download itself: final at once. Any other 409
|
|
15808
|
+
* keeps its status's reading.
|
|
15809
|
+
*/
|
|
15810
|
+
function mintOutcome(error, status) {
|
|
15811
|
+
const details = error.code === VAULT_DELETION_SCHEDULED ? { coreCode: error.code } : null;
|
|
15812
|
+
return { ...classifyTransferResponse({ status, details }), retryAfterMs: error.retryAfterMs };
|
|
15813
|
+
}
|
|
15814
|
+
/**
|
|
15815
|
+
* Core's refusal of a mint as its caller sees it: Core's sentence, code and
|
|
15816
|
+
* details, with the code in `details.coreCode`, where a refused download
|
|
15817
|
+
* names it too, so one reading tells the lock whichever answer met it.
|
|
15717
15818
|
*/
|
|
15718
|
-
function
|
|
15719
|
-
|
|
15720
|
-
return UNANSWERED;
|
|
15721
|
-
return { ...classifyTransferResponse({ status: error.statusCode }), retryAfterMs: error.retryAfterMs };
|
|
15819
|
+
function namingCoreCode(error, coreCode) {
|
|
15820
|
+
return new SparkVaultError(error.message, error.code, error.statusCode, { ...error.details, coreCode }, error.retryAfterMs);
|
|
15722
15821
|
}
|
|
15723
15822
|
/**
|
|
15724
15823
|
* Fetch one link: the rest of the file held, conditioned on its validator,
|
|
@@ -15753,11 +15852,8 @@ async function attemptDownload(link, state, options) {
|
|
|
15753
15852
|
? { signal: controller.signal, headers: { Range: `bytes=${resume.at}-`, 'If-Range': resume.validator } }
|
|
15754
15853
|
: { signal: controller.signal }), DOWNLOAD_TTFB_TIMEOUT_MS, controller, 'Download timed out waiting for response headers');
|
|
15755
15854
|
if (!response.ok) {
|
|
15756
|
-
|
|
15757
|
-
|
|
15758
|
-
error: new SparkVaultError(`Download failed with status ${response.status}`, 'download_failed', response.status),
|
|
15759
|
-
outcome: classifyTransferResponse({ status: response.status, headers: (name) => response.headers.get(name) }),
|
|
15760
|
-
};
|
|
15855
|
+
const outcome = classifyTransferResponse({ status: response.status, headers: (name) => response.headers.get(name) });
|
|
15856
|
+
return { ok: false, error: await refusedDownloadError(response, outcome, controller), outcome };
|
|
15761
15857
|
}
|
|
15762
15858
|
if (resume && response.status === 206) {
|
|
15763
15859
|
const continued = continuation(response, resume);
|
|
@@ -15813,6 +15909,24 @@ async function attemptDownload(link, state, options) {
|
|
|
15813
15909
|
signal?.removeEventListener('abort', abortFromCaller);
|
|
15814
15910
|
}
|
|
15815
15911
|
}
|
|
15912
|
+
/**
|
|
15913
|
+
* The error a download answered with a failure throws once nothing retries
|
|
15914
|
+
* it. A refusal Core decided names Core's code (the 409 of a vault scheduled
|
|
15915
|
+
* for deletion, in X-Upload-Refusal), and is reported in Core's own sentence,
|
|
15916
|
+
* read from the answer's body under the idle deadline, with the code in
|
|
15917
|
+
* `details.coreCode`; any other failure by its status.
|
|
15918
|
+
*/
|
|
15919
|
+
async function refusedDownloadError(response, outcome, controller) {
|
|
15920
|
+
const statusMessage = `Download failed with status ${response.status}`;
|
|
15921
|
+
const { coreCode } = outcome;
|
|
15922
|
+
if (outcome.verdict !== TRANSFER_VERDICT.REFUSED || coreCode === null) {
|
|
15923
|
+
return new SparkVaultError(statusMessage, 'download_failed', response.status);
|
|
15924
|
+
}
|
|
15925
|
+
const served = await withDeadline(readApiFailure(response), DOWNLOAD_IDLE_TIMEOUT_MS, controller, 'Download timed out reading the refusal');
|
|
15926
|
+
// Only a body naming the same code carries Core's sentence for it.
|
|
15927
|
+
const message = served.code === coreCode ? served.message : statusMessage;
|
|
15928
|
+
return new SparkVaultError(message, 'download_failed', response.status, { coreCode });
|
|
15929
|
+
}
|
|
15816
15930
|
/**
|
|
15817
15931
|
* The failure of a body that ended at a length other than the one its
|
|
15818
15932
|
* response declared: what the caller sees once the transfer can no longer
|
|
@@ -16222,10 +16336,13 @@ class IngotsModule {
|
|
|
16222
16336
|
* no longer holds (it expired, was cancelled, or its ingot was removed)
|
|
16223
16337
|
* rejects with code `session_gone`, and only a new upload session — a new
|
|
16224
16338
|
* {@link createUpload}, or {@link upload} again — can store the file. An
|
|
16225
|
-
* upload the server refused
|
|
16226
|
-
*
|
|
16227
|
-
* `
|
|
16228
|
-
*
|
|
16339
|
+
* upload the server refused (the account's storage pool cannot take it, a
|
|
16340
|
+
* later upload replaced it, or its vault is scheduled for deletion: a 409
|
|
16341
|
+
* `VAULT_DELETION_SCHEDULED`, whose session the server keeps until the
|
|
16342
|
+
* deletion runs or is cancelled, or the session lapses on its own) rejects
|
|
16343
|
+
* at once with code `upload_refused`, its message the server's own sentence
|
|
16344
|
+
* and its code in `details.coreCode`: a new upload is no remedy. A
|
|
16345
|
+
* publication the server
|
|
16229
16346
|
* still defers at the transfer's idle limit rejects with code
|
|
16230
16347
|
* `upload_received_publishing`: every byte is received, and the server
|
|
16231
16348
|
* finishes the publication on its own, so never upload the file again; a
|
|
@@ -16259,8 +16376,11 @@ class IngotsModule {
|
|
|
16259
16376
|
*
|
|
16260
16377
|
* It rejects as {@link sendUpload} does: `session_gone` once the server no
|
|
16261
16378
|
* longer holds the session (it expired, was cancelled, or ended when the
|
|
16262
|
-
* server refused to publish it), `upload_refused` for an upload
|
|
16263
|
-
*
|
|
16379
|
+
* server refused to publish it), `upload_refused` for an upload the server
|
|
16380
|
+
* refused (its storage pool, a later upload, or its vault scheduled for
|
|
16381
|
+
* deletion, a 409 `VAULT_DELETION_SCHEDULED` that keeps the session, so a
|
|
16382
|
+
* resume once the deletion is cancelled goes on while the session stands),
|
|
16383
|
+
* `upload_received_publishing` again for a publication the server
|
|
16264
16384
|
* still defers at the transfer's idle limit, which leaves the session to
|
|
16265
16385
|
* resume again later. A session URL that is not an upload session on an
|
|
16266
16386
|
* allowed transfer host is refused (`invalid_forge_url`), and one whose
|
|
@@ -16309,9 +16429,10 @@ class IngotsModule {
|
|
|
16309
16429
|
*
|
|
16310
16430
|
* Creates the upload session, streams the file to Forge over TUS, then
|
|
16311
16431
|
* confirms the server finalized the upload before resolving. A file the
|
|
16312
|
-
* server refused
|
|
16313
|
-
*
|
|
16314
|
-
*
|
|
16432
|
+
* server refused — another upload of it superseded this one, at its create
|
|
16433
|
+
* or while it streamed, the storage pool cannot take it, or its vault is
|
|
16434
|
+
* scheduled for deletion (a 409 `VAULT_DELETION_SCHEDULED`) — rejects with
|
|
16435
|
+
* code `upload_refused`, as {@link sendUpload} does.
|
|
16315
16436
|
*
|
|
16316
16437
|
* @example
|
|
16317
16438
|
* const ingot = await sv.ingots.upload(unsealed, {
|
|
@@ -17444,7 +17565,7 @@ class SparkVault {
|
|
|
17444
17565
|
}
|
|
17445
17566
|
/** Get the SDK version */
|
|
17446
17567
|
static get version() {
|
|
17447
|
-
return '11.2.
|
|
17568
|
+
return '11.2.6';
|
|
17448
17569
|
}
|
|
17449
17570
|
}
|
|
17450
17571
|
if (typeof window !== 'undefined') {
|