@routstr/sdk 0.1.3 → 0.1.5
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/client/index.js +12 -4
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +12 -4
- package/dist/client/index.mjs.map +1 -1
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +17 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -5
- package/dist/index.mjs.map +1 -1
- package/dist/wallet/index.js +3 -0
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +3 -0
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1314,6 +1314,9 @@ var BalanceManager = class {
|
|
|
1314
1314
|
fetchResult.token
|
|
1315
1315
|
);
|
|
1316
1316
|
const totalAmountMsat = receiveResult.unit === "msat" ? receiveResult.amount : receiveResult.amount * 1e3;
|
|
1317
|
+
if (receiveResult.success) {
|
|
1318
|
+
this.storageAdapter.removeApiKey(baseUrl);
|
|
1319
|
+
}
|
|
1317
1320
|
return {
|
|
1318
1321
|
success: receiveResult.success,
|
|
1319
1322
|
refundedAmount: totalAmountMsat,
|
|
@@ -2450,7 +2453,7 @@ var ProviderManager = class {
|
|
|
2450
2453
|
};
|
|
2451
2454
|
|
|
2452
2455
|
// client/RoutstrClient.ts
|
|
2453
|
-
var TOPUP_MARGIN =
|
|
2456
|
+
var TOPUP_MARGIN = 1.2;
|
|
2454
2457
|
var RoutstrClient = class {
|
|
2455
2458
|
constructor(walletAdapter, storageAdapter, providerRegistry, alertLevel, mode = "xcashu") {
|
|
2456
2459
|
this.walletAdapter = walletAdapter;
|
|
@@ -2737,12 +2740,14 @@ var RoutstrClient = class {
|
|
|
2737
2740
|
try {
|
|
2738
2741
|
const url = `${baseUrl.replace(/\/$/, "")}${path}`;
|
|
2739
2742
|
if (this.mode === "xcashu") this._log("DEBUG", "HEADERS,", headers);
|
|
2743
|
+
this._log("DEBUG", "HEADERS,", headers);
|
|
2740
2744
|
const response = await fetch(url, {
|
|
2741
2745
|
method,
|
|
2742
2746
|
headers,
|
|
2743
2747
|
body: body === void 0 || method === "GET" ? void 0 : JSON.stringify(body)
|
|
2744
2748
|
});
|
|
2745
2749
|
if (this.mode === "xcashu") this._log("DEBUG", "response,", response);
|
|
2750
|
+
this._log("DEBUG", "response,", response);
|
|
2746
2751
|
response.baseUrl = baseUrl;
|
|
2747
2752
|
response.token = token;
|
|
2748
2753
|
if (!response.ok) {
|
|
@@ -2849,6 +2854,7 @@ var RoutstrClient = class {
|
|
|
2849
2854
|
}
|
|
2850
2855
|
}
|
|
2851
2856
|
if ((status === 402 || status === 413 && responseBody?.includes("Insufficient balance")) && !tryNextProvider && (this.mode === "apikeys" || this.mode === "lazyrefund")) {
|
|
2857
|
+
console.log("RESPONSFE ", responseBody);
|
|
2852
2858
|
const topupResult = await this.balanceManager.topUp({
|
|
2853
2859
|
mintUrl,
|
|
2854
2860
|
baseUrl,
|
|
@@ -2951,8 +2957,6 @@ var RoutstrClient = class {
|
|
|
2951
2957
|
status,
|
|
2952
2958
|
refundResult.message ?? "Unknown error"
|
|
2953
2959
|
);
|
|
2954
|
-
} else {
|
|
2955
|
-
this.storageAdapter.removeApiKey(baseUrl);
|
|
2956
2960
|
}
|
|
2957
2961
|
}
|
|
2958
2962
|
}
|
|
@@ -3051,7 +3055,11 @@ var RoutstrClient = class {
|
|
|
3051
3055
|
baseUrl
|
|
3052
3056
|
);
|
|
3053
3057
|
const latestTokenBalance = latestBalanceInfo.unit === "msat" ? latestBalanceInfo.amount / 1e3 : latestBalanceInfo.amount;
|
|
3054
|
-
this.storageAdapter.
|
|
3058
|
+
const storedApiKeyEntry = this.storageAdapter.getApiKey(baseUrl);
|
|
3059
|
+
if (storedApiKeyEntry?.key.startsWith("cashu") && latestBalanceInfo.apiKey) {
|
|
3060
|
+
this.storageAdapter.removeApiKey(baseUrl);
|
|
3061
|
+
this.storageAdapter.setApiKey(baseUrl, latestBalanceInfo.apiKey);
|
|
3062
|
+
}
|
|
3055
3063
|
this.storageAdapter.updateApiKeyBalance(baseUrl, latestTokenBalance);
|
|
3056
3064
|
satsSpent = initialTokenBalance - latestTokenBalance;
|
|
3057
3065
|
} catch (e) {
|
|
@@ -4213,7 +4221,8 @@ async function routeRequests(options) {
|
|
|
4213
4221
|
includeProviderUrls = [],
|
|
4214
4222
|
torMode = false,
|
|
4215
4223
|
forceRefresh = false,
|
|
4216
|
-
modelManager: providedModelManager
|
|
4224
|
+
modelManager: providedModelManager,
|
|
4225
|
+
debugLevel
|
|
4217
4226
|
} = options;
|
|
4218
4227
|
let modelManager;
|
|
4219
4228
|
let providers;
|
|
@@ -4280,6 +4289,9 @@ async function routeRequests(options) {
|
|
|
4280
4289
|
alertLevel,
|
|
4281
4290
|
"apikeys"
|
|
4282
4291
|
);
|
|
4292
|
+
if (debugLevel) {
|
|
4293
|
+
client.setDebugLevel(debugLevel);
|
|
4294
|
+
}
|
|
4283
4295
|
const maxTokens = extractMaxTokens(requestBody);
|
|
4284
4296
|
const stream = extractStream(requestBody);
|
|
4285
4297
|
let response = null;
|