@routstr/sdk 0.3.6 → 0.3.8

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.
Files changed (35) hide show
  1. package/dist/client/index.d.mts +4 -4
  2. package/dist/client/index.d.ts +4 -4
  3. package/dist/client/index.js +69 -10
  4. package/dist/client/index.js.map +1 -1
  5. package/dist/client/index.mjs +69 -10
  6. package/dist/client/index.mjs.map +1 -1
  7. package/dist/discovery/index.d.mts +2 -2
  8. package/dist/discovery/index.d.ts +2 -2
  9. package/dist/discovery/index.js +3 -0
  10. package/dist/discovery/index.js.map +1 -1
  11. package/dist/discovery/index.mjs +3 -0
  12. package/dist/discovery/index.mjs.map +1 -1
  13. package/dist/index.d.mts +12 -10
  14. package/dist/index.d.ts +12 -10
  15. package/dist/index.js +81 -14
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +81 -14
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/{interfaces-D2FDCLyP.d.ts → interfaces-C-DYd9Jy.d.ts} +1 -1
  20. package/dist/{interfaces-Bp0Ngmqv.d.mts → interfaces-Csn8Uq04.d.mts} +1 -1
  21. package/dist/{interfaces-Cqkt41QR.d.mts → interfaces-Cv1k2EUK.d.mts} +1 -1
  22. package/dist/{interfaces-D9qI1ym6.d.ts → interfaces-iL7CWeG5.d.ts} +1 -1
  23. package/dist/storage/index.d.mts +6 -6
  24. package/dist/storage/index.d.ts +6 -6
  25. package/dist/{store-BFUGGr_v.d.ts → store-58VcEUoA.d.ts} +3 -3
  26. package/dist/{store-C4FyyOnO.d.mts → store-C6dfj1cc.d.mts} +3 -3
  27. package/dist/{types-DPQM6tIG.d.mts → types-_21yYFZG.d.mts} +1 -1
  28. package/dist/{types-DPQM6tIG.d.ts → types-_21yYFZG.d.ts} +1 -1
  29. package/dist/wallet/index.d.mts +4 -4
  30. package/dist/wallet/index.d.ts +4 -4
  31. package/dist/wallet/index.js +55 -8
  32. package/dist/wallet/index.js.map +1 -1
  33. package/dist/wallet/index.mjs +55 -8
  34. package/dist/wallet/index.mjs.map +1 -1
  35. package/package.json +2 -2
@@ -25,6 +25,10 @@ var InsufficientBalanceError = class extends Error {
25
25
  this.maxMintUrl = maxMintUrl;
26
26
  this.name = "InsufficientBalanceError";
27
27
  }
28
+ required;
29
+ available;
30
+ maxMintBalance;
31
+ maxMintUrl;
28
32
  };
29
33
 
30
34
  // wallet/AuditLogger.ts
@@ -98,6 +102,10 @@ var CashuSpender = class {
98
102
  this.balanceManager = balanceManager;
99
103
  this.logger = (logger ?? consoleLogger).child("CashuSpender");
100
104
  }
105
+ walletAdapter;
106
+ storageAdapter;
107
+ _providerRegistry;
108
+ balanceManager;
101
109
  _isBusy = false;
102
110
  debugLevel = "WARN";
103
111
  logger;
@@ -556,6 +564,9 @@ var CashuSpender = class {
556
564
  apiKeyEntry.baseUrl
557
565
  );
