@sparkvault/sdk-js 9.2.1 → 9.2.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/index.cjs +164 -169
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.mjs +164 -169
- 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,6 +10035,15 @@ 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',
|
|
@@ -10034,6 +10054,22 @@ const FINALIZATION_CHECK = {
|
|
|
10034
10054
|
code: 'finalization_check_failed',
|
|
10035
10055
|
networkMessage: 'Unable to confirm upload. Please check your connection and try again.',
|
|
10036
10056
|
};
|
|
10057
|
+
/**
|
|
10058
|
+
* Turn a terminal confirmation failure into something a person can read.
|
|
10059
|
+
*
|
|
10060
|
+
* The upload widget prints `error.message` verbatim, and a bare status line
|
|
10061
|
+
* ("Upload finalization check failed: 500") tells the user nothing about their
|
|
10062
|
+
* file. Only the status-carrying failure is rewritten: a timeout or a
|
|
10063
|
+
* connection failure already explains itself in the user's terms, and its code
|
|
10064
|
+
* is load-bearing taxonomy. The status and the server's own detail move into
|
|
10065
|
+
* `details`, where support can still read them.
|
|
10066
|
+
*/
|
|
10067
|
+
function asFinalizationFailure(error) {
|
|
10068
|
+
if (!(error instanceof UploadApiError) || error.code !== FINALIZATION_CHECK.code) {
|
|
10069
|
+
return error;
|
|
10070
|
+
}
|
|
10071
|
+
return new UploadApiError('Upload could not be confirmed: the server did not finalize the file.', error.code, error.statusCode ?? 0, { ...error.details, status: error.statusCode ?? 0 });
|
|
10072
|
+
}
|
|
10037
10073
|
class UploadApi extends SparkVaultApi {
|
|
10038
10074
|
constructor(config) {
|
|
10039
10075
|
super(config.timeout);
|
|
@@ -10120,8 +10156,9 @@ class UploadApi extends SparkVaultApi {
|
|
|
10120
10156
|
* offset rather than failing the whole transfer — see {@link CHUNK_MAX_ATTEMPTS}
|
|
10121
10157
|
* and {@link readResumeOffset}.
|
|
10122
10158
|
*
|
|
10123
|
-
*
|
|
10124
|
-
*
|
|
10159
|
+
* Resolves only once the server has confirmed finalization
|
|
10160
|
+
* ({@link confirmServerFinalized}), so a caller that gets a resolved promise
|
|
10161
|
+
* is always looking at a published ingot.
|
|
10125
10162
|
*/
|
|
10126
10163
|
async uploadFileToForge(file, forgeUrl, onProgress) {
|
|
10127
10164
|
if (typeof XMLHttpRequest === 'undefined') {
|
|
@@ -10150,13 +10187,6 @@ class UploadApi extends SparkVaultApi {
|
|
|
10150
10187
|
}
|
|
10151
10188
|
}
|
|
10152
10189
|
: 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
10190
|
while (offset < file.size) {
|
|
10161
10191
|
if (this.isAborted()) {
|
|
10162
10192
|
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
@@ -10165,14 +10195,11 @@ class UploadApi extends SparkVaultApi {
|
|
|
10165
10195
|
try {
|
|
10166
10196
|
offset = await this.patchChunk(uploadUrl, file.slice(offset, chunkEnd), offset, file.size, monotonicProgress);
|
|
10167
10197
|
failedAttempts = 0;
|
|
10168
|
-
if (offset >= file.size) {
|
|
10169
|
-
finalizeAcknowledged = true;
|
|
10170
|
-
}
|
|
10171
10198
|
continue;
|
|
10172
10199
|
}
|
|
10173
10200
|
catch (error) {
|
|
10174
10201
|
failedAttempts += 1;
|
|
10175
|
-
if (failedAttempts >= CHUNK_MAX_ATTEMPTS || !
|
|
10202
|
+
if (failedAttempts >= CHUNK_MAX_ATTEMPTS || !isRetryableTransferFailure(error)) {
|
|
10176
10203
|
throw error;
|
|
10177
10204
|
}
|
|
10178
10205
|
}
|
|
@@ -10187,11 +10214,11 @@ class UploadApi extends SparkVaultApi {
|
|
|
10187
10214
|
for (;;) {
|
|
10188
10215
|
await abortableDelay(CHUNK_RETRY_BASE_MS * 2 ** (failedAttempts - 1), this.getAbortSignal());
|
|
10189
10216
|
try {
|
|
10190
|
-
serverOffset = await this.readResumeOffset(uploadUrl, file.size);
|
|
10217
|
+
serverOffset = await this.readResumeOffset(uploadUrl, file.size, session.chunkSize);
|
|
10191
10218
|
break;
|
|
10192
10219
|
}
|
|
10193
10220
|
catch (headError) {
|
|
10194
|
-
if (!
|
|
10221
|
+
if (!isRetryableTransferFailure(headError)) {
|
|
10195
10222
|
throw headError;
|
|
10196
10223
|
}
|
|
10197
10224
|
failedAttempts += 1;
|
|
@@ -10200,14 +10227,6 @@ class UploadApi extends SparkVaultApi {
|
|
|
10200
10227
|
}
|
|
10201
10228
|
}
|
|
10202
10229
|
}
|
|
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
10230
|
if (serverOffset > offset) {
|
|
10212
10231
|
// Bytes reached the server despite the failure, so the transfer is
|
|
10213
10232
|
// alive: the budget is earned back rather than spent down across the
|
|
@@ -10216,86 +10235,85 @@ class UploadApi extends SparkVaultApi {
|
|
|
10216
10235
|
}
|
|
10217
10236
|
offset = serverOffset;
|
|
10218
10237
|
}
|
|
10219
|
-
|
|
10220
|
-
await this.confirmServerFinalized(uploadUrl, file.size);
|
|
10221
|
-
}
|
|
10222
|
-
return uploadUrl;
|
|
10238
|
+
await this.confirmServerFinalized(uploadUrl, file.size);
|
|
10223
10239
|
}
|
|
10224
10240
|
/**
|
|
10225
|
-
* Confirm the server finalized a fully received upload
|
|
10241
|
+
* Confirm the server finalized a fully received upload — the one receipt
|
|
10242
|
+
* every transfer ends on.
|
|
10226
10243
|
*
|
|
10227
|
-
* The server persists the session's final offset BEFORE it finalizes, so
|
|
10228
|
-
* offset
|
|
10229
|
-
* failed or is still running
|
|
10230
|
-
* a stored file whose ingot was never published.
|
|
10231
|
-
* the final offset is the server's finalization
|
|
10232
|
-
*
|
|
10233
|
-
*
|
|
10244
|
+
* The server persists the session's final offset BEFORE it finalizes, so a
|
|
10245
|
+
* HEAD offset proves receipt and never publication: it can equal the file
|
|
10246
|
+
* size while finalization failed or is still running, and reporting that as
|
|
10247
|
+
* success would hand the user a stored file whose ingot was never published.
|
|
10248
|
+
* The zero-length PATCH at the final offset is the server's finalization
|
|
10249
|
+
* re-drive — it short-circuits to 204 on an already-finalized session, and
|
|
10250
|
+
* on a received-but-unfinalized one it answers only after publication.
|
|
10251
|
+
*
|
|
10252
|
+
* A 409 means another writer is inside the finalizer right now; that is the
|
|
10253
|
+
* outcome the budget exists for, so the retry waits it out rather than
|
|
10254
|
+
* failing a transfer that is about to succeed. A 400 is the opposite — the
|
|
10255
|
+
* server is behind the offset we claim — and fails immediately.
|
|
10234
10256
|
*/
|
|
10235
10257
|
async confirmServerFinalized(uploadUrl, totalSize) {
|
|
10236
|
-
let
|
|
10237
|
-
for (;;) {
|
|
10258
|
+
let consecutiveTimeouts = 0;
|
|
10259
|
+
for (let attempt = 1;; attempt++) {
|
|
10260
|
+
// An already-aborted session must not reach fetch: without
|
|
10261
|
+
// `AbortSignal.any` the combined signal only learns about a close that
|
|
10262
|
+
// arrives later, so the request would otherwise go out post-cancel.
|
|
10238
10263
|
if (this.isAborted()) {
|
|
10239
10264
|
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
10240
10265
|
}
|
|
10241
|
-
const closeSignal = this.getAbortSignal();
|
|
10242
|
-
const { signal, dispose } = combineTimeoutAndCloseSignals(this.timeoutMs, closeSignal);
|
|
10243
10266
|
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);
|
|
10267
|
+
await this.tusRequest(uploadUrl, {
|
|
10268
|
+
method: 'PATCH',
|
|
10269
|
+
headers: {
|
|
10270
|
+
'Tus-Resumable': TUS_VERSION,
|
|
10271
|
+
'Upload-Offset': String(totalSize),
|
|
10272
|
+
'Content-Type': 'application/offset+octet-stream',
|
|
10273
|
+
},
|
|
10274
|
+
}, FINALIZATION_CHECK);
|
|
10275
|
+
return;
|
|
10266
10276
|
}
|
|
10267
10277
|
catch (error) {
|
|
10268
|
-
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
|
|
10272
|
-
if (
|
|
10273
|
-
|
|
10278
|
+
const timedOut = error instanceof UploadApiError && error.code === 'timeout';
|
|
10279
|
+
// Any answer at all — a 409 above all — proves someone is on the other
|
|
10280
|
+
// end, so the timeout tally starts over.
|
|
10281
|
+
consecutiveTimeouts = timedOut ? consecutiveTimeouts + 1 : 0;
|
|
10282
|
+
if (attempt >= FINALIZE_MAX_ATTEMPTS ||
|
|
10283
|
+
consecutiveTimeouts >= FINALIZE_MAX_CONSECUTIVE_TIMEOUTS ||
|
|
10284
|
+
!isRetryableTransferFailure(error)) {
|
|
10285
|
+
throw asFinalizationFailure(error);
|
|
10274
10286
|
}
|
|
10275
|
-
await abortableDelay(
|
|
10276
|
-
}
|
|
10277
|
-
finally {
|
|
10278
|
-
dispose();
|
|
10287
|
+
await abortableDelay(FINALIZE_RETRY_MS, this.getAbortSignal());
|
|
10279
10288
|
}
|
|
10280
10289
|
}
|
|
10281
10290
|
}
|
|
10282
10291
|
/**
|
|
10283
|
-
* Read the offset a failed chunk should resume from
|
|
10292
|
+
* Read the offset a failed chunk should resume from — the one place a
|
|
10293
|
+
* server-reported resume point is judged.
|
|
10284
10294
|
*
|
|
10285
10295
|
* Forge commits a chunk before it answers, so a PATCH that died in transit
|
|
10286
10296
|
* may have landed in full or not at all (never in part — the chunk object
|
|
10287
10297
|
* is written atomically before the offset advances); only the session's own
|
|
10288
10298
|
* persisted offset knows which, and the client's arithmetic is worthless
|
|
10289
|
-
* here.
|
|
10290
|
-
*
|
|
10291
|
-
*
|
|
10292
|
-
*
|
|
10299
|
+
* here.
|
|
10300
|
+
*
|
|
10301
|
+
* Two contracts disqualify an answer. TUS sanity: an offset past the
|
|
10302
|
+
* declared total would end the loop early and report a partial upload as
|
|
10303
|
+
* complete, the same trap {@link patchChunk} guards against on a PATCH's own
|
|
10304
|
+
* offset. Forge chunk granularity: a session advances only in whole
|
|
10305
|
+
* committed chunks, so an offset that is neither chunk-aligned nor the file
|
|
10306
|
+
* end is a corrupt session, and resuming from it would send a short
|
|
10307
|
+
* non-final chunk Forge rejects anyway.
|
|
10293
10308
|
*/
|
|
10294
|
-
async readResumeOffset(uploadUrl, totalSize) {
|
|
10309
|
+
async readResumeOffset(uploadUrl, totalSize, chunkSize) {
|
|
10295
10310
|
const offset = await this.headUploadOffset(uploadUrl, RESUME_CHECK);
|
|
10296
10311
|
if (offset > totalSize) {
|
|
10297
10312
|
throw new UploadApiError(`Server returned invalid upload offset (${offset})`, 'invalid_offset', 0);
|
|
10298
10313
|
}
|
|
10314
|
+
if (offset % chunkSize !== 0 && offset !== totalSize) {
|
|
10315
|
+
throw new UploadApiError(`Server returned misaligned upload offset (${offset})`, 'invalid_offset', 0);
|
|
10316
|
+
}
|
|
10299
10317
|
return offset;
|
|
10300
10318
|
}
|
|
10301
10319
|
/**
|
|
@@ -10427,77 +10445,58 @@ class UploadApi extends SparkVaultApi {
|
|
|
10427
10445
|
});
|
|
10428
10446
|
}
|
|
10429
10447
|
/**
|
|
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.
|
|
10448
|
+
* Read the server's persisted upload offset via a TUS HEAD request — the one
|
|
10449
|
+
* place the client asks Forge where a session really stands.
|
|
10443
10450
|
*
|
|
10444
|
-
* @param
|
|
10445
|
-
* @param expectedOffset - The declared total upload size in bytes.
|
|
10451
|
+
* @param check - Which caller this read serves; shapes the failure copy.
|
|
10446
10452
|
*/
|
|
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
|
-
}
|
|
10453
|
+
async headUploadOffset(uploadUrl, check) {
|
|
10454
|
+
const response = await this.tusRequest(uploadUrl, { method: 'HEAD', headers: { 'Tus-Resumable': TUS_VERSION } }, check);
|
|
10455
|
+
const header = response.headers.get('Upload-Offset');
|
|
10456
|
+
const offset = header !== null ? parseInt(header, 10) : NaN;
|
|
10457
|
+
if (!Number.isFinite(offset) || offset < 0) {
|
|
10458
|
+
throw new UploadApiError(`${check.name} returned an invalid offset`, check.code, response.status);
|
|
10461
10459
|
}
|
|
10462
|
-
|
|
10463
|
-
`Confirmed ${lastOffset ?? 0} of ${expectedOffset} bytes.`, 'finalization_unconfirmed', 0, { confirmedBytes: lastOffset ?? 0, expectedBytes: expectedOffset });
|
|
10460
|
+
return offset;
|
|
10464
10461
|
}
|
|
10465
10462
|
/**
|
|
10466
|
-
*
|
|
10467
|
-
*
|
|
10468
|
-
* mid-upload resume and end-of-upload confirmation.
|
|
10463
|
+
* Issue one bodyless TUS request — the single transport behind every
|
|
10464
|
+
* non-chunk call this client makes (resume HEAD, finalization PATCH).
|
|
10469
10465
|
*
|
|
10470
|
-
* Uses raw `fetch` rather than the JSON envelope helper: TUS responses
|
|
10471
|
-
*
|
|
10472
|
-
*
|
|
10473
|
-
*
|
|
10466
|
+
* Uses raw `fetch` rather than the JSON envelope helper: TUS responses carry
|
|
10467
|
+
* an empty body and surface state in headers. Honors the session abort
|
|
10468
|
+
* signal and request timeout like every other client call, and resolves only
|
|
10469
|
+
* on a 2xx so no caller has to re-check `response.ok`.
|
|
10474
10470
|
*
|
|
10475
|
-
* @param check - Which caller this
|
|
10471
|
+
* @param check - Which caller this request serves; shapes the failure copy.
|
|
10476
10472
|
*/
|
|
10477
|
-
async
|
|
10473
|
+
async tusRequest(uploadUrl, init, check) {
|
|
10474
|
+
// Capture the session's close signal now, not in the catch: resetSession()
|
|
10475
|
+
// can swap the controller while this request is in flight, and reading the
|
|
10476
|
+
// live one would misreport a genuine cancel as a timeout.
|
|
10478
10477
|
const closeSignal = this.getAbortSignal();
|
|
10479
|
-
const { signal
|
|
10478
|
+
const { signal, dispose } = combineTimeoutAndCloseSignals(this.timeoutMs, closeSignal);
|
|
10480
10479
|
try {
|
|
10481
10480
|
const response = await fetch(uploadUrl, {
|
|
10482
|
-
method:
|
|
10483
|
-
headers:
|
|
10484
|
-
signal
|
|
10481
|
+
method: init.method,
|
|
10482
|
+
headers: init.headers,
|
|
10483
|
+
signal,
|
|
10485
10484
|
});
|
|
10486
10485
|
if (!response.ok) {
|
|
10487
|
-
|
|
10486
|
+
// Read the body even though the message does not need it: an unread
|
|
10487
|
+
// body pins its connection, and a retried receipt would strand one per
|
|
10488
|
+
// attempt. What it says is the only server-side detail this client
|
|
10489
|
+
// ever sees, so it rides along in `details` for support.
|
|
10490
|
+
const detail = summarizeErrorBody(await response.text().catch(() => ''));
|
|
10491
|
+
throw new UploadApiError(`${check.name} failed: ${response.status}`, check.code, response.status, detail ? { serverDetail: detail } : undefined);
|
|
10488
10492
|
}
|
|
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;
|
|
10493
|
+
return response;
|
|
10495
10494
|
}
|
|
10496
10495
|
catch (error) {
|
|
10497
10496
|
if (error instanceof SparkVaultError)
|
|
10498
10497
|
throw error;
|
|
10499
10498
|
if (error != null && typeof error === 'object' && 'name' in error && error.name === 'AbortError') {
|
|
10500
|
-
if (
|
|
10499
|
+
if (closeSignal.aborted) {
|
|
10501
10500
|
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
10502
10501
|
}
|
|
10503
10502
|
throw new UploadApiError(`${check.name} timed out after ${this.timeoutMs}ms`, 'timeout', 0);
|
|
@@ -12891,8 +12890,10 @@ class UploadRenderer {
|
|
|
12891
12890
|
progress: 0,
|
|
12892
12891
|
bytesUploaded: 0,
|
|
12893
12892
|
});
|
|
12894
|
-
// Upload file over the canonical TUS transfer path
|
|
12895
|
-
|
|
12893
|
+
// Upload file over the canonical TUS transfer path. It resolves only
|
|
12894
|
+
// once the server has confirmed finalization, so a non-finalized upload
|
|
12895
|
+
// throws here and never reaches the success ceremony.
|
|
12896
|
+
await this.api.uploadFileToForge(file, forgeUrl, (bytesUploaded, bytesTotal) => {
|
|
12896
12897
|
const progress = Math.round((bytesUploaded / bytesTotal) * 100);
|
|
12897
12898
|
this.setState({
|
|
12898
12899
|
view: 'uploading',
|
|
@@ -12909,12 +12910,6 @@ class UploadRenderer {
|
|
|
12909
12910
|
phase: 'uploading',
|
|
12910
12911
|
});
|
|
12911
12912
|
});
|
|
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
12913
|
// Run ceremony animation
|
|
12919
12914
|
await this.runCeremony(file, ingotId, requestId);
|
|
12920
12915
|
// Complete
|
|
@@ -14016,15 +14011,14 @@ class IngotsModule {
|
|
|
14016
14011
|
return response.data;
|
|
14017
14012
|
}
|
|
14018
14013
|
/**
|
|
14019
|
-
* Run the canonical TUS transfer for a created/replaced ingot
|
|
14020
|
-
*
|
|
14014
|
+
* Run the canonical TUS transfer for a created/replaced ingot.
|
|
14015
|
+
*
|
|
14016
|
+
* The transfer resolves only once the server has confirmed finalization, so
|
|
14017
|
+
* the ingot this returns is always a published one — never a stored file
|
|
14018
|
+
* whose ingot never went active.
|
|
14021
14019
|
*/
|
|
14022
14020
|
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);
|
|
14021
|
+
await this.uploadApi.uploadFileToForge(file, created.forge_url, onProgress);
|
|
14028
14022
|
return {
|
|
14029
14023
|
id: created.ingot_id,
|
|
14030
14024
|
name: created.name,
|
|
@@ -14186,7 +14180,8 @@ async function fetchBlobWithLivenessBounds(url) {
|
|
|
14186
14180
|
throw error;
|
|
14187
14181
|
}
|
|
14188
14182
|
const contentType = response.headers.get('content-type') ?? '';
|
|
14189
|
-
//
|
|
14183
|
+
// Safari 10.1-14.4 ships fetch without `Response.body`, and the SDK's
|
|
14184
|
+
// support floor reaches back into that range. There the transfer keeps
|
|
14190
14185
|
// whole-transfer wall-clock semantics: blob() surfaces no chunk arrivals, so
|
|
14191
14186
|
// there is no liveness to observe.
|
|
14192
14187
|
if (!response.body) {
|
|
@@ -15080,7 +15075,7 @@ class SparkVault {
|
|
|
15080
15075
|
}
|
|
15081
15076
|
/** Get the SDK version */
|
|
15082
15077
|
static get version() {
|
|
15083
|
-
return '9.2.
|
|
15078
|
+
return '9.2.2';
|
|
15084
15079
|
}
|
|
15085
15080
|
}
|
|
15086
15081
|
if (typeof window !== 'undefined') {
|