@trustware/sdk-staging 1.1.11-staging.1 → 1.1.11-staging.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/README.md +54 -21
- package/dist/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/{core-BgYLe9Q7.d.ts → core-B1WCJfDI.d.ts} +1 -1
- package/dist/{core-fLSt4qD2.d.cts → core-CeNTuqPz.d.cts} +1 -1
- package/dist/core.cjs +85 -43
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.mjs +83 -42
- package/dist/core.mjs.map +1 -1
- package/dist/index.cjs +107 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.mjs +105 -55
- package/dist/index.mjs.map +1 -1
- package/dist/{manager-BY3NHAks.d.ts → manager-Bw8b1wSD.d.ts} +89 -22
- package/dist/{manager-DT8enQbE.d.cts → manager-DNGk1YkR.d.cts} +89 -22
- package/dist/{metadata-BPvFYMlc.d.ts → metadata-C__KMeuz.d.ts} +1 -1
- package/dist/{metadata-DyxUcKHk.d.cts → metadata-Dk4R8_-T.d.cts} +1 -1
- package/dist/smart-account.cjs +49 -44
- package/dist/smart-account.cjs.map +1 -1
- package/dist/smart-account.d.cts +5 -0
- package/dist/smart-account.d.ts +5 -0
- package/dist/smart-account.mjs +49 -44
- package/dist/smart-account.mjs.map +1 -1
- package/dist/wallet.cjs +40 -39
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.d.cts +3 -3
- package/dist/wallet.d.ts +3 -3
- package/dist/wallet.mjs +40 -39
- package/dist/wallet.mjs.map +1 -1
- package/dist/widget.cjs +101 -55
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.mjs +101 -55
- package/dist/widget.mjs.map +1 -1
- package/package.json +73 -5
package/dist/smart-account.d.cts
CHANGED
|
@@ -3953,6 +3953,11 @@ type RoutePlan = {
|
|
|
3953
3953
|
};
|
|
3954
3954
|
steps?: unknown[];
|
|
3955
3955
|
provider?: string;
|
|
3956
|
+
/** The winning provider's own correlation ID, not Trustware's — it is
|
|
3957
|
+
* absent when that provider issued none, and it is what lands on the
|
|
3958
|
+
* intent as `providerRequestId`. Trustware's request ID for the same call
|
|
3959
|
+
* comes back in the `X-Request-Id` response header (the provider's is also
|
|
3960
|
+
* mirrored there as `X-Provider-Request-Id`). */
|
|
3956
3961
|
requestId?: string;
|
|
3957
3962
|
reliabilityScore?: number;
|
|
3958
3963
|
diagnostics?: {
|
package/dist/smart-account.d.ts
CHANGED
|
@@ -3953,6 +3953,11 @@ type RoutePlan = {
|
|
|
3953
3953
|
};
|
|
3954
3954
|
steps?: unknown[];
|
|
3955
3955
|
provider?: string;
|
|
3956
|
+
/** The winning provider's own correlation ID, not Trustware's — it is
|
|
3957
|
+
* absent when that provider issued none, and it is what lands on the
|
|
3958
|
+
* intent as `providerRequestId`. Trustware's request ID for the same call
|
|
3959
|
+
* comes back in the `X-Request-Id` response header (the provider's is also
|
|
3960
|
+
* mirrored there as `X-Provider-Request-Id`). */
|
|
3956
3961
|
requestId?: string;
|
|
3957
3962
|
reliabilityScore?: number;
|
|
3958
3963
|
diagnostics?: {
|
package/dist/smart-account.mjs
CHANGED
|
@@ -12241,7 +12241,7 @@ var init_constants = __esm({
|
|
|
12241
12241
|
"src/constants.ts"() {
|
|
12242
12242
|
"use strict";
|
|
12243
12243
|
SDK_NAME = "@trustware/sdk";
|
|
12244
|
-
SDK_VERSION = "1.1.11-staging.
|
|
12244
|
+
SDK_VERSION = "1.1.11-staging.2";
|
|
12245
12245
|
API_ROOT = "https://bv-staging-api.trustware.io";
|
|
12246
12246
|
API_PREFIX = "/api";
|
|
12247
12247
|
}
|
|
@@ -12262,16 +12262,14 @@ var init_defaults3 = __esm({
|
|
|
12262
12262
|
});
|
|
12263
12263
|
|
|
12264
12264
|
// src/types/config.ts
|
|
12265
|
-
var DEFAULT_RETRY_CONFIG, DEFAULT_FEATURE_FLAGS;
|
|
12265
|
+
var DEFAULT_RETRY_CONFIG, RATE_LIMIT_WAIT_BUDGET_MS, DEFAULT_FEATURE_FLAGS;
|
|
12266
12266
|
var init_config = __esm({
|
|
12267
12267
|
"src/types/config.ts"() {
|
|
12268
12268
|
"use strict";
|
|
12269
12269
|
DEFAULT_RETRY_CONFIG = {
|
|
12270
|
-
autoRetry: true,
|
|
12271
|
-
maxRetries: 3,
|
|
12272
|
-
baseDelayMs: 1e3,
|
|
12273
12270
|
approachingThreshold: 5
|
|
12274
12271
|
};
|
|
12272
|
+
RATE_LIMIT_WAIT_BUDGET_MS = 1e4;
|
|
12275
12273
|
DEFAULT_FEATURE_FLAGS = {
|
|
12276
12274
|
tokensPagination: true,
|
|
12277
12275
|
balanceStreaming: false,
|
|
@@ -13547,9 +13545,6 @@ function resolveConfig(input) {
|
|
|
13547
13545
|
const theme = input.theme ?? "system";
|
|
13548
13546
|
const messages = deepMerge(DEFAULT_MESSAGES, input.messages);
|
|
13549
13547
|
const retry = {
|
|
13550
|
-
autoRetry: input.retry?.autoRetry ?? DEFAULT_RETRY_CONFIG.autoRetry,
|
|
13551
|
-
maxRetries: input.retry?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,
|
|
13552
|
-
baseDelayMs: input.retry?.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,
|
|
13553
13548
|
approachingThreshold: input.retry?.approachingThreshold ?? DEFAULT_RETRY_CONFIG.approachingThreshold,
|
|
13554
13549
|
onRateLimitInfo: input.retry?.onRateLimitInfo,
|
|
13555
13550
|
onRateLimited: input.retry?.onRateLimited,
|
|
@@ -13660,60 +13655,66 @@ function notifyRateLimitCallbacks(info, isRateLimited, retryCount) {
|
|
|
13660
13655
|
retry.onRateLimitApproaching(info, retry.approachingThreshold);
|
|
13661
13656
|
}
|
|
13662
13657
|
}
|
|
13663
|
-
function
|
|
13664
|
-
if (
|
|
13665
|
-
|
|
13658
|
+
function serverDirectedWaitMs(info) {
|
|
13659
|
+
if (!info) return null;
|
|
13660
|
+
if (typeof info.retryAfter === "number" && info.retryAfter > 0) {
|
|
13661
|
+
return info.retryAfter * 1e3;
|
|
13666
13662
|
}
|
|
13667
|
-
|
|
13663
|
+
if (typeof info.reset === "number" && info.reset > 0) {
|
|
13664
|
+
const untilReset = info.reset * 1e3 - Date.now();
|
|
13665
|
+
if (untilReset > 0) return untilReset;
|
|
13666
|
+
}
|
|
13667
|
+
return null;
|
|
13668
13668
|
}
|
|
13669
13669
|
function sleep(ms) {
|
|
13670
13670
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
13671
13671
|
}
|
|
13672
|
-
async function
|
|
13673
|
-
|
|
13674
|
-
const cfg = TrustwareConfigStore.get();
|
|
13675
|
-
if (!cfg.retry.autoRetry || skipRateLimit) {
|
|
13676
|
-
return fetch(url, fetchOptions);
|
|
13677
|
-
}
|
|
13678
|
-
const { maxRetries, baseDelayMs } = cfg.retry;
|
|
13672
|
+
async function withRateLimitRetry(attempt) {
|
|
13673
|
+
let waitedMs = 0;
|
|
13679
13674
|
let retryCount = 0;
|
|
13680
13675
|
while (true) {
|
|
13681
|
-
const response = await
|
|
13676
|
+
const response = await attempt();
|
|
13682
13677
|
const rateLimitInfo = parseRateLimitHeaders(response);
|
|
13683
|
-
if (response.status
|
|
13678
|
+
if (response.status !== 429) {
|
|
13684
13679
|
if (rateLimitInfo) {
|
|
13685
|
-
notifyRateLimitCallbacks(rateLimitInfo,
|
|
13686
|
-
}
|
|
13687
|
-
if (retryCount >= maxRetries) {
|
|
13688
|
-
throw new RateLimitError(
|
|
13689
|
-
rateLimitInfo || { limit: 0, remaining: 0, reset: 0 },
|
|
13690
|
-
true
|
|
13691
|
-
);
|
|
13680
|
+
notifyRateLimitCallbacks(rateLimitInfo, false, 0);
|
|
13692
13681
|
}
|
|
13693
|
-
|
|
13694
|
-
baseDelayMs,
|
|
13695
|
-
retryCount,
|
|
13696
|
-
rateLimitInfo?.retryAfter
|
|
13697
|
-
);
|
|
13698
|
-
await sleep(delay);
|
|
13699
|
-
retryCount++;
|
|
13700
|
-
continue;
|
|
13682
|
+
return response;
|
|
13701
13683
|
}
|
|
13702
13684
|
if (rateLimitInfo) {
|
|
13703
|
-
notifyRateLimitCallbacks(rateLimitInfo,
|
|
13685
|
+
notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
|
|
13686
|
+
}
|
|
13687
|
+
const waitMs = serverDirectedWaitMs(rateLimitInfo);
|
|
13688
|
+
const info = rateLimitInfo || { limit: 0, remaining: 0, reset: 0 };
|
|
13689
|
+
if (waitMs === null) {
|
|
13690
|
+
throw new RateLimitError(info, true);
|
|
13691
|
+
}
|
|
13692
|
+
if (waitedMs + waitMs > RATE_LIMIT_WAIT_BUDGET_MS) {
|
|
13693
|
+
throw new RateLimitError(info, false);
|
|
13704
13694
|
}
|
|
13705
|
-
|
|
13695
|
+
await sleep(waitMs);
|
|
13696
|
+
waitedMs += waitMs;
|
|
13697
|
+
retryCount++;
|
|
13706
13698
|
}
|
|
13707
13699
|
}
|
|
13700
|
+
async function rateLimitedFetch(url, options = {}) {
|
|
13701
|
+
const { skipRateLimit, ...fetchOptions } = options;
|
|
13702
|
+
if (skipRateLimit) {
|
|
13703
|
+
return fetch(url, fetchOptions);
|
|
13704
|
+
}
|
|
13705
|
+
return withRateLimitRetry(() => fetch(url, fetchOptions));
|
|
13706
|
+
}
|
|
13708
13707
|
var RateLimitError;
|
|
13709
13708
|
var init_http = __esm({
|
|
13710
13709
|
"src/core/http.ts"() {
|
|
13711
13710
|
"use strict";
|
|
13712
13711
|
init_constants();
|
|
13713
13712
|
init_config2();
|
|
13713
|
+
init_config();
|
|
13714
13714
|
RateLimitError = class extends Error {
|
|
13715
13715
|
constructor(info, retriesExhausted) {
|
|
13716
|
-
const
|
|
13716
|
+
const seconds = info.retryAfter ?? (info.reset > 0 ? Math.max(0, Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)) : null);
|
|
13717
|
+
const message = seconds === null ? "Rate limit exceeded. The server did not say when to retry." : `Rate limit exceeded. Try again in ${seconds} seconds.`;
|
|
13717
13718
|
super(message);
|
|
13718
13719
|
this.name = "RateLimitError";
|
|
13719
13720
|
this.rateLimitInfo = info;
|
|
@@ -13730,7 +13731,7 @@ import {
|
|
|
13730
13731
|
keccak256 as keccak2565,
|
|
13731
13732
|
stringToHex
|
|
13732
13733
|
} from "viem";
|
|
13733
|
-
async function
|
|
13734
|
+
async function fetchOnceWithTimeout(url, init) {
|
|
13734
13735
|
const controller = new AbortController();
|
|
13735
13736
|
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
13736
13737
|
try {
|
|
@@ -13751,6 +13752,9 @@ async function fetchWithTimeout(url, init) {
|
|
|
13751
13752
|
clearTimeout(timer);
|
|
13752
13753
|
}
|
|
13753
13754
|
}
|
|
13755
|
+
async function fetchWithTimeout(url, init) {
|
|
13756
|
+
return withRateLimitRetry(() => fetchOnceWithTimeout(url, init));
|
|
13757
|
+
}
|
|
13754
13758
|
function extractRevertHex(err) {
|
|
13755
13759
|
if (typeof err.data === "string" && err.data.startsWith("0x"))
|
|
13756
13760
|
return err.data;
|
|
@@ -14250,7 +14254,7 @@ async function estimateRelayFeeInToken(valueWei, fromAmountWei, fromAmountUSD, c
|
|
|
14250
14254
|
tokenUnitsPerDollar = Number(fromAmountWei) / fromUSD;
|
|
14251
14255
|
} else if (fromToken && fromDecimals !== void 0) {
|
|
14252
14256
|
try {
|
|
14253
|
-
const resp = await
|
|
14257
|
+
const resp = await rateLimitedFetch(
|
|
14254
14258
|
`${apiBase()}/v1/price/token?chainId=${cid}&address=${fromToken}`,
|
|
14255
14259
|
{ headers: jsonHeaders() }
|
|
14256
14260
|
);
|
|
@@ -14266,9 +14270,10 @@ async function estimateRelayFeeInToken(valueWei, fromAmountWei, fromAmountUSD, c
|
|
|
14266
14270
|
return 0n;
|
|
14267
14271
|
}
|
|
14268
14272
|
try {
|
|
14269
|
-
const resp = await
|
|
14270
|
-
|
|
14271
|
-
|
|
14273
|
+
const resp = await rateLimitedFetch(
|
|
14274
|
+
`${apiBase()}/v1/price/native?chainId=${cid}`,
|
|
14275
|
+
{ headers: jsonHeaders() }
|
|
14276
|
+
);
|
|
14272
14277
|
if (!resp.ok) throw new Error(`native price HTTP ${resp.status}`);
|
|
14273
14278
|
const json = await resp.json();
|
|
14274
14279
|
const ethPriceUSD = parseFloat(json.data?.priceUSD ?? "0");
|