@sparkvault/sdk-js 14.1.0 → 14.1.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.
package/dist/index.d.ts CHANGED
@@ -3852,11 +3852,11 @@ declare class SparkVaultError extends Error {
3852
3852
  readonly statusCode?: number;
3853
3853
  readonly details?: Record<string, unknown>;
3854
3854
  /**
3855
- * The answer's `Retry-After`, in ms from the answer, read as the platform's
3856
- * transfer policy reads it (RFC 9110 §10.2.3: delay-seconds or an
3855
+ * The answer's `Retry-After`, in ms from the answer, read by the platform's
3856
+ * one parser (`parseRetryAfterMs`; RFC 9110 §10.2.3: delay-seconds or an
3857
3857
  * HTTP-date): the earliest a next attempt can expect another answer, which
3858
3858
  * every retry the SDK makes waits out as a floor. Null when the answer
3859
- * carried none the policy could read, or no answer arrived.
3859
+ * carried none the parser could read, or no answer arrived.
3860
3860
  */
3861
3861
  readonly retryAfterMs: number | null;
3862
3862
  /**
package/dist/index.mjs CHANGED
@@ -187,6 +187,12 @@ const UPLOAD_REFUSAL_HEADER = 'X-Upload-Refusal';
187
187
  * (forge-tus), the browser SDK (sdk-js bundles this module) and the mobile SDK
188
188
  * (sdk-mobile carries a generated copy) read every answer the same way.
189
189
  *
190
+ * It also holds the one reading of `Retry-After` every JavaScript client
191
+ * applies to any answer, a transfer's or not (parseRetryAfterMs), and the one
192
+ * wait a thumbnail fetch gives a busy Forge before its single retry
193
+ * (thumbnailBusyWaitMs), so no client keeps a parser of its own that drifts
194
+ * in what it accepts.
195
+ *
190
196
  * It encodes what Google Drive, Google Cloud Storage, OneDrive, Dropbox and
191
197
  * AWS document for resumable transfers:
192
198
  * - only a request that got no answer, 408, 425, 429 or a 5xx is retried;
@@ -307,6 +313,8 @@ const CORE_CODE = /^[A-Z][A-Z0-9_]{0,63}$/;
307
313
 
308
314
 
309
315
  const UPLOAD_OFFSET_HEADER = 'Upload-Offset';
316
+
317
+ /** The header every client reads an answer's wait from (parseRetryAfterMs). */
310
318
  const RETRY_AFTER_HEADER = 'Retry-After';
311
319
 
312
320
  /**
@@ -391,7 +399,7 @@ function classifyTransferResponse({ status, headers = null, details = null, rece
391
399
  const coreCode = mayNameCoreCode(status, offset)
392
400
  ? coreCodeIn(details) ?? coreCodeOf(header(UPLOAD_REFUSAL_HEADER))
393
401
  : null;
394
- const retryAfterMs = readRetryAfterMs(header(RETRY_AFTER_HEADER), now);
402
+ const retryAfterMs = parseRetryAfterMs(header(RETRY_AFTER_HEADER), now);
395
403
  return {
396
404
  verdict: verdictFor(status, { offset, coreCode, deferral: receipt && retryAfterMs !== null }),
397
405
  retryAfterMs,
@@ -450,14 +458,26 @@ function readCount(value) {
450
458
  return Number.isSafeInteger(count) ? count : null;
451
459
  }
452
460
 
453
- /** RFC 9110 §10.2.3: `Retry-After` is delay-seconds or an HTTP-date. */
454
- function readRetryAfterMs(value, now) {
455
- const seconds = readCount(value);
461
+ /**
462
+ * An answer's `Retry-After` (RFC 9110 §10.2.3: delay-seconds or an
463
+ * HTTP-date), as every JavaScript client reads it from any answer: whole
464
+ * seconds, or the time until the date, an HTTP-date already past reading as 0.
465
+ *
466
+ * @param {unknown} headerValue - The header as received (null when absent)
467
+ * @param {number} [now] - When the answer arrived (epoch ms), which an
468
+ * HTTP-date counts from and an obsolete two-digit year is placed by
469
+ * @returns {number|null} ms from the answer, or null when absent or
470
+ * unreadable: not text, a delay other than whole seconds in decimal digits,
471
+ * words, a date that names no real moment, or seconds too large to count
472
+ * in ms
473
+ */
474
+ function parseRetryAfterMs(headerValue, now = Date.now()) {
475
+ const seconds = readCount(headerValue);
456
476
  if (seconds !== null) {
457
477
  const ms = seconds * 1000;
458
478
  return Number.isSafeInteger(ms) ? ms : null;
459
479
  }
460
- const at = typeof value === 'string' ? parseHttpDate(value.trim(), now) : null;
480
+ const at = typeof headerValue === 'string' ? parseHttpDate(headerValue.trim(), now) : null;
461
481
  return at === null ? null : Math.max(0, at - now);
462
482
  }
463
483
 
@@ -938,10 +958,8 @@ function parseJson(text) {
938
958
  * `{ message }`) or with no JSON at all, so each field falls back to its flat
939
959
  * form and then to a default. The body is read leniently: a failure's status
940
960
  * and class never depend on the body being JSON. The `Retry-After` is read by
941
- * the transfer policy's one parser (`@sparkvault/app-sdk/transfer-retry`),
942
- * never a second one: the policy reads a whole answer at once, and only its
943
- * header reading is kept here, because an API answer is the service's
944
- * verdict, never a transfer answer the policy's verdict applies to.
961
+ * the platform's one parser (`parseRetryAfterMs`,
962
+ * `@sparkvault/app-sdk/transfer-retry`), never a second one.
945
963
  */
946
964
  function failureOf(status, body, header) {
947
965
  const root = recordField(body) ?? {};
@@ -951,7 +969,7 @@ function failureOf(status, body, header) {
951
969
  message: stringField(nested?.message) ?? stringField(root.message) ?? stringField(root.error) ?? 'Request failed',
952
970
  code: stringField(nested?.code) ?? stringField(root.code) ?? 'api_error',
953
971
  details: recordField(nested?.details) ?? recordField(root.details),
954
- retryAfterMs: classifyTransferResponse({ status, headers: header }).retryAfterMs,
972
+ retryAfterMs: parseRetryAfterMs(header(RETRY_AFTER_HEADER)),
955
973
  };
956
974
  }
957
975
  /**
@@ -21342,7 +21360,7 @@ class SparkVault {
21342
21360
  }
21343
21361
  /** Get the SDK version */
21344
21362
  static get version() {
21345
- return '14.1.0';
21363
+ return '14.1.1';
21346
21364
  }
21347
21365
  }
21348
21366
  if (typeof window !== 'undefined') {