558
566
  if (balanceResult.isInvalidApiKey) {
567
+ this.logger.warn(
568
+ `refundProviders: ${apiKeyEntry.baseUrl} returned invalid API key; removing local key and treating as success`
569
+ );
559
570
  this.storageAdapter.removeApiKey(apiKeyEntry.baseUrl);
560
571
  results.push({
561
572
  baseUrl: apiKeyEntry.baseUrl,
@@ -569,13 +580,23 @@ var CashuSpender = class {
569
580
  apiKeyEntry.baseUrl,
570
581
  balanceSat
571
582
  );
583
+ } else {
584
+ this.logger.warn(
585
+ `refundProviders: balance refresh for ${apiKeyEntry.baseUrl} returned negative amount; keeping stale local balance=${apiKeyEntryFull.balance}`
586
+ );
572
587
  }
573
- } catch {
588
+ } catch (error) {
589
+ this.logger.warn(
590
+ `refundProviders: balance refresh threw for ${apiKeyEntry.baseUrl}; proceeding with stale local balance`,
591
+ error
592
+ );
574
593
  }
575
594
  const refreshedEntry = this.storageAdapter.getApiKey(
576
595
  apiKeyEntry.baseUrl
577
596
  );
578
- if (!refreshedEntry) continue;
597
+ if (!refreshedEntry) {
598
+ continue;
599
+ }
579
600
  const refundResult = await this.balanceManager.refundApiKey({
580
601
  mintUrl,
581
602
  baseUrl: apiKeyEntry.baseUrl,
@@ -588,6 +609,9 @@ var CashuSpender = class {
588
609
  const currentEntry = this.storageAdapter.getApiKey(
589
610
  apiKeyEntry.baseUrl
590
611
  );
612
+ this.logger.warn(
613
+ `refundProviders: refund failed for ${apiKeyEntry.baseUrl}; currentEntry=${Boolean(currentEntry)} balance=${currentEntry?.balance ?? "none"}. Touching lastUsed to rate-limit retries.`
614
+ );
591
615
  if (currentEntry) {
592
616
  this.storageAdapter.updateApiKeyBalance(
593
617
  apiKeyEntry.baseUrl,
@@ -600,6 +624,9 @@ var CashuSpender = class {
600
624
  success: refundResult.success
601
625
  });
602
626
  } else {
627
+ this.logger.warn(
628
+ `refundProviders: cannot refund ${apiKeyEntry.baseUrl}; apiKeyEntryFull=${Boolean(apiKeyEntryFull)} balanceManager=${Boolean(this.balanceManager)}`
629
+ );
603
630
  results.push({
604
631
  baseUrl: apiKeyEntry.baseUrl,
605
632
  success: false
@@ -672,10 +699,14 @@ var BalanceManager = class _BalanceManager {
672
699
  walletAdapter,
673
700
  storageAdapter,
674
701
  providerRegistry,
675
- this
702
+ this,
703
+ this.logger
676
704
  );
677
705
  }
678
706
  }
707
+ walletAdapter;
708
+ storageAdapter;
709
+ providerRegistry;
679
710
  cashuSpender;
680
711
  /** In-memory guard for per-provider wallet mutations (topup / refund) */
681
712
  providerWalletOps = /* @__PURE__ */ new Map();
@@ -769,6 +800,7 @@ var BalanceManager = class _BalanceManager {
769
800
  async _refundApiKeyImpl(options) {
770
801
  const { mintUrl, baseUrl, apiKey, forceRefund } = options;
771
802
  if (!apiKey) {
803
+ this.logger.warn(`refundApiKey: aborting for ${baseUrl} - no API key`);
772
804
  return { success: false, message: "No API key to refund" };
773
805
  }
774
806
  if (!forceRefund) {
@@ -776,7 +808,9 @@ var BalanceManager = class _BalanceManager {
776
808
  if (apiKeyEntry?.lastUsed) {
777
809
  const fiveMinutesAgo = Date.now() - 5 * 60 * 1e3;
778
810
  if (apiKeyEntry.lastUsed > fiveMinutesAgo) {
779
- this.logger.log(`Skipping refund for ${baseUrl} - used ${Math.round((Date.now() - apiKeyEntry.lastUsed) / 1e3)}s ago`);
811
+ this.logger.log(
812
+ `refundApiKey: skipping ${baseUrl} - used ${Math.round((Date.now() - apiKeyEntry.lastUsed) / 1e3)}s ago`
813
+ );
780
814
  return {
781
815
  success: false,
782
816
  message: "API key was used recently, skipping refund"
@@ -787,7 +821,15 @@ var BalanceManager = class _BalanceManager {
787
821
  let fetchResult;
788
822
  try {
789
823
  fetchResult = await this.fetchRefundToken(baseUrl, apiKey);
824
+ if (fetchResult.error === "No balance to refund") {
825
+ this.logger.log(`refundApiKey: provider says no balance for ${baseUrl}; removing API key`);
826
+ this.storageAdapter.removeApiKey(baseUrl);
827
+ return { success: true, message: "No balance to refund, key cleaned up" };
828
+ }
790
829
  if (!fetchResult.success) {
830
+ this.logger.warn(
831
+ `refundApiKey: fetch failed for ${baseUrl}: ${fetchResult.error || "API key refund failed"}`
832
+ );
791
833
  return {
792
834
  success: false,
793
835
  message: fetchResult.error || "API key refund failed",
@@ -795,22 +837,23 @@ var BalanceManager = class _BalanceManager {
795
837
  };
796
838
  }
797
839
  if (!fetchResult.token) {
840
+ this.logger.warn(`refundApiKey: no token received for ${baseUrl}`);
798
841
  return {
799
842
  success: false,
800
843
  message: "No token received from API key refund",
801
844
  requestId: fetchResult.requestId
802
845
  };
803
846
  }
804
- if (fetchResult.error === "No balance to refund") {
805
- this.storageAdapter.removeApiKey(baseUrl);
806
- return { success: true, message: "No balance to refund, key cleaned up" };
807
- }
808
847
  const receiveResult = await this.cashuSpender.receiveToken(
809
848
  fetchResult.token
810
849
  );
811
850
  const totalAmountMsat = receiveResult.unit === "msat" ? receiveResult.amount : receiveResult.amount * 1e3;
812
851
  if (receiveResult.success) {
813
852
  this.storageAdapter.removeApiKey(baseUrl);
853
+ } else {
854
+ this.logger.warn(
855
+ `refundApiKey: receive failed for ${baseUrl}; keeping API key. message=${receiveResult.message ?? "none"}`
856
+ );
814
857
  }
815
858
  return {
816
859
  success: receiveResult.success,
@@ -857,6 +900,10 @@ var BalanceManager = class _BalanceManager {
857
900
  const requestId = response.headers.get("x-routstr-request-id") || void 0;
858
901
  if (!response.ok) {
859
902
  const errorData = await response.json().catch(() => ({}));
903
+ this.logger.warn(
904
+ `fetchRefundToken: non-ok response for ${url} status=${response.status} statusText=${response.statusText}`,
905
+ errorData
906
+ );
860
907
  return {
861
908
  success: false,
862
909
  requestId,