@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.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,33 +10004,46 @@ 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
|
|
10018
10029
|
// misaligned offset is a protocol violation the server would only repeat.
|
|
10019
|
-
//
|
|
10020
|
-
//
|
|
10030
|
+
// The code exclusion is load-bearing for the statusCode-0 sites (the resume
|
|
10031
|
+
// and misalignment guards); patchChunk's own invalid_offset rides a 2xx
|
|
10032
|
+
// status the heuristic below would reject anyway.
|
|
10021
10033
|
if (error.code === 'cancelled' || error.code === 'invalid_offset')
|
|
10022
10034
|
return false;
|
|
10023
10035
|
const status = error.statusCode ?? 0;
|
|
10024
10036
|
return status === 0 || status === 409 || status >= 500;
|
|
10025
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
|
+
}
|
|
10026
10047
|
const RESUME_CHECK = {
|
|
10027
10048
|
name: 'Upload resume check',
|
|
10028
10049
|
code: 'resume_check_failed',
|
|
@@ -10033,6 +10054,22 @@ const FINALIZATION_CHECK = {
|
|
|
10033
10054
|
code: 'finalization_check_failed',
|
|
10034
10055
|
networkMessage: 'Unable to confirm upload. Please check your connection and try again.',
|
|
10035
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
|
+
}
|
|
10036
10073
|
class UploadApi extends SparkVaultApi {
|
|
10037
10074
|
constructor(config) {
|
|
10038
10075
|
super(config.timeout);
|
|
@@ -10119,8 +10156,9 @@ class UploadApi extends SparkVaultApi {
|
|
|
10119
10156
|
* offset rather than failing the whole transfer — see {@link CHUNK_MAX_ATTEMPTS}
|
|
10120
10157
|
* and {@link readResumeOffset}.
|
|
10121
10158
|
*
|
|
10122
|
-
*
|
|
10123
|
-
*
|
|
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.
|
|
10124
10162
|
*/
|
|
10125
10163
|
async uploadFileToForge(file, forgeUrl, onProgress) {
|
|
10126
10164
|
if (typeof XMLHttpRequest === 'undefined') {
|
|
@@ -10161,38 +10199,33 @@ class UploadApi extends SparkVaultApi {
|
|
|
10161
10199
|
}
|
|
10162
10200
|
catch (error) {
|
|
10163
10201
|
failedAttempts += 1;
|
|
10164
|
-
if (failedAttempts >= CHUNK_MAX_ATTEMPTS || !
|
|
10202
|
+
if (failedAttempts >= CHUNK_MAX_ATTEMPTS || !isRetryableTransferFailure(error)) {
|
|
10165
10203
|
throw error;
|
|
10166
10204
|
}
|
|
10167
10205
|
}
|
|
10168
|
-
//
|
|
10169
|
-
//
|
|
10170
|
-
|
|
10206
|
+
// Resync against server truth before ANY further PATCH: the failed
|
|
10207
|
+
// chunk may have landed (the acknowledgment was lost), and a PATCH at
|
|
10208
|
+
// the client's stale offset is an offset mismatch the server rejects
|
|
10209
|
+
// as a terminal 400. The blip that killed the PATCH is also the
|
|
10210
|
+
// likeliest thing to kill this HEAD moments later, so the HEAD is
|
|
10211
|
+
// retried out of the same per-position budget — the backoff races the
|
|
10212
|
+
// session's abort signal so cancellation stays prompt.
|
|
10171
10213
|
let serverOffset;
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
|
|
10175
|
-
|
|
10176
|
-
|
|
10177
|
-
// this HEAD moments later. A transient resync failure spends the same
|
|
10178
|
-
// budget as a failed chunk — never the whole transfer, which is the
|
|
10179
|
-
// exact scenario the retry exists for.
|
|
10180
|
-
if (!isRetryableChunkFailure(headError)) {
|
|
10181
|
-
throw headError;
|
|
10214
|
+
for (;;) {
|
|
10215
|
+
await abortableDelay(CHUNK_RETRY_BASE_MS * 2 ** (failedAttempts - 1), this.getAbortSignal());
|
|
10216
|
+
try {
|
|
10217
|
+
serverOffset = await this.readResumeOffset(uploadUrl, file.size, session.chunkSize);
|
|
10218
|
+
break;
|
|
10182
10219
|
}
|
|
10183
|
-
|
|
10184
|
-
|
|
10185
|
-
|
|
10220
|
+
catch (headError) {
|
|
10221
|
+
if (!isRetryableTransferFailure(headError)) {
|
|
10222
|
+
throw headError;
|
|
10223
|
+
}
|
|
10224
|
+
failedAttempts += 1;
|
|
10225
|
+
if (failedAttempts >= CHUNK_MAX_ATTEMPTS) {
|
|
10226
|
+
throw headError;
|
|
10227
|
+
}
|
|
10186
10228
|
}
|
|
10187
|
-
continue;
|
|
10188
|
-
}
|
|
10189
|
-
// Forge advances a session's offset only in whole committed chunks, so a
|
|
10190
|
-
// legitimate resume point is always chunk-aligned (or the file end). A
|
|
10191
|
-
// misaligned offset is a corrupt session, and resuming from it would
|
|
10192
|
-
// send a short non-final chunk Forge rejects anyway — fail it as the
|
|
10193
|
-
// protocol violation it is instead.
|
|
10194
|
-
if (serverOffset % session.chunkSize !== 0 && serverOffset !== file.size) {
|
|
10195
|
-
throw new UploadApiError(`Server returned misaligned upload offset (${serverOffset})`, 'invalid_offset', 0);
|
|
10196
10229
|
}
|
|
10197
10230
|
if (serverOffset > offset) {
|
|
10198
10231
|
// Bytes reached the server despite the failure, so the transfer is
|
|
@@ -10202,25 +10235,85 @@ class UploadApi extends SparkVaultApi {
|
|
|
10202
10235
|
}
|
|
10203
10236
|
offset = serverOffset;
|
|
10204
10237
|
}
|
|
10205
|
-
|
|
10238
|
+
await this.confirmServerFinalized(uploadUrl, file.size);
|
|
10239
|
+
}
|
|
10240
|
+
/**
|
|
10241
|
+
* Confirm the server finalized a fully received upload — the one receipt
|
|
10242
|
+
* every transfer ends on.
|
|
10243
|
+
*
|
|
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.
|
|
10256
|
+
*/
|
|
10257
|
+
async confirmServerFinalized(uploadUrl, totalSize) {
|
|
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.
|
|
10263
|
+
if (this.isAborted()) {
|
|
10264
|
+
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
10265
|
+
}
|
|
10266
|
+
try {
|
|
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;
|
|
10276
|
+
}
|
|
10277
|
+
catch (error) {
|
|
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);
|
|
10286
|
+
}
|
|
10287
|
+
await abortableDelay(FINALIZE_RETRY_MS, this.getAbortSignal());
|
|
10288
|
+
}
|
|
10289
|
+
}
|
|
10206
10290
|
}
|
|
10207
10291
|
/**
|
|
10208
|
-
* 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.
|
|
10209
10294
|
*
|
|
10210
10295
|
* Forge commits a chunk before it answers, so a PATCH that died in transit
|
|
10211
10296
|
* may have landed in full or not at all (never in part — the chunk object
|
|
10212
10297
|
* is written atomically before the offset advances); only the session's own
|
|
10213
10298
|
* persisted offset knows which, and the client's arithmetic is worthless
|
|
10214
|
-
* here.
|
|
10215
|
-
*
|
|
10216
|
-
*
|
|
10217
|
-
*
|
|
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.
|
|
10218
10308
|
*/
|
|
10219
|
-
async readResumeOffset(uploadUrl, totalSize) {
|
|
10309
|
+
async readResumeOffset(uploadUrl, totalSize, chunkSize) {
|
|
10220
10310
|
const offset = await this.headUploadOffset(uploadUrl, RESUME_CHECK);
|
|
10221
10311
|
if (offset > totalSize) {
|
|
10222
10312
|
throw new UploadApiError(`Server returned invalid upload offset (${offset})`, 'invalid_offset', 0);
|
|
10223
10313
|
}
|
|
10314
|
+
if (offset % chunkSize !== 0 && offset !== totalSize) {
|
|
10315
|
+
throw new UploadApiError(`Server returned misaligned upload offset (${offset})`, 'invalid_offset', 0);
|
|
10316
|
+
}
|
|
10224
10317
|
return offset;
|
|
10225
10318
|
}
|
|
10226
10319
|
/**
|
|
@@ -10352,77 +10445,58 @@ class UploadApi extends SparkVaultApi {
|
|
|
10352
10445
|
});
|
|
10353
10446
|
}
|
|
10354
10447
|
/**
|
|
10355
|
-
*
|
|
10356
|
-
*
|
|
10357
|
-
* The TUS PATCH loop trusts a server-provided `Upload-Offset`; a buggy or
|
|
10358
|
-
* malicious Forge could return an inflated offset before every chunk was
|
|
10359
|
-
* actually committed and encrypted. This re-reads the server's own
|
|
10360
|
-
* persisted offset via a TUS HEAD (which Forge only advances on a real S3
|
|
10361
|
-
* commit) and requires it to reach the declared total — the web equivalent
|
|
10362
|
-
* of the mobile SDK's `verifyIngotActive` (status === 'active') guarantee.
|
|
10363
|
-
*
|
|
10364
|
-
* Polls because the final chunk's commit and the offset write can lag the
|
|
10365
|
-
* PATCH acknowledgement by a moment. Throws on a non-2xx HEAD, on a session
|
|
10366
|
-
* that never reaches the expected offset within the poll budget, or on a
|
|
10367
|
-
* 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.
|
|
10368
10450
|
*
|
|
10369
|
-
* @param
|
|
10370
|
-
* @param expectedOffset - The declared total upload size in bytes.
|
|
10451
|
+
* @param check - Which caller this read serves; shapes the failure copy.
|
|
10371
10452
|
*/
|
|
10372
|
-
async
|
|
10373
|
-
|
|
10374
|
-
|
|
10375
|
-
|
|
10376
|
-
|
|
10377
|
-
}
|
|
10378
|
-
const offset = await this.headUploadOffset(uploadUrl, FINALIZATION_CHECK);
|
|
10379
|
-
lastOffset = offset;
|
|
10380
|
-
if (offset >= expectedOffset) {
|
|
10381
|
-
return;
|
|
10382
|
-
}
|
|
10383
|
-
if (attempt < FINALIZE_POLL_MAX) {
|
|
10384
|
-
await delay(FINALIZE_POLL_MS);
|
|
10385
|
-
}
|
|
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);
|
|
10386
10459
|
}
|
|
10387
|
-
|
|
10388
|
-
`Confirmed ${lastOffset ?? 0} of ${expectedOffset} bytes.`, 'finalization_unconfirmed', 0, { confirmedBytes: lastOffset ?? 0, expectedBytes: expectedOffset });
|
|
10460
|
+
return offset;
|
|
10389
10461
|
}
|
|
10390
10462
|
/**
|
|
10391
|
-
*
|
|
10392
|
-
*
|
|
10393
|
-
* 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).
|
|
10394
10465
|
*
|
|
10395
|
-
* Uses raw `fetch` rather than the JSON envelope helper: TUS responses
|
|
10396
|
-
*
|
|
10397
|
-
*
|
|
10398
|
-
*
|
|
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`.
|
|
10399
10470
|
*
|
|
10400
|
-
* @param check - Which caller this
|
|
10471
|
+
* @param check - Which caller this request serves; shapes the failure copy.
|
|
10401
10472
|
*/
|
|
10402
|
-
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.
|
|
10403
10477
|
const closeSignal = this.getAbortSignal();
|
|
10404
|
-
const { signal
|
|
10478
|
+
const { signal, dispose } = combineTimeoutAndCloseSignals(this.timeoutMs, closeSignal);
|
|
10405
10479
|
try {
|
|
10406
10480
|
const response = await fetch(uploadUrl, {
|
|
10407
|
-
method:
|
|
10408
|
-
headers:
|
|
10409
|
-
signal
|
|
10481
|
+
method: init.method,
|
|
10482
|
+
headers: init.headers,
|
|
10483
|
+
signal,
|
|
10410
10484
|
});
|
|
10411
10485
|
if (!response.ok) {
|
|
10412
|
-
|
|
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);
|
|
10413
10492
|
}
|
|
10414
|
-
|
|
10415
|
-
const offset = header !== null ? parseInt(header, 10) : NaN;
|
|
10416
|
-
if (!Number.isFinite(offset) || offset < 0) {
|
|
10417
|
-
throw new UploadApiError(`${check.name} returned an invalid offset`, check.code, response.status);
|
|
10418
|
-
}
|
|
10419
|
-
return offset;
|
|
10493
|
+
return response;
|
|
10420
10494
|
}
|
|
10421
10495
|
catch (error) {
|
|
10422
10496
|
if (error instanceof SparkVaultError)
|
|
10423
10497
|
throw error;
|
|
10424
10498
|
if (error != null && typeof error === 'object' && 'name' in error && error.name === 'AbortError') {
|
|
10425
|
-
if (
|
|
10499
|
+
if (closeSignal.aborted) {
|
|
10426
10500
|
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
10427
10501
|
}
|
|
10428
10502
|
throw new UploadApiError(`${check.name} timed out after ${this.timeoutMs}ms`, 'timeout', 0);
|
|
@@ -12816,8 +12890,10 @@ class UploadRenderer {
|
|
|
12816
12890
|
progress: 0,
|
|
12817
12891
|
bytesUploaded: 0,
|
|
12818
12892
|
});
|
|
12819
|
-
// Upload file over the canonical TUS transfer path
|
|
12820
|
-
|
|
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) => {
|
|
12821
12897
|
const progress = Math.round((bytesUploaded / bytesTotal) * 100);
|
|
12822
12898
|
this.setState({
|
|
12823
12899
|
view: 'uploading',
|
|
@@ -12834,12 +12910,6 @@ class UploadRenderer {
|
|
|
12834
12910
|
phase: 'uploading',
|
|
12835
12911
|
});
|
|
12836
12912
|
});
|
|
12837
|
-
// Confirm the server actually finalized the upload before celebrating.
|
|
12838
|
-
// The TUS loop trusts a server-provided offset; this re-reads the
|
|
12839
|
-
// server's own persisted offset and requires it to reach the file size,
|
|
12840
|
-
// mirroring the mobile SDK's active-status check. A non-finalized
|
|
12841
|
-
// upload throws here and never reaches the success ceremony.
|
|
12842
|
-
await this.api.verifyUploadFinalized(uploadUrl, file.size);
|
|
12843
12913
|
// Run ceremony animation
|
|
12844
12914
|
await this.runCeremony(file, ingotId, requestId);
|
|
12845
12915
|
// Complete
|
|
@@ -13941,15 +14011,14 @@ class IngotsModule {
|
|
|
13941
14011
|
return response.data;
|
|
13942
14012
|
}
|
|
13943
14013
|
/**
|
|
13944
|
-
* Run the canonical TUS transfer for a created/replaced ingot
|
|
13945
|
-
*
|
|
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.
|
|
13946
14019
|
*/
|
|
13947
14020
|
async transferAndFinalize(created, file, onProgress) {
|
|
13948
|
-
|
|
13949
|
-
// Confirm the server actually finalized the upload before reporting
|
|
13950
|
-
// success — the TUS loop's offsets alone don't prove the final chunk
|
|
13951
|
-
// committed and the ingot went active.
|
|
13952
|
-
await this.uploadApi.verifyUploadFinalized(uploadUrl, file.size);
|
|
14021
|
+
await this.uploadApi.uploadFileToForge(file, created.forge_url, onProgress);
|
|
13953
14022
|
return {
|
|
13954
14023
|
id: created.ingot_id,
|
|
13955
14024
|
name: created.name,
|
|
@@ -14111,7 +14180,8 @@ async function fetchBlobWithLivenessBounds(url) {
|
|
|
14111
14180
|
throw error;
|
|
14112
14181
|
}
|
|
14113
14182
|
const contentType = response.headers.get('content-type') ?? '';
|
|
14114
|
-
//
|
|
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
|
|
14115
14185
|
// whole-transfer wall-clock semantics: blob() surfaces no chunk arrivals, so
|
|
14116
14186
|
// there is no liveness to observe.
|
|
14117
14187
|
if (!response.body) {
|
|
@@ -15005,7 +15075,7 @@ class SparkVault {
|
|
|
15005
15075
|
}
|
|
15006
15076
|
/** Get the SDK version */
|
|
15007
15077
|
static get version() {
|
|
15008
|
-
return '9.2.
|
|
15078
|
+
return '9.2.2';
|
|
15009
15079
|
}
|
|
15010
15080
|
}
|
|
15011
15081
|
if (typeof window !== 'undefined') {
|