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