@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.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, then confirm
2588
- * the server finalized the upload before reporting success.
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
- * Server-side finalization confirmation poll.
9962
+ * Retry budget for the finalization receipt.
9963
9963
  *
9964
- * After the last chunk is PATCHed, Forge advances the session offset (and
9965
- * flips the ingot to `active`) only once the chunk has actually committed to
9966
- * S3. We re-read the server's *own persisted* `Upload-Offset` via a TUS HEAD
9967
- * — independent of the offset the PATCH response claimed — and require it to
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 FINALIZE_POLL_MAX = 10;
9971
- const FINALIZE_POLL_MS = 1000;
9972
- /** Promise-wrapped delay, for retry backoff and finalization polling. */
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,22 +10000,25 @@ 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 chunk PATCH is worth another attempt.
10004
+ * Whether a failed transfer request is worth another attempt. Every retrying
10005
+ * stage of an upload asks this one question:
10000
10006
  *
10001
- * A transport-level failure (status 0 — a dropped connection, or the
10002
- * inactivity watchdog aborting a silent socket) says nothing about whether the
10003
- * bytes reached Forge, 409 is Forge's documented "another writer holds the
10004
- * session lease; re-check the offset and retry", and a 5xx is a server-side
10005
- * blip. Every other outcome is the server's considered answer about this exact
10006
- * chunk — a rejected offset, a bad ISTK, a vanished session, or a 2xx carrying
10007
- * a protocol-violating offset — and re-sending would only earn it again. A
10008
- * cancelled session is the user's decision, never a failure to retry.
10009
- */
10010
- function isRetryableChunkFailure(error) {
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
@@ -10020,6 +10031,15 @@ function isRetryableChunkFailure(error) {
10020
10031
  const status = error.statusCode ?? 0;
10021
10032
  return status === 0 || status === 409 || status >= 500;
10022
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
+ }
10023
10043
  const RESUME_CHECK = {
10024
10044
  name: 'Upload resume check',
10025
10045
  code: 'resume_check_failed',
@@ -10030,6 +10050,22 @@ const FINALIZATION_CHECK = {
10030
10050
  code: 'finalization_check_failed',
10031
10051
  networkMessage: 'Unable to confirm upload. Please check your connection and try again.',
10032
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
+ }
10033
10069
  class UploadApi extends SparkVaultApi {
10034
10070
  constructor(config) {
10035
10071
  super(config.timeout);
@@ -10116,8 +10152,9 @@ class UploadApi extends SparkVaultApi {
10116
10152
  * offset rather than failing the whole transfer — see {@link CHUNK_MAX_ATTEMPTS}
10117
10153
  * and {@link readResumeOffset}.
10118
10154
  *
10119
- * Returns the TUS session URL so the caller can confirm server-side
10120
- * finalization via {@link verifyUploadFinalized} before reporting success.
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.
10121
10158
  */
10122
10159
  async uploadFileToForge(file, forgeUrl, onProgress) {
10123
10160
  if (typeof XMLHttpRequest === 'undefined') {
@@ -10146,13 +10183,6 @@ class UploadApi extends SparkVaultApi {
10146
10183
  }
10147
10184
  }
10148
10185
  : undefined;
10149
- // A successful final-chunk PATCH is the server's finalization receipt:
10150
- // Forge finalizes (publishes the ingot, moves the counters) BEFORE it
10151
- // acknowledges that chunk with a 204. An offset learned from a resume
10152
- // HEAD carries no such receipt — the server persists the final offset
10153
- // before it finalizes — so a completion reached through the resume path
10154
- // must be confirmed explicitly after the loop.
10155
- let finalizeAcknowledged = false;
10156
10186
  while (offset < file.size) {
10157
10187
  if (this.isAborted()) {
10158
10188
  throw new UploadApiError('Upload cancelled', 'cancelled', 0);
@@ -10161,14 +10191,11 @@ class UploadApi extends SparkVaultApi {
10161
10191
  try {
10162
10192
  offset = await this.patchChunk(uploadUrl, file.slice(offset, chunkEnd), offset, file.size, monotonicProgress);
10163
10193
  failedAttempts = 0;
10164
- if (offset >= file.size) {
10165
- finalizeAcknowledged = true;
10166
- }
10167
10194
  continue;
10168
10195
  }
10169
10196
  catch (error) {
10170
10197
  failedAttempts += 1;
10171
- if (failedAttempts >= CHUNK_MAX_ATTEMPTS || !isRetryableChunkFailure(error)) {
10198
+ if (failedAttempts >= CHUNK_MAX_ATTEMPTS || !isRetryableTransferFailure(error)) {
10172
10199
  throw error;
10173
10200
  }
10174
10201
  }
@@ -10183,11 +10210,11 @@ class UploadApi extends SparkVaultApi {
10183
10210
  for (;;) {
10184
10211
  await abortableDelay(CHUNK_RETRY_BASE_MS * 2 ** (failedAttempts - 1), this.getAbortSignal());
10185
10212
  try {
10186
- serverOffset = await this.readResumeOffset(uploadUrl, file.size);
10213
+ serverOffset = await this.readResumeOffset(uploadUrl, file.size, session.chunkSize);
10187
10214
  break;
10188
10215
  }
10189
10216
  catch (headError) {
10190
- if (!isRetryableChunkFailure(headError)) {
10217
+ if (!isRetryableTransferFailure(headError)) {
10191
10218
  throw headError;
10192
10219
  }
10193
10220
  failedAttempts += 1;
@@ -10196,14 +10223,6 @@ class UploadApi extends SparkVaultApi {
10196
10223
  }
10197
10224
  }
10198
10225
  }
10199
- // Forge advances a session's offset only in whole committed chunks, so a
10200
- // legitimate resume point is always chunk-aligned (or the file end). A
10201
- // misaligned offset is a corrupt session, and resuming from it would
10202
- // send a short non-final chunk Forge rejects anyway — fail it as the
10203
- // protocol violation it is instead.
10204
- if (serverOffset % session.chunkSize !== 0 && serverOffset !== file.size) {
10205
- throw new UploadApiError(`Server returned misaligned upload offset (${serverOffset})`, 'invalid_offset', 0);
10206
- }
10207
10226
  if (serverOffset > offset) {
10208
10227
  // Bytes reached the server despite the failure, so the transfer is
10209
10228
  // alive: the budget is earned back rather than spent down across the
@@ -10212,86 +10231,85 @@ class UploadApi extends SparkVaultApi {
10212
10231
  }
10213
10232
  offset = serverOffset;
10214
10233
  }
10215
- if (!finalizeAcknowledged) {
10216
- await this.confirmServerFinalized(uploadUrl, file.size);
10217
- }
10218
- return uploadUrl;
10234
+ await this.confirmServerFinalized(uploadUrl, file.size);
10219
10235
  }
10220
10236
  /**
10221
- * Confirm the server finalized a fully received upload.
10237
+ * Confirm the server finalized a fully received upload — the one receipt
10238
+ * every transfer ends on.
10222
10239
  *
10223
- * The server persists the session's final offset BEFORE it finalizes, so an
10224
- * offset read from a resume HEAD can equal the file size while finalization
10225
- * failed or is still running — treating that offset as success would report
10226
- * a stored file whose ingot was never published. The zero-length PATCH at
10227
- * the final offset is the server's finalization re-drive: it answers 2xx
10228
- * only once finalization has actually completed, the same receipt a
10229
- * successful final chunk carries.
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.
10230
10252
  */
10231
10253
  async confirmServerFinalized(uploadUrl, totalSize) {
10232
- let attempts = 0;
10233
- for (;;) {
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.
10234
10259
  if (this.isAborted()) {
10235
10260
  throw new UploadApiError('Upload cancelled', 'cancelled', 0);
10236
10261
  }
10237
- const closeSignal = this.getAbortSignal();
10238
- const { signal, dispose } = combineTimeoutAndCloseSignals(this.timeoutMs, closeSignal);
10239
10262
  try {
10240
- let response;
10241
- try {
10242
- response = await fetch(uploadUrl, {
10243
- method: 'PATCH',
10244
- headers: {
10245
- 'Tus-Resumable': TUS_VERSION,
10246
- 'Upload-Offset': String(totalSize),
10247
- 'Content-Type': 'application/offset+octet-stream',
10248
- },
10249
- signal,
10250
- });
10251
- }
10252
- catch {
10253
- if (closeSignal.aborted) {
10254
- throw new UploadApiError('Upload cancelled', 'cancelled', 0);
10255
- }
10256
- throw new UploadApiError('Upload finalization check failed: network error', 'finalization_check_failed', 0);
10257
- }
10258
- if (response.ok) {
10259
- return;
10260
- }
10261
- throw new UploadApiError(`Upload finalization check failed: ${response.status}`, 'finalization_check_failed', response.status);
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;
10262
10272
  }
10263
10273
  catch (error) {
10264
- if (!isRetryableChunkFailure(error)) {
10265
- throw error;
10266
- }
10267
- attempts += 1;
10268
- if (attempts >= CHUNK_MAX_ATTEMPTS) {
10269
- throw 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);
10270
10282
  }
10271
- await abortableDelay(CHUNK_RETRY_BASE_MS * 2 ** (attempts - 1), this.getAbortSignal());
10272
- }
10273
- finally {
10274
- dispose();
10283
+ await abortableDelay(FINALIZE_RETRY_MS, this.getAbortSignal());
10275
10284
  }
10276
10285
  }
10277
10286
  }
10278
10287
  /**
10279
- * 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.
10280
10290
  *
10281
10291
  * Forge commits a chunk before it answers, so a PATCH that died in transit
10282
10292
  * may have landed in full or not at all (never in part — the chunk object
10283
10293
  * is written atomically before the offset advances); only the session's own
10284
10294
  * persisted offset knows which, and the client's arithmetic is worthless
10285
- * here. An offset past the declared total is a protocol violation rather
10286
- * than a resume point: honoring it would end the loop early and report a
10287
- * partial upload as complete, the same trap {@link patchChunk} guards
10288
- * against on a PATCH's own offset.
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.
10289
10304
  */
10290
- async readResumeOffset(uploadUrl, totalSize) {
10305
+ async readResumeOffset(uploadUrl, totalSize, chunkSize) {
10291
10306
  const offset = await this.headUploadOffset(uploadUrl, RESUME_CHECK);
10292
10307
  if (offset > totalSize) {
10293
10308
  throw new UploadApiError(`Server returned invalid upload offset (${offset})`, 'invalid_offset', 0);
10294
10309
  }
10310
+ if (offset % chunkSize !== 0 && offset !== totalSize) {
10311
+ throw new UploadApiError(`Server returned misaligned upload offset (${offset})`, 'invalid_offset', 0);
10312
+ }
10295
10313
  return offset;
10296
10314
  }
10297
10315
  /**
@@ -10423,77 +10441,58 @@ class UploadApi extends SparkVaultApi {
10423
10441
  });
10424
10442
  }
10425
10443
  /**
10426
- * Confirm the upload was finalized SERVER-SIDE before reporting success.
10427
- *
10428
- * The TUS PATCH loop trusts a server-provided `Upload-Offset`; a buggy or
10429
- * malicious Forge could return an inflated offset before every chunk was
10430
- * actually committed and encrypted. This re-reads the server's own
10431
- * persisted offset via a TUS HEAD (which Forge only advances on a real S3
10432
- * commit) and requires it to reach the declared total — the web equivalent
10433
- * of the mobile SDK's `verifyIngotActive` (status === 'active') guarantee.
10434
- *
10435
- * Polls because the final chunk's commit and the offset write can lag the
10436
- * PATCH acknowledgement by a moment. Throws on a non-2xx HEAD, on a session
10437
- * that never reaches the expected offset within the poll budget, or on a
10438
- * 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.
10439
10446
  *
10440
- * @param uploadUrl - The TUS session URL (Forge `Location`, ISTK-bound).
10441
- * @param expectedOffset - The declared total upload size in bytes.
10447
+ * @param check - Which caller this read serves; shapes the failure copy.
10442
10448
  */
10443
- async verifyUploadFinalized(uploadUrl, expectedOffset) {
10444
- let lastOffset = null;
10445
- for (let attempt = 1; attempt <= FINALIZE_POLL_MAX; attempt++) {
10446
- if (this.isAborted()) {
10447
- throw new UploadApiError('Upload cancelled', 'cancelled', 0);
10448
- }
10449
- const offset = await this.headUploadOffset(uploadUrl, FINALIZATION_CHECK);
10450
- lastOffset = offset;
10451
- if (offset >= expectedOffset) {
10452
- return;
10453
- }
10454
- if (attempt < FINALIZE_POLL_MAX) {
10455
- await delay(FINALIZE_POLL_MS);
10456
- }
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);
10457
10455
  }
10458
- throw new UploadApiError('Upload could not be confirmed: the server never finalized the file. ' +
10459
- `Confirmed ${lastOffset ?? 0} of ${expectedOffset} bytes.`, 'finalization_unconfirmed', 0, { confirmedBytes: lastOffset ?? 0, expectedBytes: expectedOffset });
10456
+ return offset;
10460
10457
  }
10461
10458
  /**
10462
- * Read the server's persisted upload offset via a TUS HEAD request — the one
10463
- * place the client asks Forge where a session really stands, for both
10464
- * 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).
10465
10461
  *
10466
- * Uses raw `fetch` rather than the JSON envelope helper: TUS responses
10467
- * carry an empty body and surface state in the `Upload-Offset` header.
10468
- * Honors the session abort signal and request timeout like every other
10469
- * client call.
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`.
10470
10466
  *
10471
- * @param check - Which caller this read serves; shapes the failure copy.
10467
+ * @param check - Which caller this request serves; shapes the failure copy.
10472
10468
  */
10473
- async headUploadOffset(uploadUrl, check) {
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.
10474
10473
  const closeSignal = this.getAbortSignal();
10475
- const { signal: combinedSignal, dispose } = combineTimeoutAndCloseSignals(this.timeoutMs, closeSignal);
10474
+ const { signal, dispose } = combineTimeoutAndCloseSignals(this.timeoutMs, closeSignal);
10476
10475
  try {
10477
10476
  const response = await fetch(uploadUrl, {
10478
- method: 'HEAD',
10479
- headers: { 'Tus-Resumable': TUS_VERSION },
10480
- signal: combinedSignal,
10477
+ method: init.method,
10478
+ headers: init.headers,
10479
+ signal,
10481
10480
  });
10482
10481
  if (!response.ok) {
10483
- throw new UploadApiError(`${check.name} failed: ${response.status}`, check.code, response.status);
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);
10484
10488
  }
10485
- const header = response.headers.get('Upload-Offset');
10486
- const offset = header !== null ? parseInt(header, 10) : NaN;
10487
- if (!Number.isFinite(offset) || offset < 0) {
10488
- throw new UploadApiError(`${check.name} returned an invalid offset`, check.code, response.status);
10489
- }
10490
- return offset;
10489
+ return response;
10491
10490
  }
10492
10491
  catch (error) {
10493
10492
  if (error instanceof SparkVaultError)
10494
10493
  throw error;
10495
10494
  if (error != null && typeof error === 'object' && 'name' in error && error.name === 'AbortError') {
10496
- if (this.isAborted()) {
10495
+ if (closeSignal.aborted) {
10497
10496
  throw new UploadApiError('Upload cancelled', 'cancelled', 0);
10498
10497
  }
10499
10498
  throw new UploadApiError(`${check.name} timed out after ${this.timeoutMs}ms`, 'timeout', 0);
@@ -12887,8 +12886,10 @@ class UploadRenderer {
12887
12886
  progress: 0,
12888
12887
  bytesUploaded: 0,
12889
12888
  });
12890
- // Upload file over the canonical TUS transfer path
12891
- const uploadUrl = await this.api.uploadFileToForge(file, forgeUrl, (bytesUploaded, bytesTotal) => {
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) => {
12892
12893
  const progress = Math.round((bytesUploaded / bytesTotal) * 100);
12893
12894
  this.setState({
12894
12895
  view: 'uploading',
@@ -12905,12 +12906,6 @@ class UploadRenderer {
12905
12906
  phase: 'uploading',
12906
12907
  });
12907
12908
  });
12908
- // Confirm the server actually finalized the upload before celebrating.
12909
- // The TUS loop trusts a server-provided offset; this re-reads the
12910
- // server's own persisted offset and requires it to reach the file size,
12911
- // mirroring the mobile SDK's active-status check. A non-finalized
12912
- // upload throws here and never reaches the success ceremony.
12913
- await this.api.verifyUploadFinalized(uploadUrl, file.size);
12914
12909
  // Run ceremony animation
12915
12910
  await this.runCeremony(file, ingotId, requestId);
12916
12911
  // Complete
@@ -14012,15 +14007,14 @@ class IngotsModule {
14012
14007
  return response.data;
14013
14008
  }
14014
14009
  /**
14015
- * Run the canonical TUS transfer for a created/replaced ingot, then confirm
14016
- * the server finalized the upload before reporting success.
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.
14017
14015
  */
14018
14016
  async transferAndFinalize(created, file, onProgress) {
14019
- const uploadUrl = await this.uploadApi.uploadFileToForge(file, created.forge_url, onProgress);
14020
- // Confirm the server actually finalized the upload before reporting
14021
- // success — the TUS loop's offsets alone don't prove the final chunk
14022
- // committed and the ingot went active.
14023
- await this.uploadApi.verifyUploadFinalized(uploadUrl, file.size);
14017
+ await this.uploadApi.uploadFileToForge(file, created.forge_url, onProgress);
14024
14018
  return {
14025
14019
  id: created.ingot_id,
14026
14020
  name: created.name,
@@ -14182,7 +14176,8 @@ async function fetchBlobWithLivenessBounds(url) {
14182
14176
  throw error;
14183
14177
  }
14184
14178
  const contentType = response.headers.get('content-type') ?? '';
14185
- // Where the environment exposes no readable body, the transfer keeps
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
14186
14181
  // whole-transfer wall-clock semantics: blob() surfaces no chunk arrivals, so
14187
14182
  // there is no liveness to observe.
14188
14183
  if (!response.body) {
@@ -15076,7 +15071,7 @@ class SparkVault {
15076
15071
  }
15077
15072
  /** Get the SDK version */
15078
15073
  static get version() {
15079
- return '9.2.1';
15074
+ return '9.2.2';
15080
15075
  }
15081
15076
  }
15082
15077
  if (typeof window !== 'undefined') {