@routstr/sdk 0.3.0 → 0.3.2

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.mjs CHANGED
@@ -385,6 +385,7 @@ var ModelManager = class _ModelManager {
385
385
  if (!(error instanceof Error)) return false;
386
386
  const msg = error.message.toLowerCase();
387
387
  if (msg.includes("fetch failed")) return true;
388
+ if (msg.includes("429")) return true;
388
389
  if (msg.includes("502")) return true;
389
390
  if (msg.includes("503")) return true;
390
391
  if (msg.includes("504")) return true;
@@ -663,6 +664,7 @@ var MintDiscovery = class {
663
664
  if (!(error instanceof Error)) return false;
664
665
  const msg = error.message.toLowerCase();
665
666
  if (msg.includes("fetch failed")) return true;
667
+ if (msg.includes("429")) return true;
666
668
  if (msg.includes("502")) return true;
667
669
  if (msg.includes("503")) return true;
668
670
  if (msg.includes("504")) return true;
@@ -2454,8 +2456,8 @@ var ProviderManager = class _ProviderManager {
2454
2456
  lastFailed = /* @__PURE__ */ new Map();
2455
2457
  /** Providers on cooldown: [provider_url, cooldown_started_timestamp][] */
2456
2458
  providersOnCoolDown = [];
2457
- /** Cooldown duration in milliseconds (5 minutes) */
2458
- static COOLDOWN_DURATION_MS = 5 * 60 * 1e3;
2459
+ /** Cooldown duration in milliseconds (42 seconds) */
2460
+ static COOLDOWN_DURATION_MS = 42 * 1e3;
2459
2461
  /** Optional persistent store for failure tracking */
2460
2462
  store = null;
2461
2463
  /** Instance ID for debugging */
@@ -5290,11 +5292,12 @@ var RoutstrClient = class {
5290
5292
  baseUrl
5291
5293
  );
5292
5294
  const currentBalance = currentBalanceInfo.unit === "msat" ? currentBalanceInfo.amount / 1e3 : currentBalanceInfo.amount;
5293
- const shortfall = Math.max(0, params.requiredSats - currentBalance);
5295
+ const reservedBalance = currentBalanceInfo.unit === "msat" ? (currentBalanceInfo.reserved ?? 0) / 1e3 : currentBalanceInfo.reserved ?? 0;
5296
+ const shortfall = Math.max(0, params.requiredSats - currentBalance + reservedBalance);
5294
5297
  topupAmount = shortfall > 0.21 * params.requiredSats ? shortfall : 0.21 * params.requiredSats;
5295
5298
  this._log(
5296
5299
  "DEBUG",
5297
- `The shortfall is: ${shortfall}. requiredSats: ${params.requiredSats}. Current Balance: ${currentBalance} `
5300
+ `The shortfall is: ${shortfall}. requiredSats: ${params.requiredSats}. Current Balance: ${currentBalance}. Reserved Balance: ${reservedBalance}. Available Balance: ${currentBalance - reservedBalance}`
5298
5301
  );
5299
5302
  } catch (e) {
5300
5303
  this._log(
@@ -5439,10 +5442,10 @@ var RoutstrClient = class {
5439
5442
  tryNextProvider = true;
5440
5443
  }
5441
5444
  }
5442
- if ((status === 401 || status === 403 || status === 413 || status === 400 || status === 500 || status === 502 || status === 503 || status === 504 || status === 521) && !tryNextProvider) {
5445
+ if ((status === 401 || status === 403 || status === 413 || status === 400 || status === 429 || status === 500 || status === 502 || status === 503 || status === 504 || status === 521) && !tryNextProvider) {
5443
5446
  this._log(
5444
5447
  "DEBUG",
5445
- `[RoutstrClient] _handleErrorResponse: Status ${status} (auth/server error), attempting refund for ${baseUrl}, mode=${this.mode}`
5448
+ `[RoutstrClient] _handleErrorResponse: Status ${status} (${status === 429 ? "rate limited" : "auth/server error"}), attempting refund for ${baseUrl}, mode=${this.mode}`
5446
5449
  );
5447
5450
  if (this.mode === "apikeys") {
5448
5451
  this._log(