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