@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
@@ -1291,16 +1291,19 @@ var WalletApiClient = class _WalletApiClient {
1291
1291
  /**
1292
1292
  * Retry transient REST failures with bounded exponential backoff + jitter:
1293
1293
  * - a thrown transient `NETWORK` failure (dropped/reset connection, DNS blip)
1294
- * retries on **idempotent GETs only** — a lost-response retry of a write
1295
- * could double-apply;
1294
+ * retries on **idempotent requests** — every GET, plus a write the caller
1295
+ * marked `idempotentWrite` (the server replays it as a no-op, so a
1296
+ * lost-response retry cannot double-apply; today only `inventory/apply`,
1297
+ * idempotent by transferId — #664). A non-idempotent write is single-attempt;
1296
1298
  * - a `429` response retries on **any** method (a 429 is rejected before the
1297
1299
  * handler runs — the write never executed), honoring the server `Retry-After`;
1298
- * - a `503` response retries on **GETs only** (a write may have started).
1300
+ * - a `503` response retries on **idempotent requests only** (a non-idempotent
1301
+ * write may have started).
1299
1302
  * Every other outcome (2xx, or a non-retryable status) is returned to the
1300
1303
  * caller, which maps a non-2xx to a typed {@link WalletApiError}.
1301
1304
  */
1302
- async rawFetchWithRetry(method, path, body, jwt) {
1303
- const idempotent = method === "GET";
1305
+ async rawFetchWithRetry(method, path, body, jwt, idempotentWrite = false) {
1306
+ const idempotent = method === "GET" || idempotentWrite;
1304
1307
  for (let attempt = 1; ; attempt += 1) {
1305
1308
  let res;
1306
1309
  try {
@@ -1323,8 +1326,8 @@ var WalletApiClient = class _WalletApiClient {
1323
1326
  }
1324
1327
  /**
1325
1328
  * Delay before retrying a non-2xx response, or `null` to not retry. `429`
1326
- * retries on any method (rejected before execution); `503` on idempotent GETs.
1327
- * Honors a capped `Retry-After` when present, else falls back to backoff.
1329
+ * retries on any method (rejected before execution); `503` on idempotent
1330
+ * requests only. Honors a capped `Retry-After` when present, else backoff.
1328
1331
  */
1329
1332
  retryDelayForStatus(res, idempotent, attempt) {
1330
1333
  const retryable = res.status === 429 || res.status === 503 && idempotent;
@@ -1348,16 +1351,18 @@ var WalletApiClient = class _WalletApiClient {
1348
1351
  * Authenticated JSON request. A 401 triggers one silent re-auth
1349
1352
  * (refresh → challenge fallback) and one retry; {@link rawFetchWithRetry}
1350
1353
  * additionally rides out transient failures — a dropped connection on an
1351
- * idempotent GET, or a `429`/`503` with `Retry-After` — so a single blip or a
1352
- * brief rate-limit window doesn't fail the call.
1354
+ * idempotent request (any GET, or a write flagged `opts.idempotent`), or a
1355
+ * `429`/`503` with `Retry-After` — so a single blip or a brief rate-limit
1356
+ * window doesn't fail the call.
1353
1357
  */
1354
- async requestJson(method, path, body) {
1358
+ async requestJson(method, path, body, opts) {
1359
+ const idempotent = opts?.idempotent ?? false;
1355
1360
  if (!this.jwt) await this.signIn();
1356
- let res = await this.rawFetchWithRetry(method, path, body, this.jwt);
1361
+ let res = await this.rawFetchWithRetry(method, path, body, this.jwt, idempotent);
1357
1362
  if (res.status === 401) {
1358
1363
  this.jwt = null;
1359
1364
  await this.signIn();
1360
- res = await this.rawFetchWithRetry(method, path, body, this.jwt);
1365
+ res = await this.rawFetchWithRetry(method, path, body, this.jwt, idempotent);
1361
1366
  }
1362
1367
  if (res.status === 204) return null;
1363
1368
  if (!res.ok) throw await this.toError(res, `${method} ${path}`);
@@ -1389,12 +1394,20 @@ var WalletApiClient = class _WalletApiClient {
1389
1394
  */
1390
1395
  async applyInventoryDelta(req) {
1391
1396
  const cursor = parseApplyResult(
1392
- await this.requestJson("POST", "/v1/inventory/apply", {
1393
- transferId: req.transferId,
1394
- spent: req.spent,
1395
- added: req.added,
1396
- ...req.externalDelivery !== void 0 ? { externalDelivery: req.externalDelivery } : {}
1397
- })
1397
+ await this.requestJson(
1398
+ "POST",
1399
+ "/v1/inventory/apply",
1400
+ {
1401
+ transferId: req.transferId,
1402
+ spent: req.spent,
1403
+ added: req.added,
1404
+ ...req.externalDelivery !== void 0 ? { externalDelivery: req.externalDelivery } : {}
1405
+ },
1406
+ // Idempotent by transferId — the server replays a re-applied transferId
1407
+ // to the same cursor (beginApplied), so a lost-response retry on a flaky
1408
+ // link is safe and won't double-apply (#664).
1409
+ { idempotent: true }
1410
+ )
1398
1411
  );
1399
1412
  await this.setLocalIntentStatus(req.transferId, "completed");
1400
1413
  return cursor;