@unicitylabs/sphere-sdk 0.14.6 → 0.14.8-dev.1

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.
@@ -9484,12 +9484,15 @@ function pause(ms, signal) {
9484
9484
  });
9485
9485
  }
9486
9486
  async function retryTransient(attempt, signal, intervalMs) {
9487
+ let retried = false;
9487
9488
  for (; ; ) {
9489
+ if (signal.aborted) throw signal.reason;
9488
9490
  try {
9489
- return await attempt();
9491
+ return { value: await attempt(), retried };
9490
9492
  } catch (err) {
9491
9493
  if (signal.aborted) throw err;
9492
9494
  if (!isTransientGatewayError(err)) throw err;
9495
+ retried = true;
9493
9496
  await pause(intervalMs, signal);
9494
9497
  }
9495
9498
  }
@@ -9515,7 +9518,7 @@ function certificationDeadline(timeoutMs, external, label) {
9515
9518
  };
9516
9519
  }
9517
9520
  async function awaitProofBounded(deps, transaction, signal) {
9518
- return retryTransient(
9521
+ const { value } = await retryTransient(
9519
9522
  () => (0, import_InclusionProofUtils.waitInclusionProof)(
9520
9523
  deps.client,
9521
9524
  deps.trustBase,
@@ -9527,6 +9530,7 @@ async function awaitProofBounded(deps, transaction, signal) {
9527
9530
  signal,
9528
9531
  deps.intervalMs
9529
9532
  );
9533
+ return value;
9530
9534
  }
9531
9535
 
9532
9536
  // token-engine/errors.ts
@@ -10122,14 +10126,14 @@ var SphereTokenEngine = class {
10122
10126
  let submitError = null;
10123
10127
  let submitRejectedCleanly = false;
10124
10128
  try {
10125
- const response = await retryTransient(
10129
+ const { value: response, retried } = await retryTransient(
10126
10130
  () => this.deps.client.submitCertificationRequest(certificationData),
10127
10131
  signal,
10128
10132
  this.deps.proofPollIntervalMs ?? DEFAULT_PROOF_POLL_INTERVAL_MS
10129
10133
  );
10130
10134
  if (response.status !== import_CertificationResponse.CertificationStatus.SUCCESS) {
10131
10135
  submitError = new SphereError(`${failLabel}: ${response.status}`, failCode);
10132
- submitRejectedCleanly = CLEAN_REJECT_STATUSES.has(response.status);
10136
+ submitRejectedCleanly = !retried && CLEAN_REJECT_STATUSES.has(response.status);
10133
10137
  }
10134
10138
  } catch (err) {
10135
10139
  submitError = err ?? new SphereError(`${failLabel}: submit failed`, failCode);
@@ -11526,6 +11530,9 @@ function classifyError(e) {
11526
11530
  }
11527
11531
  return "other";
11528
11532
  }
11533
+ function firstNonConflictError(outcomes) {
11534
+ return outcomes.find((o) => o.error !== void 0 && classifyError(o.error) !== "conflict");
11535
+ }
11529
11536
  function summarize(outcomes) {
11530
11537
  const committed = outcomes.filter((o) => o.certified);
11531
11538
  const rank = { "keep-open": 3, conflict: 2, other: 1 };
@@ -11586,14 +11593,15 @@ var TransferMachine = class {
11586
11593
  ...r.payload.memo !== void 0 ? { memo: r.payload.memo } : {}
11587
11594
  };
11588
11595
  const outcomes = await this.resumeOps(ctx, engine, r);
11589
- const { committed, cls, firstError } = summarize(outcomes);
11596
+ const { committed } = summarize(outcomes);
11590
11597
  const conflicts = this.toConflicts(engine, r, outcomes);
11591
11598
  if (committed.length === 0 && conflicts.length > 0) throw conflicts[0].error;
11592
11599
  let deliveryPending = false;
11593
11600
  if (committed.length > 0) {
11594
11601
  deliveryPending = await this.deliverSet(r.transferId, r.payload.recipient, r.payload.memo, committed);
11595
11602
  }
11596
- if (cls !== null && cls !== "conflict") throw firstError;
11603
+ const blocking = firstNonConflictError(outcomes);
11604
+ if (blocking !== void 0) throw blocking.error;
11597
11605
  await this.applyCommitted(engine, r.transferId, committed);
11598
11606
  if (conflicts.length > 0) {
11599
11607
  return { deliveryPending, partial: await this.settlePartial(engine, r, committed, conflicts) };
@@ -11619,16 +11627,37 @@ var TransferMachine = class {
11619
11627
  ...plan.memo !== void 0 ? { memo: plan.memo } : {}
11620
11628
  };
11621
11629
  const outcomes = [];
11630
+ const certified = [];
11622
11631
  for (let at = 0; at < plan.ops.length; at += CERTIFY_WIDTH) {
11623
11632
  const batch = plan.ops.slice(at, at + CERTIFY_WIDTH);
11624
11633
  const settled = await Promise.all(
11625
- batch.map((op) => this.certifyOne(ctx, engine, op, plan.sources.get(op.sourceTokenId)))
11634
+ batch.map(
11635
+ (op) => this.certifyOne(ctx, engine, op, plan.sources.get(op.sourceTokenId)).then((o) => {
11636
+ if (o.certified) {
11637
+ certified.push(o);
11638
+ this.emitProgress(plan, certified);
11639
+ }
11640
+ return o;
11641
+ })
11642
+ )
11626
11643
  );
11627
11644
  outcomes.push(...settled);
11628
11645
  if (settled.some((o) => o.error !== void 0 && !o.certified)) break;
11629
11646
  }
11630
11647
  return outcomes;
11631
11648
  }
11649
+ /** In-flight snapshot: `tokenTransfers` holds the legs certified SO FAR. */
11650
+ emitProgress(plan, certified) {
11651
+ this.deps.emit("transfer:updated", {
11652
+ id: plan.transferId,
11653
+ status: "submitted",
11654
+ tokens: [],
11655
+ tokenTransfers: certified.map((o) => ({
11656
+ sourceTokenId: o.op.sourceTokenId,
11657
+ method: o.op.kind
11658
+ }))
11659
+ });
11660
+ }
11632
11661
  async certifyOne(ctx, engine, op, source) {
11633
11662
  if (source === void 0) {
11634
11663
  return {