@trustware/sdk-staging 1.1.10-staging.0 → 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.
Files changed (38) hide show
  1. package/README.md +54 -21
  2. package/dist/constants.cjs +1 -1
  3. package/dist/constants.mjs +1 -1
  4. package/dist/{core-BPLiD1UG.d.ts → core-B1WCJfDI.d.ts} +15 -2
  5. package/dist/{core-B7Ez-5-r.d.cts → core-CeNTuqPz.d.cts} +15 -2
  6. package/dist/core.cjs +365 -279
  7. package/dist/core.cjs.map +1 -1
  8. package/dist/core.d.cts +2 -2
  9. package/dist/core.d.ts +2 -2
  10. package/dist/core.mjs +363 -278
  11. package/dist/core.mjs.map +1 -1
  12. package/dist/index.cjs +375 -170
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +11 -5
  15. package/dist/index.d.ts +11 -5
  16. package/dist/index.mjs +373 -169
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/{manager-B6NNV-E_.d.ts → manager-Bw8b1wSD.d.ts} +136 -21
  19. package/dist/{manager-BwjyFjjz.d.cts → manager-DNGk1YkR.d.cts} +136 -21
  20. package/dist/{metadata-BiTMMvlY.d.ts → metadata-C__KMeuz.d.ts} +1 -1
  21. package/dist/{metadata-HCflXcsF.d.cts → metadata-Dk4R8_-T.d.cts} +1 -1
  22. package/dist/smart-account.cjs +49 -44
  23. package/dist/smart-account.cjs.map +1 -1
  24. package/dist/smart-account.d.cts +17 -12
  25. package/dist/smart-account.d.ts +17 -12
  26. package/dist/smart-account.mjs +49 -44
  27. package/dist/smart-account.mjs.map +1 -1
  28. package/dist/wallet.cjs +54 -39
  29. package/dist/wallet.cjs.map +1 -1
  30. package/dist/wallet.d.cts +3 -3
  31. package/dist/wallet.d.ts +3 -3
  32. package/dist/wallet.mjs +54 -39
  33. package/dist/wallet.mjs.map +1 -1
  34. package/dist/widget.cjs +369 -170
  35. package/dist/widget.cjs.map +1 -1
  36. package/dist/widget.mjs +369 -169
  37. package/dist/widget.mjs.map +1 -1
  38. package/package.json +73 -5
