routstrd 0.2.3 → 0.2.4

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.
@@ -30266,6 +30266,8 @@ var import_rxjs24, InsufficientBalanceError, ProviderError, MintUnreachableError
30266
30266
  const msg = error.message.toLowerCase();
30267
30267
  if (msg.includes("fetch failed"))
30268
30268
  return true;
30269
+ if (msg.includes("429"))
30270
+ return true;
30269
30271
  if (msg.includes("502"))
30270
30272
  return true;
30271
30273
  if (msg.includes("503"))
@@ -30474,6 +30476,8 @@ var import_rxjs24, InsufficientBalanceError, ProviderError, MintUnreachableError
30474
30476
  const msg = error.message.toLowerCase();
30475
30477
  if (msg.includes("fetch failed"))
30476
30478
  return true;
30479
+ if (msg.includes("429"))
30480
+ return true;
30477
30481
  if (msg.includes("502"))
30478
30482
  return true;
30479
30483
  if (msg.includes("503"))
@@ -33881,9 +33885,10 @@ var import_rxjs24, InsufficientBalanceError, ProviderError, MintUnreachableError
33881
33885
  try {
33882
33886
  const currentBalanceInfo = await this.balanceManager.getTokenBalance(params.token, baseUrl);
33883
33887
  const currentBalance = currentBalanceInfo.unit === "msat" ? currentBalanceInfo.amount / 1000 : currentBalanceInfo.amount;
33884
- const shortfall = Math.max(0, params.requiredSats - currentBalance);
33888
+ const reservedBalance = currentBalanceInfo.unit === "msat" ? (currentBalanceInfo.reserved ?? 0) / 1000 : currentBalanceInfo.reserved ?? 0;
33889
+ const shortfall = Math.max(0, params.requiredSats - currentBalance + reservedBalance);
33885
33890
  topupAmount = shortfall > 0.21 * params.requiredSats ? shortfall : 0.21 * params.requiredSats;
33886
- this._log("DEBUG", `The shortfall is: ${shortfall}. requiredSats: ${params.requiredSats}. Current Balance: ${currentBalance} `);
33891
+ this._log("DEBUG", `The shortfall is: ${shortfall}. requiredSats: ${params.requiredSats}. Current Balance: ${currentBalance}. Reserved Balance: ${reservedBalance}. Available Balance: ${currentBalance - reservedBalance}`);
33887
33892
  } catch (e) {
33888
33893
  this._log("WARN", "Could not get current token balance for topup calculation:", e);
33889
33894
  }
@@ -33974,8 +33979,8 @@ var import_rxjs24, InsufficientBalanceError, ProviderError, MintUnreachableError
33974
33979
  tryNextProvider = true;
33975
33980
  }
33976
33981
  }
33977
- if ((status === 401 || status === 403 || status === 413 || status === 400 || status === 500 || status === 502 || status === 503 || status === 504 || status === 521) && !tryNextProvider) {
33978
- this._log("DEBUG", `[RoutstrClient] _handleErrorResponse: Status ${status} (auth/server error), attempting refund for ${baseUrl}, mode=${this.mode}`);
33982
+ if ((status === 401 || status === 403 || status === 413 || status === 400 || status === 429 || status === 500 || status === 502 || status === 503 || status === 504 || status === 521) && !tryNextProvider) {
33983
+ this._log("DEBUG", `[RoutstrClient] _handleErrorResponse: Status ${status} (${status === 429 ? "rate limited" : "auth/server error"}), attempting refund for ${baseUrl}, mode=${this.mode}`);
33979
33984
  if (this.mode === "apikeys") {
33980
33985
  this._log("DEBUG", `[RoutstrClient] _handleErrorResponse: Attempting API key refund for ${baseUrl}, key preview=${token}`);
33981
33986
  const latestBalanceInfo = await this.balanceManager.getTokenBalance(token, baseUrl);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "routstrd",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "private": false,
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@cashu/cashu-ts": "^3.1.1",
27
- "@routstr/sdk": "^0.3.0",
27
+ "@routstr/sdk": "^0.3.1",
28
28
  "applesauce-core": "^5.1.0",
29
29
  "applesauce-relay": "^5.1.0",
30
30
  "commander": "^14.0.2",