@wix/builder-utils 1.21.3 → 1.21.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.
@@ -971,6 +971,34 @@ const getSignalValueDeep = (target, path = "") => {
971
971
  }
972
972
  return isSignal(value) ? value.get() : value;
973
973
  };
974
+ const retryStrategies = {
975
+ exponentialJitter: (initialDelayMs) => (attempt) => {
976
+ const base = initialDelayMs * Math.pow(2, attempt);
977
+ return base * (0.5 + Math.random() * 0.5);
978
+ }
979
+ };
980
+ function toError(error) {
981
+ return error instanceof Error ? error : new Error(String(error));
982
+ }
983
+ async function withRetry(fn, options) {
984
+ const { maxRetries, getDelay, shouldRetry = () => true, onRetry } = options;
985
+ let lastError;
986
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
987
+ try {
988
+ return await fn();
989
+ } catch (error) {
990
+ lastError = toError(error);
991
+ if (attempt < maxRetries && shouldRetry(lastError, attempt)) {
992
+ const delayMs = getDelay(attempt);
993
+ onRetry?.(lastError, attempt, delayMs);
994
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
995
+ } else {
996
+ break;
997
+ }
998
+ }
999
+ }
1000
+ throw lastError ?? new Error(`Operation failed after ${maxRetries} retries`);
1001
+ }
974
1002
  function getPageById(id, pageRegistry) {
975
1003
  return pageRegistry[id] ?? null;
976
1004
  }
@@ -1027,6 +1055,8 @@ export {
1027
1055
  getSignalValueDeep,
1028
1056
  mergeProps,
1029
1057
  removeElementProps,
1030
- routeToDynamicPage
1058
+ retryStrategies,
1059
+ routeToDynamicPage,
1060
+ withRetry
1031
1061
  };
1032
1062
  //# sourceMappingURL=builder-utils.mjs.map