@unicitylabs/sphere-sdk 0.14.6 → 0.14.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.
package/dist/index.cjs CHANGED
@@ -9542,12 +9542,15 @@ function pause(ms, signal) {
9542
9542
  });
9543
9543
  }
9544
9544
  async function retryTransient(attempt, signal, intervalMs) {
9545
+ let retried = false;
9545
9546
  for (; ; ) {
9547
+ if (signal.aborted) throw signal.reason;
9546
9548
  try {
9547
- return await attempt();
9549
+ return { value: await attempt(), retried };
9548
9550
  } catch (err) {
9549
9551
  if (signal.aborted) throw err;
9550
9552
  if (!isTransientGatewayError(err)) throw err;
9553
+ retried = true;
9551
9554
  await pause(intervalMs, signal);
9552
9555
  }
9553
9556
  }
@@ -9573,7 +9576,7 @@ function certificationDeadline(timeoutMs, external, label) {
9573
9576
  };
9574
9577
  }
9575
9578
  async function awaitProofBounded(deps, transaction, signal) {
9576
- return retryTransient(
9579
+ const { value } = await retryTransient(
9577
9580
  () => (0, import_InclusionProofUtils.waitInclusionProof)(
9578
9581
  deps.client,
9579
9582
  deps.trustBase,
@@ -9585,6 +9588,7 @@ async function awaitProofBounded(deps, transaction, signal) {
9585
9588
  signal,
9586
9589
  deps.intervalMs
9587
9590
  );
9591
+ return value;
9588
9592
  }
9589
9593
 
9590
9594
  // token-engine/errors.ts
@@ -10180,14 +10184,14 @@ var SphereTokenEngine = class {
10180
10184
  let submitError = null;
10181
10185
  let submitRejectedCleanly = false;
10182
10186
  try {
10183
- const response = await retryTransient(
10187
+ const { value: response, retried } = await retryTransient(
10184
10188
  () => this.deps.client.submitCertificationRequest(certificationData),
10185
10189
  signal,
10186
10190
  this.deps.proofPollIntervalMs ?? DEFAULT_PROOF_POLL_INTERVAL_MS
10187
10191
  );
10188
10192
  if (response.status !== import_CertificationResponse.CertificationStatus.SUCCESS) {
10189
10193
  submitError = new SphereError(`${failLabel}: ${response.status}`, failCode);
10190
- submitRejectedCleanly = CLEAN_REJECT_STATUSES.has(response.status);
10194
+ submitRejectedCleanly = !retried && CLEAN_REJECT_STATUSES.has(response.status);
10191
10195
  }
10192
10196
  } catch (err) {
10193
10197
  submitError = err ?? new SphereError(`${failLabel}: submit failed`, failCode);
@@ -11584,6 +11588,9 @@ function classifyError(e) {
11584
11588
  }
11585
11589
  return "other";
11586
11590
  }
11591
+ function firstNonConflictError(outcomes) {
11592
+ return outcomes.find((o) => o.error !== void 0 && classifyError(o.error) !== "conflict");
11593
+ }
11587
11594
  function summarize(outcomes) {
11588
11595
  const committed = outcomes.filter((o) => o.certified);
11589
11596
  const rank = { "keep-open": 3, conflict: 2, other: 1 };
@@ -11644,14 +11651,15 @@ var TransferMachine = class {
11644
11651
  ...r.payload.memo !== void 0 ? { memo: r.payload.memo } : {}
11645
11652
  };
11646
11653
  const outcomes = await this.resumeOps(ctx, engine, r);
11647
- const { committed, cls, firstError } = summarize(outcomes);
11654
+ const { committed } = summarize(outcomes);
11648
11655
  const conflicts = this.toConflicts(engine, r, outcomes);
11649
11656
  if (committed.length === 0 && conflicts.length > 0) throw conflicts[0].error;
11650
11657
  let deliveryPending = false;
11651
11658
  if (committed.length > 0) {
11652
11659
  deliveryPending = await this.deliverSet(r.transferId, r.payload.recipient, r.payload.memo, committed);
11653
11660
  }
11654
- if (cls !== null && cls !== "conflict") throw firstError;
11661
+ const blocking = firstNonConflictError(outcomes);
11662
+ if (blocking !== void 0) throw blocking.error;
11655
11663
  await this.applyCommitted(engine, r.transferId, committed);
11656
11664
  if (conflicts.length > 0) {
11657
11665
  return { deliveryPending, partial: await this.settlePartial(engine, r, committed, conflicts) };