@sparkvault/sdk-js 8.12.2 → 8.13.1

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.
@@ -9336,8 +9336,13 @@ function isInitiateUploadResponse(data) {
9336
9336
  }
9337
9337
  /** tus protocol version used for the resumable upload session. */
9338
9338
  const TUS_VERSION = '1.0.0';
9339
- /** Default TUS chunk size; the server may override via `X-Chunk-Size`. */
9340
- const DEFAULT_CHUNK_SIZE = 50 * 1024 * 1024;
9339
+ /** Strict positive-integer parse of Forge's advertised chunk size; anything else is `null`. */
9340
+ function parseChunkSizeHeader(raw) {
9341
+ if (raw === null || !/^\d+$/.test(raw.trim()))
9342
+ return null;
9343
+ const value = Number(raw);
9344
+ return Number.isSafeInteger(value) && value > 0 ? value : null;
9345
+ }
9341
9346
  /**
9342
9347
  * Abort a stalled chunk PATCH after this long with no upload progress.
9343
9348
  * XHR's own `timeout` measures total request duration, which would abort a
@@ -9432,10 +9437,11 @@ class UploadApi extends SparkVaultApi {
9432
9437
  *
9433
9438
  * The single canonical browser transfer path — the upload widget and the
9434
9439
  * authenticated `ingots.upload` flow both go through here (one canonical
9435
- * transfer path). Creates the session, PATCHes chunks sized by the server's
9436
- * `X-Chunk-Size` (50MB default, which keeps every request under CDN body
9437
- * caps such as Cloudflare's 100MB), validates every server-reported offset,
9438
- * and honors the session abort signal plus per-request timeouts.
9440
+ * transfer path). Creates the session, PATCHes chunks sized exactly by the
9441
+ * server's `X-Chunk-Size` (Forge fixes the geometry at 50MB, which keeps
9442
+ * every request under CDN body caps such as Cloudflare's 100MB), validates
9443
+ * every server-reported offset, and honors the session abort signal plus
9444
+ * per-request timeouts.
9439
9445
  *
9440
9446
  * Returns the TUS session URL so the caller can confirm server-side
9441
9447
  * finalization via {@link verifyUploadFinalized} before reporting success.
@@ -9489,12 +9495,15 @@ class UploadApi extends SparkVaultApi {
9489
9495
  if (!location) {
9490
9496
  throw new UploadApiError('Server did not return upload location', 'tus_create_failed', response.status);
9491
9497
  }
9498
+ // Forge fixes every session's chunk geometry and rejects any non-final
9499
+ // chunk that is not exactly the advertised size, so a client-side guess
9500
+ // could only ever be rejected: a missing header is a contract violation.
9492
9501
  const chunkSizeHeader = response.headers.get('X-Chunk-Size');
9493
- const chunkSize = chunkSizeHeader ? parseInt(chunkSizeHeader, 10) : NaN;
9494
- return {
9495
- location,
9496
- chunkSize: Number.isFinite(chunkSize) && chunkSize > 0 ? chunkSize : DEFAULT_CHUNK_SIZE,
9497
- };
9502
+ const chunkSize = parseChunkSizeHeader(chunkSizeHeader);
9503
+ if (chunkSize === null) {
9504
+ throw new UploadApiError('Server did not return a valid X-Chunk-Size', 'tus_create_failed', response.status, { header: 'X-Chunk-Size', received: chunkSizeHeader });
9505
+ }
9506
+ return { location, chunkSize };
9498
9507
  }
9499
9508
  catch (error) {
9500
9509
  if (error instanceof SparkVaultError)