@sparkvault/sdk-js 9.2.1 → 9.2.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.
- package/dist/index.cjs +149 -168
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.mjs +149 -168
- package/dist/index.mjs.map +1 -1
- package/dist/ingots/index.d.ts +5 -2
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/upload/api.d.ts +41 -41
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -9963,17 +9963,25 @@ const CHUNK_INACTIVITY_TIMEOUT_MS = 60000;
|
|
|
9963
9963
|
const CHUNK_MAX_ATTEMPTS = 3;
|
|
9964
9964
|
const CHUNK_RETRY_BASE_MS = 500;
|
|
9965
9965
|
/**
|
|
9966
|
-
*
|
|
9966
|
+
* Retry budget for the finalization receipt.
|
|
9967
9967
|
*
|
|
9968
|
-
*
|
|
9969
|
-
*
|
|
9970
|
-
*
|
|
9971
|
-
*
|
|
9972
|
-
* reach the declared total before reporting success.
|
|
9968
|
+
* Forge answers the zero-length PATCH with a 409 while another writer is still
|
|
9969
|
+
* inside the finalizer, so the confirmation has to out-wait a finalization
|
|
9970
|
+
* already in flight rather than give up on it — a budget measured in seconds
|
|
9971
|
+
* rather than in the sub-second blips a chunk retry recovers from.
|
|
9973
9972
|
*/
|
|
9974
|
-
const
|
|
9975
|
-
const
|
|
9976
|
-
/**
|
|
9973
|
+
const FINALIZE_MAX_ATTEMPTS = 10;
|
|
9974
|
+
const FINALIZE_RETRY_MS = 1000;
|
|
9975
|
+
/**
|
|
9976
|
+
* How many consecutive timeouts end the confirmation early.
|
|
9977
|
+
*
|
|
9978
|
+
* A genuinely slow finalize shows up as ONE timeout — the PATCH that started
|
|
9979
|
+
* the re-drive — followed by 409s from the writer that is working on it.
|
|
9980
|
+
* Back-to-back timeouts mean nobody is answering at all, and spending the full
|
|
9981
|
+
* budget on a black-holed socket would freeze the widget at 100% for minutes
|
|
9982
|
+
* with nothing for the user to act on.
|
|
9983
|
+
*/
|
|
9984
|
+
const FINALIZE_MAX_CONSECUTIVE_TIMEOUTS = 2;
|
|
9977
9985
|
/**
|
|
9978
9986
|
* A delay that a cancel cuts short: resolves after `ms`, rejects with the
|
|
9979
9987
|
* canonical cancelled error the moment the signal aborts.
|
|
@@ -9996,22 +10004,25 @@ function abortableDelay(ms, signal) {
|
|
|
9996
10004
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
9997
10005
|
});
|
|
9998
10006
|
}
|
|
9999
|
-
function delay(ms) {
|
|
10000
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
10001
|
-
}
|
|
10002
10007
|
/**
|
|
10003
|
-
* Whether a failed
|
|
10008
|
+
* Whether a failed transfer request is worth another attempt. Every retrying
|
|
10009
|
+
* stage of an upload asks this one question:
|
|
10004
10010
|
*
|
|
10005
|
-
*
|
|
10006
|
-
*
|
|
10007
|
-
*
|
|
10008
|
-
*
|
|
10009
|
-
*
|
|
10010
|
-
*
|
|
10011
|
-
*
|
|
10012
|
-
*
|
|
10013
|
-
|
|
10014
|
-
|
|
10011
|
+
* - the chunk PATCH loop — may this chunk be re-sent?
|
|
10012
|
+
* - the resume-HEAD loop — may the session's offset be re-read?
|
|
10013
|
+
* - the finalization receipt — may publication be asked about again?
|
|
10014
|
+
*
|
|
10015
|
+
* A transport-level failure (status 0 — a dropped connection, a timeout, or
|
|
10016
|
+
* the inactivity watchdog aborting a silent socket) says nothing about whether
|
|
10017
|
+
* the request reached Forge, 409 is Forge's documented "another writer holds
|
|
10018
|
+
* the session lease; re-check and retry" (on the receipt: a finalizer is
|
|
10019
|
+
* running right now), and a 5xx is a server-side blip. Every other outcome is
|
|
10020
|
+
* the server's considered answer about this exact request — a rejected offset,
|
|
10021
|
+
* a bad ISTK, a vanished session, or a 2xx carrying a protocol-violating
|
|
10022
|
+
* offset — and re-sending would only earn it again. A cancelled session is the
|
|
10023
|
+
* user's decision, never a failure to retry.
|
|
10024
|
+
*/
|
|
10025
|
+
function isRetryableTransferFailure(error) {
|
|
10015
10026
|
if (!(error instanceof UploadApiError))
|
|
10016
10027
|
return false;
|
|
10017
10028
|
// Verdicts, not blips: a cancel is the user's decision, and an invalid or
|
|
@@ -10024,14 +10035,25 @@ function isRetryableChunkFailure(error) {
|
|
|
10024
10035
|
const status = error.statusCode ?? 0;
|
|
10025
10036
|
return status === 0 || status === 409 || status >= 500;
|
|
10026
10037
|
}
|
|
10038
|
+
/**
|
|
10039
|
+
* A server's error body, reduced to something safe to carry on an error:
|
|
10040
|
+
* whitespace collapsed and length clipped, so an HTML error page or a stack
|
|
10041
|
+
* trace can never become the payload.
|
|
10042
|
+
*/
|
|
10043
|
+
const ERROR_DETAIL_MAX_CHARS = 200;
|
|
10044
|
+
function summarizeErrorBody(body) {
|
|
10045
|
+
return body.replace(/\s+/g, ' ').trim().slice(0, ERROR_DETAIL_MAX_CHARS);
|
|
10046
|
+
}
|
|
10027
10047
|
const RESUME_CHECK = {
|
|
10028
10048
|
name: 'Upload resume check',
|
|
10029
10049
|
code: 'resume_check_failed',
|
|
10050
|
+
serverFailureMessage: 'Upload could not be resumed: the server no longer recognizes this upload session.',
|
|
10030
10051
|
networkMessage: 'Unable to resume upload. Please check your connection and try again.',
|
|
10031
10052
|
};
|
|
10032
10053
|
const FINALIZATION_CHECK = {
|
|
10033
10054
|
name: 'Upload finalization check',
|
|
10034
10055
|
code: 'finalization_check_failed',
|
|
10056
|
+
serverFailureMessage: 'Upload could not be confirmed: the server did not finalize the file.',
|
|
10035
10057
|
networkMessage: 'Unable to confirm upload. Please check your connection and try again.',
|
|
10036
10058
|
};
|
|
10037
10059
|
class UploadApi extends SparkVaultApi {
|
|
@@ -10120,8 +10142,9 @@ class UploadApi extends SparkVaultApi {
|
|
|
10120
10142
|
* offset rather than failing the whole transfer — see {@link CHUNK_MAX_ATTEMPTS}
|
|
10121
10143
|
* and {@link readResumeOffset}.
|
|
10122
10144
|
*
|
|
10123
|
-
*
|
|
10124
|
-
*
|
|
10145
|
+
* Resolves only once the server has confirmed finalization
|
|
10146
|
+
* ({@link confirmServerFinalized}), so a caller that gets a resolved promise
|
|
10147
|
+
* is always looking at a published ingot.
|
|
10125
10148
|
*/
|
|
10126
10149
|
async uploadFileToForge(file, forgeUrl, onProgress) {
|
|
10127
10150
|
if (typeof XMLHttpRequest === 'undefined') {
|
|
@@ -10150,13 +10173,6 @@ class UploadApi extends SparkVaultApi {
|
|
|
10150
10173
|
}
|
|
10151
10174
|
}
|
|
10152
10175
|
: undefined;
|
|
10153
|
-
// A successful final-chunk PATCH is the server's finalization receipt:
|
|
10154
|
-
// Forge finalizes (publishes the ingot, moves the counters) BEFORE it
|
|
10155
|
-
// acknowledges that chunk with a 204. An offset learned from a resume
|
|
10156
|
-
// HEAD carries no such receipt — the server persists the final offset
|
|
10157
|
-
// before it finalizes — so a completion reached through the resume path
|
|
10158
|
-
// must be confirmed explicitly after the loop.
|
|
10159
|
-
let finalizeAcknowledged = false;
|
|
10160
10176
|
while (offset < file.size) {
|
|
10161
10177
|
if (this.isAborted()) {
|
|
10162
10178
|
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
@@ -10165,14 +10181,11 @@ class UploadApi extends SparkVaultApi {
|
|
|
10165
10181
|
try {
|
|
10166
10182
|
offset = await this.patchChunk(uploadUrl, file.slice(offset, chunkEnd), offset, file.size, monotonicProgress);
|
|
10167
10183
|
failedAttempts = 0;
|
|
10168
|
-
if (offset >= file.size) {
|
|
10169
|
-
finalizeAcknowledged = true;
|
|
10170
|
-
}
|
|
10171
10184
|
continue;
|
|
10172
10185
|
}
|
|
10173
10186
|
catch (error) {
|
|
10174
10187
|
failedAttempts += 1;
|
|
10175
|
-
if (failedAttempts >= CHUNK_MAX_ATTEMPTS || !
|
|
10188
|
+
if (failedAttempts >= CHUNK_MAX_ATTEMPTS || !isRetryableTransferFailure(error)) {
|
|
10176
10189
|
throw error;
|
|
10177
10190
|
}
|
|
10178
10191
|
}
|
|
@@ -10187,11 +10200,11 @@ class UploadApi extends SparkVaultApi {
|
|
|
10187
10200
|
for (;;) {
|
|
10188
10201
|
await abortableDelay(CHUNK_RETRY_BASE_MS * 2 ** (failedAttempts - 1), this.getAbortSignal());
|
|
10189
10202
|
try {
|
|
10190
|
-
serverOffset = await this.readResumeOffset(uploadUrl, file.size);
|
|
10203
|
+
serverOffset = await this.readResumeOffset(uploadUrl, file.size, session.chunkSize);
|
|
10191
10204
|
break;
|
|
10192
10205
|
}
|
|
10193
10206
|
catch (headError) {
|
|
10194
|
-
if (!
|
|
10207
|
+
if (!isRetryableTransferFailure(headError)) {
|
|
10195
10208
|
throw headError;
|
|
10196
10209
|
}
|
|
10197
10210
|
failedAttempts += 1;
|
|
@@ -10200,14 +10213,6 @@ class UploadApi extends SparkVaultApi {
|
|
|
10200
10213
|
}
|
|
10201
10214
|
}
|
|
10202
10215
|
}
|
|
10203
|
-
// Forge advances a session's offset only in whole committed chunks, so a
|
|
10204
|
-
// legitimate resume point is always chunk-aligned (or the file end). A
|
|
10205
|
-
// misaligned offset is a corrupt session, and resuming from it would
|
|
10206
|
-
// send a short non-final chunk Forge rejects anyway — fail it as the
|
|
10207
|
-
// protocol violation it is instead.
|
|
10208
|
-
if (serverOffset % session.chunkSize !== 0 && serverOffset !== file.size) {
|
|
10209
|
-
throw new UploadApiError(`Server returned misaligned upload offset (${serverOffset})`, 'invalid_offset', 0);
|
|
10210
|
-
}
|
|
10211
10216
|
if (serverOffset > offset) {
|
|
10212
10217
|
// Bytes reached the server despite the failure, so the transfer is
|
|
10213
10218
|
// alive: the budget is earned back rather than spent down across the
|
|
@@ -10216,86 +10221,85 @@ class UploadApi extends SparkVaultApi {
|
|
|
10216
10221
|
}
|
|
10217
10222
|
offset = serverOffset;
|
|
10218
10223
|
}
|
|
10219
|
-
|
|
10220
|
-
await this.confirmServerFinalized(uploadUrl, file.size);
|
|
10221
|
-
}
|
|
10222
|
-
return uploadUrl;
|
|
10224
|
+
await this.confirmServerFinalized(uploadUrl, file.size);
|
|
10223
10225
|
}
|
|
10224
10226
|
/**
|
|
10225
|
-
* Confirm the server finalized a fully received upload
|
|
10227
|
+
* Confirm the server finalized a fully received upload — the one receipt
|
|
10228
|
+
* every transfer ends on.
|
|
10229
|
+
*
|
|
10230
|
+
* The server persists the session's final offset BEFORE it finalizes, so a
|
|
10231
|
+
* HEAD offset proves receipt and never publication: it can equal the file
|
|
10232
|
+
* size while finalization failed or is still running, and reporting that as
|
|
10233
|
+
* success would hand the user a stored file whose ingot was never published.
|
|
10234
|
+
* The zero-length PATCH at the final offset is the server's finalization
|
|
10235
|
+
* re-drive — it short-circuits to 204 on an already-finalized session, and
|
|
10236
|
+
* on a received-but-unfinalized one it answers only after publication.
|
|
10226
10237
|
*
|
|
10227
|
-
*
|
|
10228
|
-
*
|
|
10229
|
-
*
|
|
10230
|
-
*
|
|
10231
|
-
* the final offset is the server's finalization re-drive: it answers 2xx
|
|
10232
|
-
* only once finalization has actually completed, the same receipt a
|
|
10233
|
-
* successful final chunk carries.
|
|
10238
|
+
* A 409 means another writer is inside the finalizer right now; that is the
|
|
10239
|
+
* outcome the budget exists for, so the retry waits it out rather than
|
|
10240
|
+
* failing a transfer that is about to succeed. A 400 is the opposite — the
|
|
10241
|
+
* server is behind the offset we claim — and fails immediately.
|
|
10234
10242
|
*/
|
|
10235
10243
|
async confirmServerFinalized(uploadUrl, totalSize) {
|
|
10236
|
-
let
|
|
10237
|
-
for (;;) {
|
|
10244
|
+
let consecutiveTimeouts = 0;
|
|
10245
|
+
for (let attempt = 1;; attempt++) {
|
|
10246
|
+
// An already-aborted session must not reach fetch: without
|
|
10247
|
+
// `AbortSignal.any` the combined signal only learns about a close that
|
|
10248
|
+
// arrives later, so the request would otherwise go out post-cancel.
|
|
10238
10249
|
if (this.isAborted()) {
|
|
10239
10250
|
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
10240
10251
|
}
|
|
10241
|
-
const closeSignal = this.getAbortSignal();
|
|
10242
|
-
const { signal, dispose } = combineTimeoutAndCloseSignals(this.timeoutMs, closeSignal);
|
|
10243
10252
|
try {
|
|
10244
|
-
|
|
10245
|
-
|
|
10246
|
-
|
|
10247
|
-
|
|
10248
|
-
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
signal,
|
|
10254
|
-
});
|
|
10255
|
-
}
|
|
10256
|
-
catch {
|
|
10257
|
-
if (closeSignal.aborted) {
|
|
10258
|
-
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
10259
|
-
}
|
|
10260
|
-
throw new UploadApiError('Upload finalization check failed: network error', 'finalization_check_failed', 0);
|
|
10261
|
-
}
|
|
10262
|
-
if (response.ok) {
|
|
10263
|
-
return;
|
|
10264
|
-
}
|
|
10265
|
-
throw new UploadApiError(`Upload finalization check failed: ${response.status}`, 'finalization_check_failed', response.status);
|
|
10253
|
+
await this.tusRequest(uploadUrl, {
|
|
10254
|
+
method: 'PATCH',
|
|
10255
|
+
headers: {
|
|
10256
|
+
'Tus-Resumable': TUS_VERSION,
|
|
10257
|
+
'Upload-Offset': String(totalSize),
|
|
10258
|
+
'Content-Type': 'application/offset+octet-stream',
|
|
10259
|
+
},
|
|
10260
|
+
}, FINALIZATION_CHECK);
|
|
10261
|
+
return;
|
|
10266
10262
|
}
|
|
10267
10263
|
catch (error) {
|
|
10268
|
-
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
|
|
10272
|
-
if (
|
|
10264
|
+
const timedOut = error instanceof UploadApiError && error.code === 'timeout';
|
|
10265
|
+
// Any answer at all — a 409 above all — proves someone is on the other
|
|
10266
|
+
// end, so the timeout tally starts over.
|
|
10267
|
+
consecutiveTimeouts = timedOut ? consecutiveTimeouts + 1 : 0;
|
|
10268
|
+
if (attempt >= FINALIZE_MAX_ATTEMPTS ||
|
|
10269
|
+
consecutiveTimeouts >= FINALIZE_MAX_CONSECUTIVE_TIMEOUTS ||
|
|
10270
|
+
!isRetryableTransferFailure(error)) {
|
|
10273
10271
|
throw error;
|
|
10274
10272
|
}
|
|
10275
|
-
await abortableDelay(
|
|
10276
|
-
}
|
|
10277
|
-
finally {
|
|
10278
|
-
dispose();
|
|
10273
|
+
await abortableDelay(FINALIZE_RETRY_MS, this.getAbortSignal());
|
|
10279
10274
|
}
|
|
10280
10275
|
}
|
|
10281
10276
|
}
|
|
10282
10277
|
/**
|
|
10283
|
-
* Read the offset a failed chunk should resume from
|
|
10278
|
+
* Read the offset a failed chunk should resume from — the one place a
|
|
10279
|
+
* server-reported resume point is judged.
|
|
10284
10280
|
*
|
|
10285
10281
|
* Forge commits a chunk before it answers, so a PATCH that died in transit
|
|
10286
10282
|
* may have landed in full or not at all (never in part — the chunk object
|
|
10287
10283
|
* is written atomically before the offset advances); only the session's own
|
|
10288
10284
|
* persisted offset knows which, and the client's arithmetic is worthless
|
|
10289
|
-
* here.
|
|
10290
|
-
*
|
|
10291
|
-
*
|
|
10292
|
-
*
|
|
10285
|
+
* here.
|
|
10286
|
+
*
|
|
10287
|
+
* Two contracts disqualify an answer. TUS sanity: an offset past the
|
|
10288
|
+
* declared total would end the loop early and report a partial upload as
|
|
10289
|
+
* complete, the same trap {@link patchChunk} guards against on a PATCH's own
|
|
10290
|
+
* offset. Forge chunk granularity: a session advances only in whole
|
|
10291
|
+
* committed chunks, so an offset that is neither chunk-aligned nor the file
|
|
10292
|
+
* end is a corrupt session, and resuming from it would send a short
|
|
10293
|
+
* non-final chunk Forge rejects anyway.
|
|
10293
10294
|
*/
|
|
10294
|
-
async readResumeOffset(uploadUrl, totalSize) {
|
|
10295
|
+
async readResumeOffset(uploadUrl, totalSize, chunkSize) {
|
|
10295
10296
|
const offset = await this.headUploadOffset(uploadUrl, RESUME_CHECK);
|
|
10296
10297
|
if (offset > totalSize) {
|
|
10297
10298
|
throw new UploadApiError(`Server returned invalid upload offset (${offset})`, 'invalid_offset', 0);
|
|
10298
10299
|
}
|
|
10300
|
+
if (offset % chunkSize !== 0 && offset !== totalSize) {
|
|
10301
|
+
throw new UploadApiError(`Server returned misaligned upload offset (${offset})`, 'invalid_offset', 0);
|
|
10302
|
+
}
|
|
10299
10303
|
return offset;
|
|
10300
10304
|
}
|
|
10301
10305
|
/**
|
|
@@ -10427,77 +10431,58 @@ class UploadApi extends SparkVaultApi {
|
|
|
10427
10431
|
});
|
|
10428
10432
|
}
|
|
10429
10433
|
/**
|
|
10430
|
-
*
|
|
10431
|
-
*
|
|
10432
|
-
* The TUS PATCH loop trusts a server-provided `Upload-Offset`; a buggy or
|
|
10433
|
-
* malicious Forge could return an inflated offset before every chunk was
|
|
10434
|
-
* actually committed and encrypted. This re-reads the server's own
|
|
10435
|
-
* persisted offset via a TUS HEAD (which Forge only advances on a real S3
|
|
10436
|
-
* commit) and requires it to reach the declared total — the web equivalent
|
|
10437
|
-
* of the mobile SDK's `verifyIngotActive` (status === 'active') guarantee.
|
|
10438
|
-
*
|
|
10439
|
-
* Polls because the final chunk's commit and the offset write can lag the
|
|
10440
|
-
* PATCH acknowledgement by a moment. Throws on a non-2xx HEAD, on a session
|
|
10441
|
-
* that never reaches the expected offset within the poll budget, or on a
|
|
10442
|
-
* cancelled session — never reports a half-finished upload as done.
|
|
10434
|
+
* Read the server's persisted upload offset via a TUS HEAD request — the one
|
|
10435
|
+
* place the client asks Forge where a session really stands.
|
|
10443
10436
|
*
|
|
10444
|
-
* @param
|
|
10445
|
-
* @param expectedOffset - The declared total upload size in bytes.
|
|
10437
|
+
* @param check - Which caller this read serves; shapes the failure copy.
|
|
10446
10438
|
*/
|
|
10447
|
-
async
|
|
10448
|
-
|
|
10449
|
-
|
|
10450
|
-
|
|
10451
|
-
|
|
10452
|
-
}
|
|
10453
|
-
const offset = await this.headUploadOffset(uploadUrl, FINALIZATION_CHECK);
|
|
10454
|
-
lastOffset = offset;
|
|
10455
|
-
if (offset >= expectedOffset) {
|
|
10456
|
-
return;
|
|
10457
|
-
}
|
|
10458
|
-
if (attempt < FINALIZE_POLL_MAX) {
|
|
10459
|
-
await delay(FINALIZE_POLL_MS);
|
|
10460
|
-
}
|
|
10439
|
+
async headUploadOffset(uploadUrl, check) {
|
|
10440
|
+
const response = await this.tusRequest(uploadUrl, { method: 'HEAD', headers: { 'Tus-Resumable': TUS_VERSION } }, check);
|
|
10441
|
+
const header = response.headers.get('Upload-Offset');
|
|
10442
|
+
const offset = header !== null ? parseInt(header, 10) : NaN;
|
|
10443
|
+
if (!Number.isFinite(offset) || offset < 0) {
|
|
10444
|
+
throw new UploadApiError(`${check.name} returned an invalid offset`, check.code, response.status);
|
|
10461
10445
|
}
|
|
10462
|
-
|
|
10463
|
-
`Confirmed ${lastOffset ?? 0} of ${expectedOffset} bytes.`, 'finalization_unconfirmed', 0, { confirmedBytes: lastOffset ?? 0, expectedBytes: expectedOffset });
|
|
10446
|
+
return offset;
|
|
10464
10447
|
}
|
|
10465
10448
|
/**
|
|
10466
|
-
*
|
|
10467
|
-
*
|
|
10468
|
-
* mid-upload resume and end-of-upload confirmation.
|
|
10449
|
+
* Issue one bodyless TUS request — the single transport behind every
|
|
10450
|
+
* non-chunk call this client makes (resume HEAD, finalization PATCH).
|
|
10469
10451
|
*
|
|
10470
|
-
* Uses raw `fetch` rather than the JSON envelope helper: TUS responses
|
|
10471
|
-
*
|
|
10472
|
-
*
|
|
10473
|
-
*
|
|
10452
|
+
* Uses raw `fetch` rather than the JSON envelope helper: TUS responses carry
|
|
10453
|
+
* an empty body and surface state in headers. Honors the session abort
|
|
10454
|
+
* signal and request timeout like every other client call, and resolves only
|
|
10455
|
+
* on a 2xx so no caller has to re-check `response.ok`.
|
|
10474
10456
|
*
|
|
10475
|
-
* @param check - Which caller this
|
|
10457
|
+
* @param check - Which caller this request serves; shapes the failure copy.
|
|
10476
10458
|
*/
|
|
10477
|
-
async
|
|
10459
|
+
async tusRequest(uploadUrl, init, check) {
|
|
10460
|
+
// Capture the session's close signal now, not in the catch: resetSession()
|
|
10461
|
+
// can swap the controller while this request is in flight, and reading the
|
|
10462
|
+
// live one would misreport a genuine cancel as a timeout.
|
|
10478
10463
|
const closeSignal = this.getAbortSignal();
|
|
10479
|
-
const { signal
|
|
10464
|
+
const { signal, dispose } = combineTimeoutAndCloseSignals(this.timeoutMs, closeSignal);
|
|
10480
10465
|
try {
|
|
10481
10466
|
const response = await fetch(uploadUrl, {
|
|
10482
|
-
method:
|
|
10483
|
-
headers:
|
|
10484
|
-
signal
|
|
10467
|
+
method: init.method,
|
|
10468
|
+
headers: init.headers,
|
|
10469
|
+
signal,
|
|
10485
10470
|
});
|
|
10486
10471
|
if (!response.ok) {
|
|
10487
|
-
|
|
10472
|
+
// Read the body even though the message does not need it: an unread
|
|
10473
|
+
// body pins its connection, and a retried receipt would strand one per
|
|
10474
|
+
// attempt. What it says is the only server-side detail this client
|
|
10475
|
+
// ever sees, so it rides along in `details` for support.
|
|
10476
|
+
const detail = summarizeErrorBody(await response.text().catch(() => ''));
|
|
10477
|
+
throw new UploadApiError(check.serverFailureMessage, check.code, response.status, { status: response.status, ...(detail ? { serverDetail: detail } : {}) });
|
|
10488
10478
|
}
|
|
10489
|
-
|
|
10490
|
-
const offset = header !== null ? parseInt(header, 10) : NaN;
|
|
10491
|
-
if (!Number.isFinite(offset) || offset < 0) {
|
|
10492
|
-
throw new UploadApiError(`${check.name} returned an invalid offset`, check.code, response.status);
|
|
10493
|
-
}
|
|
10494
|
-
return offset;
|
|
10479
|
+
return response;
|
|
10495
10480
|
}
|
|
10496
10481
|
catch (error) {
|
|
10497
10482
|
if (error instanceof SparkVaultError)
|
|
10498
10483
|
throw error;
|
|
10499
10484
|
if (error != null && typeof error === 'object' && 'name' in error && error.name === 'AbortError') {
|
|
10500
|
-
if (
|
|
10485
|
+
if (closeSignal.aborted) {
|
|
10501
10486
|
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
10502
10487
|
}
|
|
10503
10488
|
throw new UploadApiError(`${check.name} timed out after ${this.timeoutMs}ms`, 'timeout', 0);
|
|
@@ -12891,8 +12876,10 @@ class UploadRenderer {
|
|
|
12891
12876
|
progress: 0,
|
|
12892
12877
|
bytesUploaded: 0,
|
|
12893
12878
|
});
|
|
12894
|
-
// Upload file over the canonical TUS transfer path
|
|
12895
|
-
|
|
12879
|
+
// Upload file over the canonical TUS transfer path. It resolves only
|
|
12880
|
+
// once the server has confirmed finalization, so a non-finalized upload
|
|
12881
|
+
// throws here and never reaches the success ceremony.
|
|
12882
|
+
await this.api.uploadFileToForge(file, forgeUrl, (bytesUploaded, bytesTotal) => {
|
|
12896
12883
|
const progress = Math.round((bytesUploaded / bytesTotal) * 100);
|
|
12897
12884
|
this.setState({
|
|
12898
12885
|
view: 'uploading',
|
|
@@ -12909,12 +12896,6 @@ class UploadRenderer {
|
|
|
12909
12896
|
phase: 'uploading',
|
|
12910
12897
|
});
|
|
12911
12898
|
});
|
|
12912
|
-
// Confirm the server actually finalized the upload before celebrating.
|
|
12913
|
-
// The TUS loop trusts a server-provided offset; this re-reads the
|
|
12914
|
-
// server's own persisted offset and requires it to reach the file size,
|
|
12915
|
-
// mirroring the mobile SDK's active-status check. A non-finalized
|
|
12916
|
-
// upload throws here and never reaches the success ceremony.
|
|
12917
|
-
await this.api.verifyUploadFinalized(uploadUrl, file.size);
|
|
12918
12899
|
// Run ceremony animation
|
|
12919
12900
|
await this.runCeremony(file, ingotId, requestId);
|
|
12920
12901
|
// Complete
|
|
@@ -14016,15 +13997,14 @@ class IngotsModule {
|
|
|
14016
13997
|
return response.data;
|
|
14017
13998
|
}
|
|
14018
13999
|
/**
|
|
14019
|
-
* Run the canonical TUS transfer for a created/replaced ingot
|
|
14020
|
-
*
|
|
14000
|
+
* Run the canonical TUS transfer for a created/replaced ingot.
|
|
14001
|
+
*
|
|
14002
|
+
* The transfer resolves only once the server has confirmed finalization, so
|
|
14003
|
+
* the ingot this returns is always a published one — never a stored file
|
|
14004
|
+
* whose ingot never went active.
|
|
14021
14005
|
*/
|
|
14022
14006
|
async transferAndFinalize(created, file, onProgress) {
|
|
14023
|
-
|
|
14024
|
-
// Confirm the server actually finalized the upload before reporting
|
|
14025
|
-
// success — the TUS loop's offsets alone don't prove the final chunk
|
|
14026
|
-
// committed and the ingot went active.
|
|
14027
|
-
await this.uploadApi.verifyUploadFinalized(uploadUrl, file.size);
|
|
14007
|
+
await this.uploadApi.uploadFileToForge(file, created.forge_url, onProgress);
|
|
14028
14008
|
return {
|
|
14029
14009
|
id: created.ingot_id,
|
|
14030
14010
|
name: created.name,
|
|
@@ -14186,7 +14166,8 @@ async function fetchBlobWithLivenessBounds(url) {
|
|
|
14186
14166
|
throw error;
|
|
14187
14167
|
}
|
|
14188
14168
|
const contentType = response.headers.get('content-type') ?? '';
|
|
14189
|
-
//
|
|
14169
|
+
// Safari 10.1-14.4 ships fetch without `Response.body`, and the SDK's
|
|
14170
|
+
// support floor reaches back into that range. There the transfer keeps
|
|
14190
14171
|
// whole-transfer wall-clock semantics: blob() surfaces no chunk arrivals, so
|
|
14191
14172
|
// there is no liveness to observe.
|
|
14192
14173
|
if (!response.body) {
|
|
@@ -15080,7 +15061,7 @@ class SparkVault {
|
|
|
15080
15061
|
}
|
|
15081
15062
|
/** Get the SDK version */
|
|
15082
15063
|
static get version() {
|
|
15083
|
-
return '9.2.
|
|
15064
|
+
return '9.2.3';
|
|
15084
15065
|
}
|
|
15085
15066
|
}
|
|
15086
15067
|
if (typeof window !== 'undefined') {
|