package/dist/wallet.cjs CHANGED
@@ -219,6 +219,20 @@ var init_eipWallets = __esm({
219
219
  "src/wallets/eipWallets.ts"() {
220
220
  "use strict";
221
221
  CHAIN_PARAMS = {
222
+ 1: {
223
+ chainIdHex: "0x1",
224
+ chainName: "Ethereum",
225
+ rpcUrls: ["https://eth.llamarpc.com"],
226
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
227
+ blockExplorerUrls: ["https://etherscan.io"]
228
+ },
229
+ 137: {
230
+ chainIdHex: "0x89",
231
+ chainName: "Polygon",
232
+ rpcUrls: ["https://polygon-rpc.com"],
233
+ nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
234
+ blockExplorerUrls: ["https://polygonscan.com"]
235
+ },
222
236
  8453: {
223
237
  chainIdHex: "0x2105",
224
238
  chainName: "Base",
@@ -250,7 +264,7 @@ var init_constants = __esm({
250
264
  "src/constants.ts"() {
251
265
  "use strict";
252
266
  SDK_NAME = "@trustware/sdk";
253
- SDK_VERSION = "1.1.10-staging.0";
267
+ SDK_VERSION = "1.1.11-staging.2";
254
268
  API_ROOT = "https://bv-staging-api.trustware.io";
255
269
  API_PREFIX = "/api";
256
270
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -273,16 +287,14 @@ var init_defaults = __esm({
273
287
  });
274
288
 
275
289
  // src/types/config.ts
276
- var DEFAULT_RETRY_CONFIG, DEFAULT_FEATURE_FLAGS;
290
+ var DEFAULT_RETRY_CONFIG, RATE_LIMIT_WAIT_BUDGET_MS, DEFAULT_FEATURE_FLAGS;
277
291
  var init_config = __esm({
278
292
  "src/types/config.ts"() {
279
293
  "use strict";
280
294
  DEFAULT_RETRY_CONFIG = {
281
- autoRetry: true,
282
- maxRetries: 3,
283
- baseDelayMs: 1e3,
284
295
  approachingThreshold: 5
285
296
  };
297
+ RATE_LIMIT_WAIT_BUDGET_MS = 1e4;
286
298
  DEFAULT_FEATURE_FLAGS = {
287
299
  tokensPagination: true,
288
300
  balanceStreaming: false,
@@ -3735,9 +3747,6 @@ function resolveConfig(input) {
3735
3747
  const theme = input.theme ?? "system";
3736
3748
  const messages = deepMerge(DEFAULT_MESSAGES, input.messages);
3737
3749
  const retry = {
3738
- autoRetry: input.retry?.autoRetry ?? DEFAULT_RETRY_CONFIG.autoRetry,
3739
- maxRetries: input.retry?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,
3740
- baseDelayMs: input.retry?.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,
3741
3750
  approachingThreshold: input.retry?.approachingThreshold ?? DEFAULT_RETRY_CONFIG.approachingThreshold,
3742
3751
  onRateLimitInfo: input.retry?.onRateLimitInfo,
3743
3752
  onRateLimited: input.retry?.onRateLimited,
@@ -3838,50 +3847,54 @@ function notifyRateLimitCallbacks(info, isRateLimited, retryCount) {
3838
3847
  retry.onRateLimitApproaching(info, retry.approachingThreshold);
3839
3848
  }
3840
3849
  }
3841
- function calculateBackoffDelay(baseDelayMs, retryCount, retryAfter) {
3842
- if (retryAfter && retryAfter > 0) {
3843
- return retryAfter * 1e3;
3850
+ function serverDirectedWaitMs(info) {
3851
+ if (!info) return null;
3852
+ if (typeof info.retryAfter === "number" && info.retryAfter > 0) {
3853
+ return info.retryAfter * 1e3;
3844
3854
  }
3845
- return baseDelayMs * Math.pow(2, retryCount);
3855
+ if (typeof info.reset === "number" && info.reset > 0) {
3856
+ const untilReset = info.reset * 1e3 - Date.now();
3857
+ if (untilReset > 0) return untilReset;
3858
+ }
3859
+ return null;
3846
3860
  }
3847
3861
  function sleep(ms) {
3848
3862
  return new Promise((resolve) => setTimeout(resolve, ms));
3849
3863
  }
3850
- async function rateLimitedFetch(url, options = {}) {
3851
- const { skipRateLimit, ...fetchOptions } = options;
3852
- const cfg = TrustwareConfigStore.get();
3853
- if (!cfg.retry.autoRetry || skipRateLimit) {
3854
- return fetch(url, fetchOptions);
3855
- }
3856
- const { maxRetries, baseDelayMs } = cfg.retry;
3864
+ async function withRateLimitRetry(attempt) {
3865
+ let waitedMs = 0;
3857
3866
  let retryCount = 0;
3858
3867
  while (true) {
3859
- const response = await fetch(url, fetchOptions);
3868
+ const response = await attempt();
3860
3869
  const rateLimitInfo = parseRateLimitHeaders(response);
3861
- if (response.status === 429) {
3870
+ if (response.status !== 429) {
3862
3871
  if (rateLimitInfo) {
3863
- notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
3864
- }
3865
- if (retryCount >= maxRetries) {
3866
- throw new RateLimitError(
3867
- rateLimitInfo || { limit: 0, remaining: 0, reset: 0 },
3868
- true
3869
- );
3872
+ notifyRateLimitCallbacks(rateLimitInfo, false, 0);
3870
3873
  }
3871
- const delay = calculateBackoffDelay(
3872
- baseDelayMs,
3873
- retryCount,
3874
- rateLimitInfo?.retryAfter
3875
- );
3876
- await sleep(delay);
3877
- retryCount++;
3878
- continue;
3874
+ return response;
3879
3875
  }
3880
3876
  if (rateLimitInfo) {
3881
- notifyRateLimitCallbacks(rateLimitInfo, false, 0);
3877
+ notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
3878
+ }
3879
+ const waitMs = serverDirectedWaitMs(rateLimitInfo);
3880
+ const info = rateLimitInfo || { limit: 0, remaining: 0, reset: 0 };
3881
+ if (waitMs === null) {
3882
+ throw new RateLimitError(info, true);
3882
3883
  }
3883
- return response;
3884
+ if (waitedMs + waitMs > RATE_LIMIT_WAIT_BUDGET_MS) {
3885
+ throw new RateLimitError(info, false);
3886
+ }
3887
+ await sleep(waitMs);
3888
+ waitedMs += waitMs;
3889
+ retryCount++;
3890
+ }
3891
+ }
3892
+ async function rateLimitedFetch(url, options = {}) {
3893
+ const { skipRateLimit, ...fetchOptions } = options;
3894
+ if (skipRateLimit) {
3895
+ return fetch(url, fetchOptions);
3884
3896
  }
3897
+ return withRateLimitRetry(() => fetch(url, fetchOptions));
3885
3898
  }
3886
3899
  var RateLimitError;
3887
3900
  var init_http = __esm({
@@ -3889,9 +3902,11 @@ var init_http = __esm({
3889
3902
  "use strict";
3890
3903
  init_constants();
3891
3904
  init_config2();
3905
+ init_config();
3892
3906
  RateLimitError = class extends Error {
3893
3907
  constructor(info, retriesExhausted) {
3894
- const message = retriesExhausted ? `Rate limit exceeded after max retries. Try again in ${info.retryAfter ?? Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)} seconds.` : `Rate limit exceeded. Try again in ${info.retryAfter} seconds.`;
3908
+ const seconds = info.retryAfter ?? (info.reset > 0 ? Math.max(0, Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)) : null);
3909
+ const message = seconds === null ? "Rate limit exceeded. The server did not say when to retry." : `Rate limit exceeded. Try again in ${seconds} seconds.`;
3895
3910
  super(message);
3896
3911
  this.name = "RateLimitError";
3897
3912
  this.rateLimitInfo = info;