@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
@@ -1568,11 +1568,14 @@ declare class WalletApiClient {
1568
1568
  /**
1569
1569
  * Retry transient REST failures with bounded exponential backoff + jitter:
1570
1570
  * - a thrown transient `NETWORK` failure (dropped/reset connection, DNS blip)
1571
- * retries on **idempotent GETs only** — a lost-response retry of a write
1572
- * could double-apply;
1571
+ * retries on **idempotent requests** — every GET, plus a write the caller
1572
+ * marked `idempotentWrite` (the server replays it as a no-op, so a
1573
+ * lost-response retry cannot double-apply; today only `inventory/apply`,
1574
+ * idempotent by transferId — #664). A non-idempotent write is single-attempt;
1573
1575
  * - a `429` response retries on **any** method (a 429 is rejected before the
1574
1576
  * handler runs — the write never executed), honoring the server `Retry-After`;
1575
- * - a `503` response retries on **GETs only** (a write may have started).
1577
+ * - a `503` response retries on **idempotent requests only** (a non-idempotent
1578
+ * write may have started).
1576
1579
  * Every other outcome (2xx, or a non-retryable status) is returned to the
1577
1580
  * caller, which maps a non-2xx to a typed {@link WalletApiError}.
1578
1581
  */
@@ -1581,8 +1584,8 @@ declare class WalletApiClient {
1581
1584
  private backoffMs;
1582
1585
  /**
1583
1586
  * Delay before retrying a non-2xx response, or `null` to not retry. `429`
1584
- * retries on any method (rejected before execution); `503` on idempotent GETs.
1585
- * Honors a capped `Retry-After` when present, else falls back to backoff.
1587
+ * retries on any method (rejected before execution); `503` on idempotent
1588
+ * requests only. Honors a capped `Retry-After` when present, else backoff.
1586
1589
  */
1587
1590
  private retryDelayForStatus;
1588
1591
  /** Parse `Retry-After` (delta-seconds or an HTTP-date) to ms, or `null` if absent/unparseable. */
@@ -1592,8 +1595,9 @@ declare class WalletApiClient {
1592
1595
  * Authenticated JSON request. A 401 triggers one silent re-auth
1593
1596
  * (refresh → challenge fallback) and one retry; {@link rawFetchWithRetry}
1594
1597
  * additionally rides out transient failures — a dropped connection on an
1595
- * idempotent GET, or a `429`/`503` with `Retry-After` — so a single blip or a
1596
- * brief rate-limit window doesn't fail the call.
1598
+ * idempotent request (any GET, or a write flagged `opts.idempotent`), or a
1599
+ * `429`/`503` with `Retry-After` — so a single blip or a brief rate-limit
1600
+ * window doesn't fail the call.
1597
1601
  */
1598
1602
  private requestJson;
1599
1603
  /** `GET /v1/inventory?since=` — one page; the caller loops while `more`. */
@@ -1568,11 +1568,14 @@ declare class WalletApiClient {
1568
1568
  /**
1569
1569
  * Retry transient REST failures with bounded exponential backoff + jitter:
1570
1570
  * - a thrown transient `NETWORK` failure (dropped/reset connection, DNS blip)
1571
- * retries on **idempotent GETs only** — a lost-response retry of a write
1572
- * could double-apply;
1571
+ * retries on **idempotent requests** — every GET, plus a write the caller
1572
+ * marked `idempotentWrite` (the server replays it as a no-op, so a
1573
+ * lost-response retry cannot double-apply; today only `inventory/apply`,
1574
+ * idempotent by transferId — #664). A non-idempotent write is single-attempt;
1573
1575
  * - a `429` response retries on **any** method (a 429 is rejected before the
1574
1576
  * handler runs — the write never executed), honoring the server `Retry-After`;
1575
- * - a `503` response retries on **GETs only** (a write may have started).
1577
+ * - a `503` response retries on **idempotent requests only** (a non-idempotent
1578
+ * write may have started).
1576
1579
  * Every other outcome (2xx, or a non-retryable status) is returned to the
1577
1580
  * caller, which maps a non-2xx to a typed {@link WalletApiError}.
1578
1581
  */
@@ -1581,8 +1584,8 @@ declare class WalletApiClient {
1581
1584
  private backoffMs;
1582
1585
  /**
1583
1586
  * Delay before retrying a non-2xx response, or `null` to not retry. `429`
1584
- * retries on any method (rejected before execution); `503` on idempotent GETs.
1585
- * Honors a capped `Retry-After` when present, else falls back to backoff.
1587
+ * retries on any method (rejected before execution); `503` on idempotent
1588
+ * requests only. Honors a capped `Retry-After` when present, else backoff.
1586
1589
  */
1587
1590
  private retryDelayForStatus;
1588
1591
  /** Parse `Retry-After` (delta-seconds or an HTTP-date) to ms, or `null` if absent/unparseable. */
@@ -1592,8 +1595,9 @@ declare class WalletApiClient {
1592
1595
  * Authenticated JSON request. A 401 triggers one silent re-auth
1593
1596
  * (refresh → challenge fallback) and one retry; {@link rawFetchWithRetry}
1594
1597
  * additionally rides out transient failures — a dropped connection on an
1595
- * idempotent GET, or a `429`/`503` with `Retry-After` — so a single blip or a
1596
- * brief rate-limit window doesn't fail the call.
1598
+ * idempotent request (any GET, or a write flagged `opts.idempotent`), or a
1599
+ * `429`/`503` with `Retry-After` — so a single blip or a brief rate-limit
1600
+ * window doesn't fail the call.
1597
1601
  */
1598
1602
  private requestJson;
1599
1603
  /** `GET /v1/inventory?since=` — one page; the caller loops while `more`. */
@@ -1442,16 +1442,19 @@ var WalletApiClient = class _WalletApiClient {
1442
1442
  /**
1443
1443
  * Retry transient REST failures with bounded exponential backoff + jitter:
1444
1444
  * - a thrown transient `NETWORK` failure (dropped/reset connection, DNS blip)
1445
- * retries on **idempotent GETs only** — a lost-response retry of a write
1446
- * could double-apply;
1445
+ * retries on **idempotent requests** — every GET, plus a write the caller
1446
+ * marked `idempotentWrite` (the server replays it as a no-op, so a
1447
+ * lost-response retry cannot double-apply; today only `inventory/apply`,
1448
+ * idempotent by transferId — #664). A non-idempotent write is single-attempt;
1447
1449
  * - a `429` response retries on **any** method (a 429 is rejected before the
1448
1450
  * handler runs — the write never executed), honoring the server `Retry-After`;
1449
- * - a `503` response retries on **GETs only** (a write may have started).
1451
+ * - a `503` response retries on **idempotent requests only** (a non-idempotent
1452
+ * write may have started).
1450
1453
  * Every other outcome (2xx, or a non-retryable status) is returned to the
1451
1454
  * caller, which maps a non-2xx to a typed {@link WalletApiError}.
1452
1455
  */
1453
- async rawFetchWithRetry(method, path, body, jwt) {
1454
- const idempotent = method === "GET";
1456
+ async rawFetchWithRetry(method, path, body, jwt, idempotentWrite = false) {
1457
+ const idempotent = method === "GET" || idempotentWrite;
1455
1458
  for (let attempt = 1; ; attempt += 1) {
1456
1459
  let res;
1457
1460
  try {
@@ -1474,8 +1477,8 @@ var WalletApiClient = class _WalletApiClient {
1474
1477
  }
1475
1478
  /**
1476
1479
  * Delay before retrying a non-2xx response, or `null` to not retry. `429`
1477
- * retries on any method (rejected before execution); `503` on idempotent GETs.
1478
- * Honors a capped `Retry-After` when present, else falls back to backoff.
1480
+ * retries on any method (rejected before execution); `503` on idempotent
1481
+ * requests only. Honors a capped `Retry-After` when present, else backoff.
1479
1482
  */
1480
1483
  retryDelayForStatus(res, idempotent, attempt) {
1481
1484
  const retryable = res.status === 429 || res.status === 503 && idempotent;
@@ -1499,16 +1502,18 @@ var WalletApiClient = class _WalletApiClient {
1499
1502
  * Authenticated JSON request. A 401 triggers one silent re-auth
1500
1503
  * (refresh → challenge fallback) and one retry; {@link rawFetchWithRetry}
1501
1504
  * additionally rides out transient failures — a dropped connection on an
1502
- * idempotent GET, or a `429`/`503` with `Retry-After` — so a single blip or a
1503
- * brief rate-limit window doesn't fail the call.
1505
+ * idempotent request (any GET, or a write flagged `opts.idempotent`), or a
1506
+ * `429`/`503` with `Retry-After` — so a single blip or a brief rate-limit
1507
+ * window doesn't fail the call.
1504
1508
  */
1505
- async requestJson(method, path, body) {
1509
+ async requestJson(method, path, body, opts) {
1510
+ const idempotent = opts?.idempotent ?? false;
1506
1511
  if (!this.jwt) await this.signIn();
1507
- let res = await this.rawFetchWithRetry(method, path, body, this.jwt);
1512
+ let res = await this.rawFetchWithRetry(method, path, body, this.jwt, idempotent);
1508
1513
  if (res.status === 401) {
1509
1514
  this.jwt = null;
1510
1515
  await this.signIn();
1511
- res = await this.rawFetchWithRetry(method, path, body, this.jwt);
1516
+ res = await this.rawFetchWithRetry(method, path, body, this.jwt, idempotent);
1512
1517
  }
1513
1518
  if (res.status === 204) return null;
1514
1519
  if (!res.ok) throw await this.toError(res, `${method} ${path}`);
@@ -1540,12 +1545,20 @@ var WalletApiClient = class _WalletApiClient {
1540
1545
  */
1541
1546
  async applyInventoryDelta(req) {
1542
1547
  const cursor = parseApplyResult(
1543
- await this.requestJson("POST", "/v1/inventory/apply", {
1544
- transferId: req.transferId,
1545
- spent: req.spent,
1546
- added: req.added,
1547
- ...req.externalDelivery !== void 0 ? { externalDelivery: req.externalDelivery } : {}
1548
- })
1548
+ await this.requestJson(
1549
+ "POST",
1550
+ "/v1/inventory/apply",
1551
+ {
1552
+ transferId: req.transferId,
1553
+ spent: req.spent,
1554
+ added: req.added,
1555
+ ...req.externalDelivery !== void 0 ? { externalDelivery: req.externalDelivery } : {}
1556
+ },
1557
+ // Idempotent by transferId — the server replays a re-applied transferId
1558
+ // to the same cursor (beginApplied), so a lost-response retry on a flaky
1559
+ // link is safe and won't double-apply (#664).
1560
+ { idempotent: true }
1561
+ )
1549
1562
  );
1550
1563
  await this.setLocalIntentStatus(req.transferId, "completed");
1551
1564
  return cursor;