@unicitylabs/sphere-sdk 0.10.6 → 0.10.7

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 +24 -3
  10. package/dist/impl/browser/index.cjs.map +1 -1
  11. package/dist/impl/browser/index.js +24 -3
  12. package/dist/impl/browser/index.js.map +1 -1
  13. package/dist/impl/nodejs/index.cjs +24 -3
  14. package/dist/impl/nodejs/index.cjs.map +1 -1
  15. package/dist/impl/nodejs/index.d.cts +9 -1
  16. package/dist/impl/nodejs/index.d.ts +9 -1
  17. package/dist/impl/nodejs/index.js +24 -3
  18. package/dist/impl/nodejs/index.js.map +1 -1
  19. package/dist/impl/shared/wallet-api/index.cjs +24 -3
  20. package/dist/impl/shared/wallet-api/index.cjs.map +1 -1
  21. package/dist/impl/shared/wallet-api/index.d.cts +9 -1
  22. package/dist/impl/shared/wallet-api/index.d.ts +9 -1
  23. package/dist/impl/shared/wallet-api/index.js +24 -3
  24. package/dist/impl/shared/wallet-api/index.js.map +1 -1
  25. package/dist/index.cjs +24 -3
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +9 -1
  28. package/dist/index.d.ts +9 -1
  29. package/dist/index.js +24 -3
  30. package/dist/index.js.map +1 -1
  31. package/dist/wallet-api/index.cjs +24 -3
  32. package/dist/wallet-api/index.cjs.map +1 -1
  33. package/dist/wallet-api/index.d.cts +9 -1
  34. package/dist/wallet-api/index.d.ts +9 -1
  35. package/dist/wallet-api/index.js +24 -3
  36. package/dist/wallet-api/index.js.map +1 -1
  37. package/package.json +1 -1
@@ -1020,6 +1020,8 @@ function defaultWebSocketFactory(url) {
1020
1020
  }
1021
1021
  return new Ctor(url);
1022
1022
  }
1023
+ var GET_RETRY_ATTEMPTS = 3;
1024
+ var GET_RETRY_BASE_MS = 200;
1023
1025
  var WalletApiClient = class _WalletApiClient {
1024
1026
  /** Network name (also the blob-key prefix `<network>/t/<sha256>` — §5.2). */
1025
1027
  network;
@@ -1213,17 +1215,36 @@ var WalletApiClient = class _WalletApiClient {
1213
1215
  }
1214
1216
  return WalletApiError.fromStatus(res.status, message);
1215
1217
  }
1218
+ /**
1219
+ * GET-only retry on a transient NETWORK failure (a dropped/reset connection — e.g. a backend under
1220
+ * load resetting mid-read). GETs are idempotent, so re-issuing is safe; non-GET methods are NEVER
1221
+ * retried here because a lost-response retry could double-apply a write. Non-NETWORK outcomes (any
1222
+ * HTTP status) come back as a response and are handled by the caller. Bounded exponential backoff.
1223
+ */
1224
+ async rawFetchWithReadRetry(method, path, body, jwt) {
1225
+ const attempts = method === "GET" ? GET_RETRY_ATTEMPTS : 1;
1226
+ for (let attempt = 1; ; attempt += 1) {
1227
+ try {
1228
+ return await this.rawFetch(method, path, body, jwt);
1229
+ } catch (err) {
1230
+ const transient = err instanceof WalletApiError && err.code === "NETWORK";
1231
+ if (!transient || attempt >= attempts) throw err;
1232
+ await new Promise((resolve) => setTimeout(resolve, GET_RETRY_BASE_MS * 2 ** (attempt - 1)));
1233
+ }
1234
+ }
1235
+ }
1216
1236
  /**
1217
1237
  * Authenticated JSON request. A 401 triggers one silent re-auth
1218
- * (refresh → challenge fallback) and one retry.
1238
+ * (refresh → challenge fallback) and one retry; idempotent GETs additionally retry a transient
1239
+ * NETWORK failure (rawFetchWithReadRetry) so a single dropped connection doesn't fail the call.
1219
1240
  */
1220
1241
  async requestJson(method, path, body) {
1221
1242
  if (!this.jwt) await this.signIn();
1222
- let res = await this.rawFetch(method, path, body, this.jwt);
1243
+ let res = await this.rawFetchWithReadRetry(method, path, body, this.jwt);
1223
1244
  if (res.status === 401) {
1224
1245
  this.jwt = null;
1225
1246
  await this.signIn();
1226
- res = await this.rawFetch(method, path, body, this.jwt);
1247
+ res = await this.rawFetchWithReadRetry(method, path, body, this.jwt);
1227
1248
  }
1228
1249
  if (res.status === 204) return null;
1229
1250
  if (!res.ok) throw await this.toError(res, `${method} ${path}`);