@swype-org/react-sdk 0.2.173 → 0.2.174

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
@@ -1995,6 +1995,7 @@ var DEFAULT_POLL_INTERVAL_MS = 2e3;
1995
1995
  var DEFAULT_MAX_ATTEMPTS = 60;
1996
1996
  var DEFAULT_REQUEST_TIMEOUT_MS = 8e3;
1997
1997
  var DEFAULT_MAX_CONSECUTIVE_ERRORS = 5;
1998
+ var DEFAULT_ERROR_GRACE_PERIOD_MS = 6e4;
1998
1999
  var DEFAULT_LOG_EVERY_N_ATTEMPTS = 5;
1999
2000
  function classifyCallsStatus(status) {
2000
2001
  if (typeof status === "number") {
@@ -2016,11 +2017,14 @@ async function pollWalletCallsStatus(walletClient, callsId, options = {}) {
2016
2017
  const maxAttempts = options.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
2017
2018
  const requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
2018
2019
  const maxConsecutiveErrors = options.maxConsecutiveErrors ?? DEFAULT_MAX_CONSECUTIVE_ERRORS;
2020
+ const errorGracePeriodMs = options.errorGracePeriodMs ?? DEFAULT_ERROR_GRACE_PERIOD_MS;
2019
2021
  const logEveryN = Math.max(1, options.logEveryNAttempts ?? DEFAULT_LOG_EVERY_N_ATTEMPTS);
2020
2022
  const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
2023
+ const now = options.now ?? (() => Date.now());
2021
2024
  const info = options.logger?.info ?? ((m) => console.info(m));
2022
2025
  const warn = options.logger?.warn ?? ((m) => console.warn(m));
2023
2026
  const error = options.logger?.error ?? ((m) => console.error(m));
2027
+ const pollStartedAt = now();
2024
2028
  let consecutiveErrors = 0;
2025
2029
  let lastStatus;
2026
2030
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
@@ -2040,9 +2044,15 @@ async function pollWalletCallsStatus(walletClient, callsId, options = {}) {
2040
2044
  consecutiveErrors += 1;
2041
2045
  const message = err instanceof Error ? err.message : String(err);
2042
2046
  const isTimeout = err instanceof PromiseTimeoutError;
2047
+ const elapsedMs = now() - pollStartedAt;
2048
+ const inGracePeriod = elapsedMs < errorGracePeriodMs;
2043
2049
  warn(
2044
- `[blink-sdk][batch-wallet-calls] wallet_getCallsStatus errored. callsId=${callsId}, attempt=${attempt}, consecutiveErrors=${consecutiveErrors}, isTimeout=${isTimeout}, error=${message}`
2050
+ `[blink-sdk][batch-wallet-calls] wallet_getCallsStatus errored. callsId=${callsId}, attempt=${attempt}, consecutiveErrors=${consecutiveErrors}, isTimeout=${isTimeout}, inGracePeriod=${inGracePeriod}, elapsedMs=${elapsedMs}, error=${message}`
2045
2051
  );
2052
+ if (inGracePeriod) {
2053
+ consecutiveErrors = 0;
2054
+ continue;
2055
+ }
2046
2056
  if (consecutiveErrors >= maxConsecutiveErrors) {
2047
2057
  error(
2048
2058
  `[blink-sdk][batch-wallet-calls] Aborting poll after ${consecutiveErrors} consecutive errors. callsId=${callsId}, attempt=${attempt}, lastError=${message}`