@sparkvault/sdk-js 9.2.0 → 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 +199 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.mjs +199 -129
- 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 +45 -33
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2584,8 +2584,11 @@ declare class IngotsModule {
|
|
|
2584
2584
|
*/
|
|
2585
2585
|
private requestUploadSession;
|
|
2586
2586
|
/**
|
|
2587
|
-
* Run the canonical TUS transfer for a created/replaced ingot
|
|
2588
|
-
*
|
|
2587
|
+
* Run the canonical TUS transfer for a created/replaced ingot.
|
|
2588
|
+
*
|
|
2589
|
+
* The transfer resolves only once the server has confirmed finalization, so
|
|
2590
|
+
* the ingot this returns is always a published one — never a stored file
|
|
2591
|
+
* whose ingot never went active.
|
|
2589
2592
|
*/
|
|
2590
2593
|
private transferAndFinalize;
|
|
2591
2594
|
private validateFile;
|
package/dist/index.mjs
CHANGED
|
@@ -9959,17 +9959,25 @@ const CHUNK_INACTIVITY_TIMEOUT_MS = 60000;
|
|
|
9959
9959
|
const CHUNK_MAX_ATTEMPTS = 3;
|
|
9960
9960
|
const CHUNK_RETRY_BASE_MS = 500;
|
|
9961
9961
|
/**
|
|
9962
|
-
*
|
|
9962
|
+
* Retry budget for the finalization receipt.
|
|
9963
9963
|
*
|
|
9964
|
-
*
|
|
9965
|
-
*
|
|
9966
|
-
*
|
|
9967
|
-
*
|
|
9968
|
-
* reach the declared total before reporting success.
|
|
9964
|
+
* Forge answers the zero-length PATCH with a 409 while another writer is still
|
|
9965
|
+
* inside the finalizer, so the confirmation has to out-wait a finalization
|
|
9966
|
+
* already in flight rather than give up on it — a budget measured in seconds
|
|
9967
|
+
* rather than in the sub-second blips a chunk retry recovers from.
|
|
9969
9968
|
*/
|
|
9970
|
-
const
|
|
9971
|
-
const
|
|
9972
|
-
/**
|
|
9969
|
+
const FINALIZE_MAX_ATTEMPTS = 10;
|
|
9970
|
+
const FINALIZE_RETRY_MS = 1000;
|
|
9971
|
+
/**
|
|
9972
|
+
* How many consecutive timeouts end the confirmation early.
|
|
9973
|
+
*
|
|
9974
|
+
* A genuinely slow finalize shows up as ONE timeout — the PATCH that started
|
|
9975
|
+
* the re-drive — followed by 409s from the writer that is working on it.
|
|
9976
|
+
* Back-to-back timeouts mean nobody is answering at all, and spending the full
|
|
9977
|
+
* budget on a black-holed socket would freeze the widget at 100% for minutes
|
|
9978
|
+
* with nothing for the user to act on.
|
|
9979
|
+
*/
|
|
9980
|
+
const FINALIZE_MAX_CONSECUTIVE_TIMEOUTS = 2;
|
|
9973
9981
|
/**
|
|
9974
9982
|
* A delay that a cancel cuts short: resolves after `ms`, rejects with the
|
|
9975
9983
|
* canonical cancelled error the moment the signal aborts.
|
|
@@ -9992,33 +10000,46 @@ function abortableDelay(ms, signal) {
|
|
|
9992
10000
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
9993
10001
|
});
|
|
9994
10002
|
}
|
|
9995
|
-
function delay(ms) {
|
|
9996
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
9997
|
-
}
|
|
9998
10003
|
/**
|
|
9999
|
-
* Whether a failed
|
|
10004
|
+
* Whether a failed transfer request is worth another attempt. Every retrying
|
|
10005
|
+
* stage of an upload asks this one question:
|
|
10000
10006
|
*
|
|
10001
|
-
*
|
|
10002
|
-
*
|
|
10003
|
-
*
|
|
10004
|
-
*
|
|
10005
|
-
*
|
|
10006
|
-
*
|
|
10007
|
-
*
|
|
10008
|
-
*
|
|
10009
|
-
|
|
10010
|
-
|
|
10007
|
+
* - the chunk PATCH loop — may this chunk be re-sent?
|
|
10008
|
+
* - the resume-HEAD loop — may the session's offset be re-read?
|
|
10009
|
+
* - the finalization receipt — may publication be asked about again?
|
|
10010
|
+
*
|
|
10011
|
+
* A transport-level failure (status 0 — a dropped connection, a timeout, or
|
|
10012
|
+
* the inactivity watchdog aborting a silent socket) says nothing about whether
|
|
10013
|
+
* the request reached Forge, 409 is Forge's documented "another writer holds
|
|
10014
|
+
* the session lease; re-check and retry" (on the receipt: a finalizer is
|
|
10015
|
+
* running right now), and a 5xx is a server-side blip. Every other outcome is
|
|
10016
|
+
* the server's considered answer about this exact request — a rejected offset,
|
|
10017
|
+
* a bad ISTK, a vanished session, or a 2xx carrying a protocol-violating
|
|
10018
|
+
* offset — and re-sending would only earn it again. A cancelled session is the
|
|
10019
|
+
* user's decision, never a failure to retry.
|
|
10020
|
+
*/
|
|
10021
|
+
function isRetryableTransferFailure(error) {
|
|
10011
10022
|
if (!(error instanceof UploadApiError))
|
|
10012
10023
|
return false;
|
|
10013
10024
|
// Verdicts, not blips: a cancel is the user's decision, and an invalid or
|
|
10014
10025
|
// misaligned offset is a protocol violation the server would only repeat.
|
|
10015
|
-
//
|
|
10016
|
-
//
|
|
10026
|
+
// The code exclusion is load-bearing for the statusCode-0 sites (the resume
|
|
10027
|
+
// and misalignment guards); patchChunk's own invalid_offset rides a 2xx
|
|
10028
|
+
// status the heuristic below would reject anyway.
|
|
10017
10029
|
if (error.code === 'cancelled' || error.code === 'invalid_offset')
|
|
10018
10030
|
return false;
|
|
10019
10031
|
const status = error.statusCode ?? 0;
|
|
10020
10032
|
return status === 0 || status === 409 || status >= 500;
|
|
10021
10033
|
}
|
|
10034
|
+
/**
|
|
10035
|
+
* A server's error body, reduced to something safe to carry on an error:
|
|
10036
|
+
* whitespace collapsed and length clipped, so an HTML error page or a stack
|
|
10037
|
+
* trace can never become the payload.
|
|
10038
|
+
*/
|
|
10039
|
+
const ERROR_DETAIL_MAX_CHARS = 200;
|
|
10040
|
+
function summarizeErrorBody(body) {
|
|
10041
|
+
return body.replace(/\s+/g, ' ').trim().slice(0, ERROR_DETAIL_MAX_CHARS);
|
|
10042
|
+
}
|
|
10022
10043
|
const RESUME_CHECK = {
|
|
10023
10044
|
name: 'Upload resume check',
|
|
10024
10045
|
code: 'resume_check_failed',
|
|
@@ -10029,6 +10050,22 @@ const FINALIZATION_CHECK = {
|
|
|
10029
10050
|
code: 'finalization_check_failed',
|
|
10030
10051
|
networkMessage: 'Unable to confirm upload. Please check your connection and try again.',
|
|
10031
10052
|
};
|
|
10053
|
+
/**
|
|
10054
|
+
* Turn a terminal confirmation failure into something a person can read.
|
|
10055
|
+
*
|
|
10056
|
+
* The upload widget prints `error.message` verbatim, and a bare status line
|
|
10057
|
+
* ("Upload finalization check failed: 500") tells the user nothing about their
|
|
10058
|
+
* file. Only the status-carrying failure is rewritten: a timeout or a
|
|
10059
|
+
* connection failure already explains itself in the user's terms, and its code
|
|
10060
|
+
* is load-bearing taxonomy. The status and the server's own detail move into
|
|
10061
|
+
* `details`, where support can still read them.
|
|
10062
|
+
*/
|
|
10063
|
+
function asFinalizationFailure(error) {
|
|
10064
|
+
if (!(error instanceof UploadApiError) || error.code !== FINALIZATION_CHECK.code) {
|
|
10065
|
+
return error;
|
|
10066
|
+
}
|
|
10067
|
+
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 });
|
|
10068
|
+
}
|
|
10032
10069
|
class UploadApi extends SparkVaultApi {
|
|
10033
10070
|
constructor(config) {
|
|
10034
10071
|
super(config.timeout);
|
|
@@ -10115,8 +10152,9 @@ class UploadApi extends SparkVaultApi {
|
|
|
10115
10152
|
* offset rather than failing the whole transfer — see {@link CHUNK_MAX_ATTEMPTS}
|
|
10116
10153
|
* and {@link readResumeOffset}.
|
|
10117
10154
|
*
|
|
10118
|
-
*
|
|
10119
|
-
*
|
|
10155
|
+
* Resolves only once the server has confirmed finalization
|
|
10156
|
+
* ({@link confirmServerFinalized}), so a caller that gets a resolved promise
|
|
10157
|
+
* is always looking at a published ingot.
|
|
10120
10158
|
*/
|
|
10121
10159
|
async uploadFileToForge(file, forgeUrl, onProgress) {
|
|
10122
10160
|
if (typeof XMLHttpRequest === 'undefined') {
|
|
@@ -10157,38 +10195,33 @@ class UploadApi extends SparkVaultApi {
|
|
|
10157
10195
|
}
|
|
10158
10196
|
catch (error) {
|
|
10159
10197
|
failedAttempts += 1;
|
|
10160
|
-
if (failedAttempts >= CHUNK_MAX_ATTEMPTS || !
|
|
10198
|
+
if (failedAttempts >= CHUNK_MAX_ATTEMPTS || !isRetryableTransferFailure(error)) {
|
|
10161
10199
|
throw error;
|
|
10162
10200
|
}
|
|
10163
10201
|
}
|
|
10164
|
-
//
|
|
10165
|
-
//
|
|
10166
|
-
|
|
10202
|
+
// Resync against server truth before ANY further PATCH: the failed
|
|
10203
|
+
// chunk may have landed (the acknowledgment was lost), and a PATCH at
|
|
10204
|
+
// the client's stale offset is an offset mismatch the server rejects
|
|
10205
|
+
// as a terminal 400. The blip that killed the PATCH is also the
|
|
10206
|
+
// likeliest thing to kill this HEAD moments later, so the HEAD is
|
|
10207
|
+
// retried out of the same per-position budget — the backoff races the
|
|
10208
|
+
// session's abort signal so cancellation stays prompt.
|
|
10167
10209
|
let serverOffset;
|
|
10168
|
-
|
|
10169
|
-
|
|
10170
|
-
|
|
10171
|
-
|
|
10172
|
-
|
|
10173
|
-
// this HEAD moments later. A transient resync failure spends the same
|
|
10174
|
-
// budget as a failed chunk — never the whole transfer, which is the
|
|
10175
|
-
// exact scenario the retry exists for.
|
|
10176
|
-
if (!isRetryableChunkFailure(headError)) {
|
|
10177
|
-
throw headError;
|
|
10210
|
+
for (;;) {
|
|
10211
|
+
await abortableDelay(CHUNK_RETRY_BASE_MS * 2 ** (failedAttempts - 1), this.getAbortSignal());
|
|
10212
|
+
try {
|
|
10213
|
+
serverOffset = await this.readResumeOffset(uploadUrl, file.size, session.chunkSize);
|
|
10214
|
+
break;
|
|
10178
10215
|
}
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10216
|
+
catch (headError) {
|
|
10217
|
+
if (!isRetryableTransferFailure(headError)) {
|
|
10218
|
+
throw headError;
|
|
10219
|
+
}
|
|
10220
|
+
failedAttempts += 1;
|
|
10221
|
+
if (failedAttempts >= CHUNK_MAX_ATTEMPTS) {
|
|
10222
|
+
throw headError;
|
|
10223
|
+
}
|
|
10182
10224
|
}
|
|
10183
|
-
continue;
|
|
10184
|
-
}
|
|
10185
|
-
// Forge advances a session's offset only in whole committed chunks, so a
|
|
10186
|
-
// legitimate resume point is always chunk-aligned (or the file end). A
|
|
10187
|
-
// misaligned offset is a corrupt session, and resuming from it would
|
|
10188
|
-
// send a short non-final chunk Forge rejects anyway — fail it as the
|
|
10189
|
-
// protocol violation it is instead.
|
|
10190
|
-
if (serverOffset % session.chunkSize !== 0 && serverOffset !== file.size) {
|
|
10191
|
-
throw new UploadApiError(`Server returned misaligned upload offset (${serverOffset})`, 'invalid_offset', 0);
|
|
10192
10225
|
}
|
|
10193
10226
|
if (serverOffset > offset) {
|
|
10194
10227
|
// Bytes reached the server despite the failure, so the transfer is
|
|
@@ -10198,25 +10231,85 @@ class UploadApi extends SparkVaultApi {
|
|
|
10198
10231
|
}
|
|
10199
10232
|
offset = serverOffset;
|
|
10200
10233
|
}
|
|
10201
|
-
|
|
10234
|
+
await this.confirmServerFinalized(uploadUrl, file.size);
|
|
10235
|
+
}
|
|
10236
|
+
/**
|
|
10237
|
+
* Confirm the server finalized a fully received upload — the one receipt
|
|
10238
|
+
* every transfer ends on.
|
|
10239
|
+
*
|
|
10240
|
+
* The server persists the session's final offset BEFORE it finalizes, so a
|
|
10241
|
+
* HEAD offset proves receipt and never publication: it can equal the file
|
|
10242
|
+
* size while finalization failed or is still running, and reporting that as
|
|
10243
|
+
* success would hand the user a stored file whose ingot was never published.
|
|
10244
|
+
* The zero-length PATCH at the final offset is the server's finalization
|
|
10245
|
+
* re-drive — it short-circuits to 204 on an already-finalized session, and
|
|
10246
|
+
* on a received-but-unfinalized one it answers only after publication.
|
|
10247
|
+
*
|
|
10248
|
+
* A 409 means another writer is inside the finalizer right now; that is the
|
|
10249
|
+
* outcome the budget exists for, so the retry waits it out rather than
|
|
10250
|
+
* failing a transfer that is about to succeed. A 400 is the opposite — the
|
|
10251
|
+
* server is behind the offset we claim — and fails immediately.
|
|
10252
|
+
*/
|
|
10253
|
+
async confirmServerFinalized(uploadUrl, totalSize) {
|
|
10254
|
+
let consecutiveTimeouts = 0;
|
|
10255
|
+
for (let attempt = 1;; attempt++) {
|
|
10256
|
+
// An already-aborted session must not reach fetch: without
|
|
10257
|
+
// `AbortSignal.any` the combined signal only learns about a close that
|
|
10258
|
+
// arrives later, so the request would otherwise go out post-cancel.
|
|
10259
|
+
if (this.isAborted()) {
|
|
10260
|
+
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
10261
|
+
}
|
|
10262
|
+
try {
|
|
10263
|
+
await this.tusRequest(uploadUrl, {
|
|
10264
|
+
method: 'PATCH',
|
|
10265
|
+
headers: {
|
|
10266
|
+
'Tus-Resumable': TUS_VERSION,
|
|
10267
|
+
'Upload-Offset': String(totalSize),
|
|
10268
|
+
'Content-Type': 'application/offset+octet-stream',
|
|
10269
|
+
},
|
|
10270
|
+
}, FINALIZATION_CHECK);
|
|
10271
|
+
return;
|
|
10272
|
+
}
|
|
10273
|
+
catch (error) {
|
|
10274
|
+
const timedOut = error instanceof UploadApiError && error.code === 'timeout';
|
|
10275
|
+
// Any answer at all — a 409 above all — proves someone is on the other
|
|
10276
|
+
// end, so the timeout tally starts over.
|
|
10277
|
+
consecutiveTimeouts = timedOut ? consecutiveTimeouts + 1 : 0;
|
|
10278
|
+
if (attempt >= FINALIZE_MAX_ATTEMPTS ||
|
|
10279
|
+
consecutiveTimeouts >= FINALIZE_MAX_CONSECUTIVE_TIMEOUTS ||
|
|
10280
|
+
!isRetryableTransferFailure(error)) {
|
|
10281
|
+
throw asFinalizationFailure(error);
|
|
10282
|
+
}
|
|
10283
|
+
await abortableDelay(FINALIZE_RETRY_MS, this.getAbortSignal());
|
|
10284
|
+
}
|
|
10285
|
+
}
|
|
10202
10286
|
}
|
|
10203
10287
|
/**
|
|
10204
|
-
* Read the offset a failed chunk should resume from
|
|
10288
|
+
* Read the offset a failed chunk should resume from — the one place a
|
|
10289
|
+
* server-reported resume point is judged.
|
|
10205
10290
|
*
|
|
10206
10291
|
* Forge commits a chunk before it answers, so a PATCH that died in transit
|
|
10207
10292
|
* may have landed in full or not at all (never in part — the chunk object
|
|
10208
10293
|
* is written atomically before the offset advances); only the session's own
|
|
10209
10294
|
* persisted offset knows which, and the client's arithmetic is worthless
|
|
10210
|
-
* here.
|
|
10211
|
-
*
|
|
10212
|
-
*
|
|
10213
|
-
*
|
|
10295
|
+
* here.
|
|
10296
|
+
*
|
|
10297
|
+
* Two contracts disqualify an answer. TUS sanity: an offset past the
|
|
10298
|
+
* declared total would end the loop early and report a partial upload as
|
|
10299
|
+
* complete, the same trap {@link patchChunk} guards against on a PATCH's own
|
|
10300
|
+
* offset. Forge chunk granularity: a session advances only in whole
|
|
10301
|
+
* committed chunks, so an offset that is neither chunk-aligned nor the file
|
|
10302
|
+
* end is a corrupt session, and resuming from it would send a short
|
|
10303
|
+
* non-final chunk Forge rejects anyway.
|
|
10214
10304
|
*/
|
|
10215
|
-
async readResumeOffset(uploadUrl, totalSize) {
|
|
10305
|
+
async readResumeOffset(uploadUrl, totalSize, chunkSize) {
|
|
10216
10306
|
const offset = await this.headUploadOffset(uploadUrl, RESUME_CHECK);
|
|
10217
10307
|
if (offset > totalSize) {
|
|
10218
10308
|
throw new UploadApiError(`Server returned invalid upload offset (${offset})`, 'invalid_offset', 0);
|
|
10219
10309
|
}
|
|
10310
|
+
if (offset % chunkSize !== 0 && offset !== totalSize) {
|
|
10311
|
+
throw new UploadApiError(`Server returned misaligned upload offset (${offset})`, 'invalid_offset', 0);
|
|
10312
|
+
}
|
|
10220
10313
|
return offset;
|
|
10221
10314
|
}
|
|
10222
10315
|
/**
|
|
@@ -10348,77 +10441,58 @@ class UploadApi extends SparkVaultApi {
|
|
|
10348
10441
|
});
|
|
10349
10442
|
}
|
|
10350
10443
|
/**
|
|
10351
|
-
*
|
|
10352
|
-
*
|
|
10353
|
-
* The TUS PATCH loop trusts a server-provided `Upload-Offset`; a buggy or
|
|
10354
|
-
* malicious Forge could return an inflated offset before every chunk was
|
|
10355
|
-
* actually committed and encrypted. This re-reads the server's own
|
|
10356
|
-
* persisted offset via a TUS HEAD (which Forge only advances on a real S3
|
|
10357
|
-
* commit) and requires it to reach the declared total — the web equivalent
|
|
10358
|
-
* of the mobile SDK's `verifyIngotActive` (status === 'active') guarantee.
|
|
10359
|
-
*
|
|
10360
|
-
* Polls because the final chunk's commit and the offset write can lag the
|
|
10361
|
-
* PATCH acknowledgement by a moment. Throws on a non-2xx HEAD, on a session
|
|
10362
|
-
* that never reaches the expected offset within the poll budget, or on a
|
|
10363
|
-
* cancelled session — never reports a half-finished upload as done.
|
|
10444
|
+
* Read the server's persisted upload offset via a TUS HEAD request — the one
|
|
10445
|
+
* place the client asks Forge where a session really stands.
|
|
10364
10446
|
*
|
|
10365
|
-
* @param
|
|
10366
|
-
* @param expectedOffset - The declared total upload size in bytes.
|
|
10447
|
+
* @param check - Which caller this read serves; shapes the failure copy.
|
|
10367
10448
|
*/
|
|
10368
|
-
async
|
|
10369
|
-
|
|
10370
|
-
|
|
10371
|
-
|
|
10372
|
-
|
|
10373
|
-
}
|
|
10374
|
-
const offset = await this.headUploadOffset(uploadUrl, FINALIZATION_CHECK);
|
|
10375
|
-
lastOffset = offset;
|
|
10376
|
-
if (offset >= expectedOffset) {
|
|
10377
|
-
return;
|
|
10378
|
-
}
|
|
10379
|
-
if (attempt < FINALIZE_POLL_MAX) {
|
|
10380
|
-
await delay(FINALIZE_POLL_MS);
|
|
10381
|
-
}
|
|
10449
|
+
async headUploadOffset(uploadUrl, check) {
|
|
10450
|
+
const response = await this.tusRequest(uploadUrl, { method: 'HEAD', headers: { 'Tus-Resumable': TUS_VERSION } }, check);
|
|
10451
|
+
const header = response.headers.get('Upload-Offset');
|
|
10452
|
+
const offset = header !== null ? parseInt(header, 10) : NaN;
|
|
10453
|
+
if (!Number.isFinite(offset) || offset < 0) {
|
|
10454
|
+
throw new UploadApiError(`${check.name} returned an invalid offset`, check.code, response.status);
|
|
10382
10455
|
}
|
|
10383
|
-
|
|
10384
|
-
`Confirmed ${lastOffset ?? 0} of ${expectedOffset} bytes.`, 'finalization_unconfirmed', 0, { confirmedBytes: lastOffset ?? 0, expectedBytes: expectedOffset });
|
|
10456
|
+
return offset;
|
|
10385
10457
|
}
|
|
10386
10458
|
/**
|
|
10387
|
-
*
|
|
10388
|
-
*
|
|
10389
|
-
* mid-upload resume and end-of-upload confirmation.
|
|
10459
|
+
* Issue one bodyless TUS request — the single transport behind every
|
|
10460
|
+
* non-chunk call this client makes (resume HEAD, finalization PATCH).
|
|
10390
10461
|
*
|
|
10391
|
-
* Uses raw `fetch` rather than the JSON envelope helper: TUS responses
|
|
10392
|
-
*
|
|
10393
|
-
*
|
|
10394
|
-
*
|
|
10462
|
+
* Uses raw `fetch` rather than the JSON envelope helper: TUS responses carry
|
|
10463
|
+
* an empty body and surface state in headers. Honors the session abort
|
|
10464
|
+
* signal and request timeout like every other client call, and resolves only
|
|
10465
|
+
* on a 2xx so no caller has to re-check `response.ok`.
|
|
10395
10466
|
*
|
|
10396
|
-
* @param check - Which caller this
|
|
10467
|
+
* @param check - Which caller this request serves; shapes the failure copy.
|
|
10397
10468
|
*/
|
|
10398
|
-
async
|
|
10469
|
+
async tusRequest(uploadUrl, init, check) {
|
|
10470
|
+
// Capture the session's close signal now, not in the catch: resetSession()
|
|
10471
|
+
// can swap the controller while this request is in flight, and reading the
|
|
10472
|
+
// live one would misreport a genuine cancel as a timeout.
|
|
10399
10473
|
const closeSignal = this.getAbortSignal();
|
|
10400
|
-
const { signal
|
|
10474
|
+
const { signal, dispose } = combineTimeoutAndCloseSignals(this.timeoutMs, closeSignal);
|
|
10401
10475
|
try {
|
|
10402
10476
|
const response = await fetch(uploadUrl, {
|
|
10403
|
-
method:
|
|
10404
|
-
headers:
|
|
10405
|
-
signal
|
|
10477
|
+
method: init.method,
|
|
10478
|
+
headers: init.headers,
|
|
10479
|
+
signal,
|
|
10406
10480
|
});
|
|
10407
10481
|
if (!response.ok) {
|
|
10408
|
-
|
|
10482
|
+
// Read the body even though the message does not need it: an unread
|
|
10483
|
+
// body pins its connection, and a retried receipt would strand one per
|
|
10484
|
+
// attempt. What it says is the only server-side detail this client
|
|
10485
|
+
// ever sees, so it rides along in `details` for support.
|
|
10486
|
+
const detail = summarizeErrorBody(await response.text().catch(() => ''));
|
|
10487
|
+
throw new UploadApiError(`${check.name} failed: ${response.status}`, check.code, response.status, detail ? { serverDetail: detail } : undefined);
|
|
10409
10488
|
}
|
|
10410
|
-
|
|
10411
|
-
const offset = header !== null ? parseInt(header, 10) : NaN;
|
|
10412
|
-
if (!Number.isFinite(offset) || offset < 0) {
|
|
10413
|
-
throw new UploadApiError(`${check.name} returned an invalid offset`, check.code, response.status);
|
|
10414
|
-
}
|
|
10415
|
-
return offset;
|
|
10489
|
+
return response;
|
|
10416
10490
|
}
|
|
10417
10491
|
catch (error) {
|
|
10418
10492
|
if (error instanceof SparkVaultError)
|
|
10419
10493
|
throw error;
|
|
10420
10494
|
if (error != null && typeof error === 'object' && 'name' in error && error.name === 'AbortError') {
|
|
10421
|
-
if (
|
|
10495
|
+
if (closeSignal.aborted) {
|
|
10422
10496
|
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
10423
10497
|
}
|
|
10424
10498
|
throw new UploadApiError(`${check.name} timed out after ${this.timeoutMs}ms`, 'timeout', 0);
|
|
@@ -12812,8 +12886,10 @@ class UploadRenderer {
|
|
|
12812
12886
|
progress: 0,
|
|
12813
12887
|
bytesUploaded: 0,
|
|
12814
12888
|
});
|
|
12815
|
-
// Upload file over the canonical TUS transfer path
|
|
12816
|
-
|
|
12889
|
+
// Upload file over the canonical TUS transfer path. It resolves only
|
|
12890
|
+
// once the server has confirmed finalization, so a non-finalized upload
|
|
12891
|
+
// throws here and never reaches the success ceremony.
|
|
12892
|
+
await this.api.uploadFileToForge(file, forgeUrl, (bytesUploaded, bytesTotal) => {
|
|
12817
12893
|
const progress = Math.round((bytesUploaded / bytesTotal) * 100);
|
|
12818
12894
|
this.setState({
|
|
12819
12895
|
view: 'uploading',
|
|
@@ -12830,12 +12906,6 @@ class UploadRenderer {
|
|
|
12830
12906
|
phase: 'uploading',
|
|
12831
12907
|
});
|
|
12832
12908
|
});
|
|
12833
|
-
// Confirm the server actually finalized the upload before celebrating.
|
|
12834
|
-
// The TUS loop trusts a server-provided offset; this re-reads the
|
|
12835
|
-
// server's own persisted offset and requires it to reach the file size,
|
|
12836
|
-
// mirroring the mobile SDK's active-status check. A non-finalized
|
|
12837
|
-
// upload throws here and never reaches the success ceremony.
|
|
12838
|
-
await this.api.verifyUploadFinalized(uploadUrl, file.size);
|
|
12839
12909
|
// Run ceremony animation
|
|
12840
12910
|
await this.runCeremony(file, ingotId, requestId);
|
|
12841
12911
|
// Complete
|
|
@@ -13937,15 +14007,14 @@ class IngotsModule {
|
|
|
13937
14007
|
return response.data;
|
|
13938
14008
|
}
|
|
13939
14009
|
/**
|
|
13940
|
-
* Run the canonical TUS transfer for a created/replaced ingot
|
|
13941
|
-
*
|
|
14010
|
+
* Run the canonical TUS transfer for a created/replaced ingot.
|
|
14011
|
+
*
|
|
14012
|
+
* The transfer resolves only once the server has confirmed finalization, so
|
|
14013
|
+
* the ingot this returns is always a published one — never a stored file
|
|
14014
|
+
* whose ingot never went active.
|
|
13942
14015
|
*/
|
|
13943
14016
|
async transferAndFinalize(created, file, onProgress) {
|
|
13944
|
-
|
|
13945
|
-
// Confirm the server actually finalized the upload before reporting
|
|
13946
|
-
// success — the TUS loop's offsets alone don't prove the final chunk
|
|
13947
|
-
// committed and the ingot went active.
|
|
13948
|
-
await this.uploadApi.verifyUploadFinalized(uploadUrl, file.size);
|
|
14017
|
+
await this.uploadApi.uploadFileToForge(file, created.forge_url, onProgress);
|
|
13949
14018
|
return {
|
|
13950
14019
|
id: created.ingot_id,
|
|
13951
14020
|
name: created.name,
|
|
@@ -14107,7 +14176,8 @@ async function fetchBlobWithLivenessBounds(url) {
|
|
|
14107
14176
|
throw error;
|
|
14108
14177
|
}
|
|
14109
14178
|
const contentType = response.headers.get('content-type') ?? '';
|
|
14110
|
-
//
|
|
14179
|
+
// Safari 10.1-14.4 ships fetch without `Response.body`, and the SDK's
|
|
14180
|
+
// support floor reaches back into that range. There the transfer keeps
|
|
14111
14181
|
// whole-transfer wall-clock semantics: blob() surfaces no chunk arrivals, so
|
|
14112
14182
|
// there is no liveness to observe.
|
|
14113
14183
|
if (!response.body) {
|
|
@@ -15001,7 +15071,7 @@ class SparkVault {
|
|
|
15001
15071
|
}
|
|
15002
15072
|
/** Get the SDK version */
|
|
15003
15073
|
static get version() {
|
|
15004
|
-
return '9.2.
|
|
15074
|
+
return '9.2.2';
|
|
15005
15075
|
}
|
|
15006
15076
|
}
|
|
15007
15077
|
if (typeof window !== 'undefined') {
|