@unicitylabs/sphere-sdk 0.14.4 → 0.14.5

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.
@@ -332,35 +332,18 @@ function resolveProofTimeoutMs(configured) {
332
332
  }
333
333
  return configured;
334
334
  }
335
- function lateDeliveringSignal(signal) {
336
- return new Proxy(signal, {
337
- get(target, prop) {
338
- if (prop === "addEventListener") {
339
- return (type, listener, options) => {
340
- if (type === "abort" && target.aborted) {
341
- queueMicrotask(() => {
342
- listener.call(target, new Event("abort"));
343
- });
344
- return;
345
- }
346
- target.addEventListener(type, listener, options);
347
- };
348
- }
349
- const value = Reflect.get(target, prop, target);
350
- return typeof value === "function" ? value.bind(target) : value;
351
- }
352
- });
335
+ var TRANSIENT_HTTP_STATUSES = /* @__PURE__ */ new Set([408, 425, 429, 500, 502, 503, 504]);
336
+ function isTransientGatewayError(err) {
337
+ return err instanceof import_JsonRpcNetworkError.JsonRpcNetworkError && TRANSIENT_HTTP_STATUSES.has(err.status);
353
338
  }
354
- function rejectOnAbort(signal) {
355
- return new Promise((_resolve, reject) => {
356
- if (signal.aborted) {
357
- reject(signal.reason);
358
- return;
359
- }
339
+ function pause(ms, signal) {
340
+ return new Promise((resolve) => {
341
+ const timer = setTimeout(resolve, ms);
360
342
  signal.addEventListener(
361
343
  "abort",
362
344
  () => {
363
- reject(signal.reason);
345
+ clearTimeout(timer);
346
+ resolve();
364
347
  },
365
348
  { once: true }
366
349
  );
@@ -383,17 +366,23 @@ async function awaitProofBounded(deps, transaction, external) {
383
366
  )
384
367
  );
385
368
  }, deps.timeoutMs);
386
- const wait = (0, import_InclusionProofUtils.waitInclusionProof)(
387
- deps.client,
388
- deps.trustBase,
389
- deps.predicateVerifier,
390
- transaction,
391
- lateDeliveringSignal(controller.signal),
392
- deps.intervalMs
393
- );
394
- wait.catch(() => void 0);
395
369
  try {
396
- return await Promise.race([wait, rejectOnAbort(controller.signal)]);
370
+ for (; ; ) {
371
+ try {
372
+ return await (0, import_InclusionProofUtils.waitInclusionProof)(
373
+ deps.client,
374
+ deps.trustBase,
375
+ deps.predicateVerifier,
376
+ transaction,
377
+ controller.signal,
378
+ deps.intervalMs
379
+ );
380
+ } catch (err) {
381
+ if (controller.signal.aborted) throw err;
382
+ if (!isTransientGatewayError(err)) throw err;
383
+ await pause(deps.intervalMs, controller.signal);
384
+ }
385
+ }
397
386
  } finally {
398
387
  clearTimeout(timer);
399
388
  external?.removeEventListener("abort", relayAbort);