@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.
- package/dist/connect/index.cjs +1 -1
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.js +1 -1
- package/dist/connect/index.js.map +1 -1
- package/dist/impl/browser/connect/index.cjs +1 -1
- package/dist/impl/browser/connect/index.cjs.map +1 -1
- package/dist/impl/browser/connect/index.js +1 -1
- package/dist/impl/browser/connect/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +31 -18
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +31 -18
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +31 -18
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +11 -7
- package/dist/impl/nodejs/index.d.ts +11 -7
- package/dist/impl/nodejs/index.js +31 -18
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/impl/shared/wallet-api/index.cjs +31 -18
- package/dist/impl/shared/wallet-api/index.cjs.map +1 -1
- package/dist/impl/shared/wallet-api/index.d.cts +11 -7
- package/dist/impl/shared/wallet-api/index.d.ts +11 -7
- package/dist/impl/shared/wallet-api/index.js +31 -18
- package/dist/impl/shared/wallet-api/index.js.map +1 -1
- package/dist/index.cjs +31 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.js +31 -18
- package/dist/index.js.map +1 -1
- package/dist/wallet-api/index.cjs +31 -18
- package/dist/wallet-api/index.cjs.map +1 -1
- package/dist/wallet-api/index.d.cts +11 -7
- package/dist/wallet-api/index.d.ts +11 -7
- package/dist/wallet-api/index.js +31 -18
- package/dist/wallet-api/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7286,16 +7286,19 @@ var WalletApiClient = class _WalletApiClient {
|
|
|
7286
7286
|
/**
|
|
7287
7287
|
* Retry transient REST failures with bounded exponential backoff + jitter:
|
|
7288
7288
|
* - a thrown transient `NETWORK` failure (dropped/reset connection, DNS blip)
|
|
7289
|
-
* retries on **idempotent
|
|
7290
|
-
*
|
|
7289
|
+
* retries on **idempotent requests** — every GET, plus a write the caller
|
|
7290
|
+
* marked `idempotentWrite` (the server replays it as a no-op, so a
|
|
7291
|
+
* lost-response retry cannot double-apply; today only `inventory/apply`,
|
|
7292
|
+
* idempotent by transferId — #664). A non-idempotent write is single-attempt;
|
|
7291
7293
|
* - a `429` response retries on **any** method (a 429 is rejected before the
|
|
7292
7294
|
* handler runs — the write never executed), honoring the server `Retry-After`;
|
|
7293
|
-
* - a `503` response retries on **
|
|
7295
|
+
* - a `503` response retries on **idempotent requests only** (a non-idempotent
|
|
7296
|
+
* write may have started).
|
|
7294
7297
|
* Every other outcome (2xx, or a non-retryable status) is returned to the
|
|
7295
7298
|
* caller, which maps a non-2xx to a typed {@link WalletApiError}.
|
|
7296
7299
|
*/
|
|
7297
|
-
async rawFetchWithRetry(method, path, body, jwt) {
|
|
7298
|
-
const idempotent = method === "GET";
|
|
7300
|
+
async rawFetchWithRetry(method, path, body, jwt, idempotentWrite = false) {
|
|
7301
|
+
const idempotent = method === "GET" || idempotentWrite;
|
|
7299
7302
|
for (let attempt = 1; ; attempt += 1) {
|
|
7300
7303
|
let res;
|
|
7301
7304
|
try {
|
|
@@ -7318,8 +7321,8 @@ var WalletApiClient = class _WalletApiClient {
|
|
|
7318
7321
|
}
|
|
7319
7322
|
/**
|
|
7320
7323
|
* Delay before retrying a non-2xx response, or `null` to not retry. `429`
|
|
7321
|
-
* retries on any method (rejected before execution); `503` on idempotent
|
|
7322
|
-
* Honors a capped `Retry-After` when present, else
|
|
7324
|
+
* retries on any method (rejected before execution); `503` on idempotent
|
|
7325
|
+
* requests only. Honors a capped `Retry-After` when present, else backoff.
|
|
7323
7326
|
*/
|
|
7324
7327
|
retryDelayForStatus(res, idempotent, attempt) {
|
|
7325
7328
|
const retryable = res.status === 429 || res.status === 503 && idempotent;
|
|
@@ -7343,16 +7346,18 @@ var WalletApiClient = class _WalletApiClient {
|
|
|
7343
7346
|
* Authenticated JSON request. A 401 triggers one silent re-auth
|
|
7344
7347
|
* (refresh → challenge fallback) and one retry; {@link rawFetchWithRetry}
|
|
7345
7348
|
* additionally rides out transient failures — a dropped connection on an
|
|
7346
|
-
* idempotent GET, or a
|
|
7347
|
-
*
|
|
7349
|
+
* idempotent request (any GET, or a write flagged `opts.idempotent`), or a
|
|
7350
|
+
* `429`/`503` with `Retry-After` — so a single blip or a brief rate-limit
|
|
7351
|
+
* window doesn't fail the call.
|
|
7348
7352
|
*/
|
|
7349
|
-
async requestJson(method, path, body) {
|
|
7353
|
+
async requestJson(method, path, body, opts) {
|
|
7354
|
+
const idempotent = opts?.idempotent ?? false;
|
|
7350
7355
|
if (!this.jwt) await this.signIn();
|
|
7351
|
-
let res = await this.rawFetchWithRetry(method, path, body, this.jwt);
|
|
7356
|
+
let res = await this.rawFetchWithRetry(method, path, body, this.jwt, idempotent);
|
|
7352
7357
|
if (res.status === 401) {
|
|
7353
7358
|
this.jwt = null;
|
|
7354
7359
|
await this.signIn();
|
|
7355
|
-
res = await this.rawFetchWithRetry(method, path, body, this.jwt);
|
|
7360
|
+
res = await this.rawFetchWithRetry(method, path, body, this.jwt, idempotent);
|
|
7356
7361
|
}
|
|
7357
7362
|
if (res.status === 204) return null;
|
|
7358
7363
|
if (!res.ok) throw await this.toError(res, `${method} ${path}`);
|
|
@@ -7384,12 +7389,20 @@ var WalletApiClient = class _WalletApiClient {
|
|
|
7384
7389
|
*/
|
|
7385
7390
|
async applyInventoryDelta(req) {
|
|
7386
7391
|
const cursor = parseApplyResult(
|
|
7387
|
-
await this.requestJson(
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7392
|
+
await this.requestJson(
|
|
7393
|
+
"POST",
|
|
7394
|
+
"/v1/inventory/apply",
|
|
7395
|
+
{
|
|
7396
|
+
transferId: req.transferId,
|
|
7397
|
+
spent: req.spent,
|
|
7398
|
+
added: req.added,
|
|
7399
|
+
...req.externalDelivery !== void 0 ? { externalDelivery: req.externalDelivery } : {}
|
|
7400
|
+
},
|
|
7401
|
+
// Idempotent by transferId — the server replays a re-applied transferId
|
|
7402
|
+
// to the same cursor (beginApplied), so a lost-response retry on a flaky
|
|
7403
|
+
// link is safe and won't double-apply (#664).
|
|
7404
|
+
{ idempotent: true }
|
|
7405
|
+
)
|
|
7393
7406
|
);
|
|
7394
7407
|
await this.setLocalIntentStatus(req.transferId, "completed");
|
|
7395
7408
|
return cursor;
|