@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
|
@@ -4918,16 +4918,19 @@ var WalletApiClient = class _WalletApiClient {
|
|
|
4918
4918
|
/**
|
|
4919
4919
|
* Retry transient REST failures with bounded exponential backoff + jitter:
|
|
4920
4920
|
* - a thrown transient `NETWORK` failure (dropped/reset connection, DNS blip)
|
|
4921
|
-
* retries on **idempotent
|
|
4922
|
-
*
|
|
4921
|
+
* retries on **idempotent requests** — every GET, plus a write the caller
|
|
4922
|
+
* marked `idempotentWrite` (the server replays it as a no-op, so a
|
|
4923
|
+
* lost-response retry cannot double-apply; today only `inventory/apply`,
|
|
4924
|
+
* idempotent by transferId — #664). A non-idempotent write is single-attempt;
|
|
4923
4925
|
* - a `429` response retries on **any** method (a 429 is rejected before the
|
|
4924
4926
|
* handler runs — the write never executed), honoring the server `Retry-After`;
|
|
4925
|
-
* - a `503` response retries on **
|
|
4927
|
+
* - a `503` response retries on **idempotent requests only** (a non-idempotent
|
|
4928
|
+
* write may have started).
|
|
4926
4929
|
* Every other outcome (2xx, or a non-retryable status) is returned to the
|
|
4927
4930
|
* caller, which maps a non-2xx to a typed {@link WalletApiError}.
|
|
4928
4931
|
*/
|
|
4929
|
-
async rawFetchWithRetry(method, path, body, jwt) {
|
|
4930
|
-
const idempotent = method === "GET";
|
|
4932
|
+
async rawFetchWithRetry(method, path, body, jwt, idempotentWrite = false) {
|
|
4933
|
+
const idempotent = method === "GET" || idempotentWrite;
|
|
4931
4934
|
for (let attempt = 1; ; attempt += 1) {
|
|
4932
4935
|
let res;
|
|
4933
4936
|
try {
|
|
@@ -4950,8 +4953,8 @@ var WalletApiClient = class _WalletApiClient {
|
|
|
4950
4953
|
}
|
|
4951
4954
|
/**
|
|
4952
4955
|
* Delay before retrying a non-2xx response, or `null` to not retry. `429`
|
|
4953
|
-
* retries on any method (rejected before execution); `503` on idempotent
|
|
4954
|
-
* Honors a capped `Retry-After` when present, else
|
|
4956
|
+
* retries on any method (rejected before execution); `503` on idempotent
|
|
4957
|
+
* requests only. Honors a capped `Retry-After` when present, else backoff.
|
|
4955
4958
|
*/
|
|
4956
4959
|
retryDelayForStatus(res, idempotent, attempt) {
|
|
4957
4960
|
const retryable = res.status === 429 || res.status === 503 && idempotent;
|
|
@@ -4975,16 +4978,18 @@ var WalletApiClient = class _WalletApiClient {
|
|
|
4975
4978
|
* Authenticated JSON request. A 401 triggers one silent re-auth
|
|
4976
4979
|
* (refresh → challenge fallback) and one retry; {@link rawFetchWithRetry}
|
|
4977
4980
|
* additionally rides out transient failures — a dropped connection on an
|
|
4978
|
-
* idempotent GET, or a
|
|
4979
|
-
*
|
|
4981
|
+
* idempotent request (any GET, or a write flagged `opts.idempotent`), or a
|
|
4982
|
+
* `429`/`503` with `Retry-After` — so a single blip or a brief rate-limit
|
|
4983
|
+
* window doesn't fail the call.
|
|
4980
4984
|
*/
|
|
4981
|
-
async requestJson(method, path, body) {
|
|
4985
|
+
async requestJson(method, path, body, opts) {
|
|
4986
|
+
const idempotent = opts?.idempotent ?? false;
|
|
4982
4987
|
if (!this.jwt) await this.signIn();
|
|
4983
|
-
let res = await this.rawFetchWithRetry(method, path, body, this.jwt);
|
|
4988
|
+
let res = await this.rawFetchWithRetry(method, path, body, this.jwt, idempotent);
|
|
4984
4989
|
if (res.status === 401) {
|
|
4985
4990
|
this.jwt = null;
|
|
4986
4991
|
await this.signIn();
|
|
4987
|
-
res = await this.rawFetchWithRetry(method, path, body, this.jwt);
|
|
4992
|
+
res = await this.rawFetchWithRetry(method, path, body, this.jwt, idempotent);
|
|
4988
4993
|
}
|
|
4989
4994
|
if (res.status === 204) return null;
|
|
4990
4995
|
if (!res.ok) throw await this.toError(res, `${method} ${path}`);
|
|
@@ -5016,12 +5021,20 @@ var WalletApiClient = class _WalletApiClient {
|
|
|
5016
5021
|
*/
|
|
5017
5022
|
async applyInventoryDelta(req) {
|
|
5018
5023
|
const cursor = parseApplyResult(
|
|
5019
|
-
await this.requestJson(
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5024
|
+
await this.requestJson(
|
|
5025
|
+
"POST",
|
|
5026
|
+
"/v1/inventory/apply",
|
|
5027
|
+
{
|
|
5028
|
+
transferId: req.transferId,
|
|
5029
|
+
spent: req.spent,
|
|
5030
|
+
added: req.added,
|
|
5031
|
+
...req.externalDelivery !== void 0 ? { externalDelivery: req.externalDelivery } : {}
|
|
5032
|
+
},
|
|
5033
|
+
// Idempotent by transferId — the server replays a re-applied transferId
|
|
5034
|
+
// to the same cursor (beginApplied), so a lost-response retry on a flaky
|
|
5035
|
+
// link is safe and won't double-apply (#664).
|
|
5036
|
+
{ idempotent: true }
|
|
5037
|
+
)
|
|
5025
5038
|
);
|
|
5026
5039
|
await this.setLocalIntentStatus(req.transferId, "completed");
|
|
5027
5040
|
return cursor;
|