@unicitylabs/sphere-sdk 0.11.7 → 0.11.8

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.
Files changed (37) hide show
  1. package/dist/connect/index.cjs +1 -1
  2. package/dist/connect/index.cjs.map +1 -1
  3. package/dist/connect/index.js +1 -1
  4. package/dist/connect/index.js.map +1 -1
  5. package/dist/impl/browser/connect/index.cjs +1 -1
  6. package/dist/impl/browser/connect/index.cjs.map +1 -1
  7. package/dist/impl/browser/connect/index.js +1 -1
  8. package/dist/impl/browser/connect/index.js.map +1 -1
  9. package/dist/impl/browser/index.cjs +31 -18
  10. package/dist/impl/browser/index.cjs.map +1 -1
  11. package/dist/impl/browser/index.js +31 -18
  12. package/dist/impl/browser/index.js.map +1 -1
  13. package/dist/impl/nodejs/index.cjs +31 -18
  14. package/dist/impl/nodejs/index.cjs.map +1 -1
  15. package/dist/impl/nodejs/index.d.cts +11 -7
  16. package/dist/impl/nodejs/index.d.ts +11 -7
  17. package/dist/impl/nodejs/index.js +31 -18
  18. package/dist/impl/nodejs/index.js.map +1 -1
  19. package/dist/impl/shared/wallet-api/index.cjs +31 -18
  20. package/dist/impl/shared/wallet-api/index.cjs.map +1 -1
  21. package/dist/impl/shared/wallet-api/index.d.cts +11 -7
  22. package/dist/impl/shared/wallet-api/index.d.ts +11 -7
  23. package/dist/impl/shared/wallet-api/index.js +31 -18
  24. package/dist/impl/shared/wallet-api/index.js.map +1 -1
  25. package/dist/index.cjs +31 -18
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +11 -7
  28. package/dist/index.d.ts +11 -7
  29. package/dist/index.js +31 -18
  30. package/dist/index.js.map +1 -1
  31. package/dist/wallet-api/index.cjs +31 -18
  32. package/dist/wallet-api/index.cjs.map +1 -1
  33. package/dist/wallet-api/index.d.cts +11 -7
  34. package/dist/wallet-api/index.d.ts +11 -7
  35. package/dist/wallet-api/index.js +31 -18
  36. package/dist/wallet-api/index.js.map +1 -1
  37. package/package.json +1 -1
@@ -1485,16 +1485,19 @@ var WalletApiClient = class _WalletApiClient {
1485
1485
  /**
1486
1486
  * Retry transient REST failures with bounded exponential backoff + jitter:
1487
1487
  * - a thrown transient `NETWORK` failure (dropped/reset connection, DNS blip)
1488
- * retries on **idempotent GETs only** — a lost-response retry of a write
1489
- * could double-apply;
1488
+ * retries on **idempotent requests** — every GET, plus a write the caller
1489
+ * marked `idempotentWrite` (the server replays it as a no-op, so a
1490
+ * lost-response retry cannot double-apply; today only `inventory/apply`,
1491
+ * idempotent by transferId — #664). A non-idempotent write is single-attempt;
1490
1492
  * - a `429` response retries on **any** method (a 429 is rejected before the
1491
1493
  * handler runs — the write never executed), honoring the server `Retry-After`;
1492
- * - a `503` response retries on **GETs only** (a write may have started).
1494
+ * - a `503` response retries on **idempotent requests only** (a non-idempotent
1495
+ * write may have started).
1493
1496
  * Every other outcome (2xx, or a non-retryable status) is returned to the
1494
1497
  * caller, which maps a non-2xx to a typed {@link WalletApiError}.
1495
1498
  */
1496
- async rawFetchWithRetry(method, path, body, jwt) {
1497
- const idempotent = method === "GET";
1499
+ async rawFetchWithRetry(method, path, body, jwt, idempotentWrite = false) {
1500
+ const idempotent = method === "GET" || idempotentWrite;
1498
1501
  for (let attempt = 1; ; attempt += 1) {
1499
1502
  let res;
1500
1503
  try {
@@ -1517,8 +1520,8 @@ var WalletApiClient = class _WalletApiClient {
1517
1520
  }
1518
1521
  /**
1519
1522
  * Delay before retrying a non-2xx response, or `null` to not retry. `429`
1520
- * retries on any method (rejected before execution); `503` on idempotent GETs.
1521
- * Honors a capped `Retry-After` when present, else falls back to backoff.
1523
+ * retries on any method (rejected before execution); `503` on idempotent
1524
+ * requests only. Honors a capped `Retry-After` when present, else backoff.
1522
1525
  */
1523
1526
  retryDelayForStatus(res, idempotent, attempt) {
1524
1527
  const retryable = res.status === 429 || res.status === 503 && idempotent;
@@ -1542,16 +1545,18 @@ var WalletApiClient = class _WalletApiClient {
1542
1545
  * Authenticated JSON request. A 401 triggers one silent re-auth
1543
1546
  * (refresh → challenge fallback) and one retry; {@link rawFetchWithRetry}
1544
1547
  * additionally rides out transient failures — a dropped connection on an
1545
- * idempotent GET, or a `429`/`503` with `Retry-After` — so a single blip or a
1546
- * brief rate-limit window doesn't fail the call.
1548
+ * idempotent request (any GET, or a write flagged `opts.idempotent`), or a
1549
+ * `429`/`503` with `Retry-After` — so a single blip or a brief rate-limit
1550
+ * window doesn't fail the call.
1547
1551
  */
1548
- async requestJson(method, path, body) {
1552
+ async requestJson(method, path, body, opts) {
1553
+ const idempotent = opts?.idempotent ?? false;
1549
1554
  if (!this.jwt) await this.signIn();
1550
- let res = await this.rawFetchWithRetry(method, path, body, this.jwt);
1555
+ let res = await this.rawFetchWithRetry(method, path, body, this.jwt, idempotent);
1551
1556
  if (res.status === 401) {
1552
1557
  this.jwt = null;
1553
1558
  await this.signIn();
1554
- res = await this.rawFetchWithRetry(method, path, body, this.jwt);
1559
+ res = await this.rawFetchWithRetry(method, path, body, this.jwt, idempotent);
1555
1560
  }
1556
1561
  if (res.status === 204) return null;
1557
1562
  if (!res.ok) throw await this.toError(res, `${method} ${path}`);
@@ -1583,12 +1588,20 @@ var WalletApiClient = class _WalletApiClient {
1583
1588
  */
1584
1589
  async applyInventoryDelta(req) {
1585
1590
  const cursor = parseApplyResult(
1586
- await this.requestJson("POST", "/v1/inventory/apply", {
1587
- transferId: req.transferId,
1588
- spent: req.spent,
1589
- added: req.added,
1590
- ...req.externalDelivery !== void 0 ? { externalDelivery: req.externalDelivery } : {}
1591
- })
1591
+ await this.requestJson(
1592
+ "POST",
1593
+ "/v1/inventory/apply",
1594
+ {
1595
+ transferId: req.transferId,
1596
+ spent: req.spent,
1597
+ added: req.added,
1598
+ ...req.externalDelivery !== void 0 ? { externalDelivery: req.externalDelivery } : {}
1599
+ },
1600
+ // Idempotent by transferId — the server replays a re-applied transferId
1601
+ // to the same cursor (beginApplied), so a lost-response retry on a flaky
1602
+ // link is safe and won't double-apply (#664).
1603
+ { idempotent: true }
1604
+ )
1592
1605
  );
1593
1606
  await this.setLocalIntentStatus(req.transferId, "completed");
1594
1607
  return cursor;