routstrd 0.2.19 → 0.2.20

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/bun.lock CHANGED
@@ -4,7 +4,7 @@
4
4
  "": {
5
5
  "dependencies": {
6
6
  "@cashu/cashu-ts": "^3.1.1",
7
- "@routstr/sdk": "^0.3.4",
7
+ "@routstr/sdk": "^0.3.5",
8
8
  "applesauce-core": "^5.1.0",
9
9
  "applesauce-relay": "^5.1.0",
10
10
  "commander": "^14.0.2",
@@ -31,7 +31,7 @@
31
31
 
32
32
  "@noble/hashes": ["@noble/hashes@2.0.1", "", {}, "sha512-XlOlEbQcE9fmuXxrVTXCTlG2nlRXa9Rj3rr5Ue/+tX+nmkgbX720YHh0VR3hBF9xDvwnb8D2shVGOwNx+ulArw=="],
33
33
 
34
- "@routstr/sdk": ["@routstr/sdk@0.3.4", "", { "dependencies": { "@cashu/cashu-ts": "^3.1.1", "applesauce-core": "^5.1.0", "applesauce-relay": "^5.1.0", "rxjs": "^7.8.1", "zustand": "^5.0.5" }, "optionalDependencies": { "better-sqlite3": "^11.7.2" }, "peerDependencies": { "typescript": ">=5.0.0" } }, "sha512-v07U5M9r/gzRRiT3fFn5NvKv0QM17UU1h1OlGS1Yw2LpXVAVNzmrfJRyLfyx7XNz8JVRkj50AeBIoMjRBiqZMQ=="],
34
+ "@routstr/sdk": ["@routstr/sdk@0.3.5", "", { "dependencies": { "@cashu/cashu-ts": "^3.1.1", "applesauce-core": "^5.1.0", "applesauce-relay": "^5.1.0", "rxjs": "^7.8.1", "zustand": "^5.0.5" }, "optionalDependencies": { "better-sqlite3": "^11.7.2" }, "peerDependencies": { "typescript": ">=5.0.0" } }, "sha512-xMdZhrtGCfNJmneW6BIA/oxtMQhQEU37FlBIyXnI/s4KQTg6qkTr4MrKYacwswM+dL0j3BMmZuSbGVitlAc9lQ=="],
35
35
 
36
36
  "@scure/base": ["@scure/base@2.0.0", "", {}, "sha512-3E1kpuZginKkek01ovG8krQ0Z44E3DHPjc5S2rjJw9lZn3KSQOs8S7wqikF/AH7iRanHypj85uGyxk0XAyC37w=="],
37
37
 
@@ -33628,16 +33628,38 @@ var import_rxjs24, consoleLogger, noopLogger, InsufficientBalanceError, Provider
33628
33628
  for (const apiKeyEntry of apiKeyDistribution) {
33629
33629
  const apiKeyEntryFull = this.storageAdapter.getApiKey(apiKeyEntry.baseUrl);
33630
33630
  if (apiKeyEntryFull && this.balanceManager) {
33631
+ try {
33632
+ const balanceResult = await this.balanceManager.getTokenBalance(apiKeyEntryFull.key, apiKeyEntry.baseUrl);
33633
+ if (balanceResult.isInvalidApiKey) {
33634
+ this.storageAdapter.removeApiKey(apiKeyEntry.baseUrl);
33635
+ results.push({
33636
+ baseUrl: apiKeyEntry.baseUrl,
33637
+ success: true
33638
+ });
33639
+ continue;
33640
+ }
33641
+ if (balanceResult.amount >= 0) {
33642
+ const balanceSat = balanceResult.unit === "msat" ? Math.floor(balanceResult.amount / 1000) : balanceResult.amount;
33643
+ this.storageAdapter.updateApiKeyBalance(apiKeyEntry.baseUrl, balanceSat);
33644
+ }
33645
+ } catch {
33646
+ }
33647
+ const refreshedEntry = this.storageAdapter.getApiKey(apiKeyEntry.baseUrl);
33648
+ if (!refreshedEntry)
33649
+ continue;
33631
33650
  const refundResult = await this.balanceManager.refundApiKey({
33632
33651
  mintUrl,
33633
33652
  baseUrl: apiKeyEntry.baseUrl,
33634
- apiKey: apiKeyEntryFull.key,
33653
+ apiKey: refreshedEntry.key,
33635
33654
  forceRefund
33636
33655
  });
33637
33656
  if (refundResult.success) {
33638
33657
  this.storageAdapter.removeApiKey(apiKeyEntry.baseUrl);
33639
33658
  } else {
33640
- this.storageAdapter.updateApiKeyBalance(apiKeyEntry.baseUrl, apiKeyEntry.amount);
33659
+ const currentEntry = this.storageAdapter.getApiKey(apiKeyEntry.baseUrl);
33660
+ if (currentEntry) {
33661
+ this.storageAdapter.updateApiKeyBalance(apiKeyEntry.baseUrl, currentEntry.balance);
33662
+ }
33641
33663
  }
33642
33664
  results.push({
33643
33665
  baseUrl: apiKeyEntry.baseUrl,
@@ -33819,7 +33841,8 @@ var import_rxjs24, consoleLogger, noopLogger, InsufficientBalanceError, Provider
33819
33841
  };
33820
33842
  }
33821
33843
  if (fetchResult.error === "No balance to refund") {
33822
- return { success: false, message: "No balance to refund" };
33844
+ this.storageAdapter.removeApiKey(baseUrl);
33845
+ return { success: true, message: "No balance to refund, key cleaned up" };
33823
33846
  }
33824
33847
  const receiveResult = await this.cashuSpender.receiveToken(fetchResult.token);
33825
33848
  const totalAmountMsat = receiveResult.unit === "msat" ? receiveResult.amount : receiveResult.amount * 1000;
@@ -35977,9 +36000,7 @@ var import_rxjs24, consoleLogger, noopLogger, InsufficientBalanceError, Provider
35977
36000
  const distributionMap = {};
35978
36001
  for (const entry of apiKeys) {
35979
36002
  const sum = entry.balance || 0;
35980
- if (sum > 0) {
35981
- distributionMap[entry.baseUrl] = (distributionMap[entry.baseUrl] || 0) + sum;
35982
- }
36003
+ distributionMap[entry.baseUrl] = (distributionMap[entry.baseUrl] || 0) + sum;
35983
36004
  }
35984
36005
  return Object.entries(distributionMap).map(([baseUrl, amt]) => ({ baseUrl, amount: amt })).sort((a, b) => b.amount - a.amount);
35985
36006
  },
package/dist/index.js CHANGED
@@ -15629,7 +15629,7 @@ async function isCocodInstalled(cocodPath) {
15629
15629
  // package.json
15630
15630
  var package_default = {
15631
15631
  name: "routstrd",
15632
- version: "0.2.19",
15632
+ version: "0.2.20",
15633
15633
  module: "src/index.ts",
15634
15634
  type: "module",
15635
15635
  private: false,
@@ -15653,7 +15653,7 @@ var package_default = {
15653
15653
  },
15654
15654
  dependencies: {
15655
15655
  "@cashu/cashu-ts": "^3.1.1",
15656
- "@routstr/sdk": "^0.3.4",
15656
+ "@routstr/sdk": "^0.3.5",
15657
15657
  "applesauce-core": "^5.1.0",
15658
15658
  "applesauce-relay": "^5.1.0",
15659
15659
  commander: "^14.0.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "routstrd",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
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.4",
27
+ "@routstr/sdk": "^0.3.5",
28
28
  "applesauce-core": "^5.1.0",
29
29
  "applesauce-relay": "^5.1.0",
30
30
  "commander": "^14.0.2",