@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.
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-BgYLe9Q7.d.ts → core-B1WCJfDI.d.ts} +1 -1
  5. package/dist/{core-fLSt4qD2.d.cts → core-CeNTuqPz.d.cts} +1 -1
  6. package/dist/core.cjs +85 -43
  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 +83 -42
  11. package/dist/core.mjs.map +1 -1
  12. package/dist/index.cjs +107 -55
  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 +105 -55
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/{manager-BY3NHAks.d.ts → manager-Bw8b1wSD.d.ts} +89 -22
  19. package/dist/{manager-DT8enQbE.d.cts → manager-DNGk1YkR.d.cts} +89 -22
  20. package/dist/{metadata-BPvFYMlc.d.ts → metadata-C__KMeuz.d.ts} +1 -1
  21. package/dist/{metadata-DyxUcKHk.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 +5 -0
  25. package/dist/smart-account.d.ts +5 -0
  26. package/dist/smart-account.mjs +49 -44
  27. package/dist/smart-account.mjs.map +1 -1
  28. package/dist/wallet.cjs +40 -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 +40 -39
  33. package/dist/wallet.mjs.map +1 -1
  34. package/dist/widget.cjs +101 -55
  35. package/dist/widget.cjs.map +1 -1
  36. package/dist/widget.mjs +101 -55
  37. package/dist/widget.mjs.map +1 -1
  38. package/package.json +73 -5
package/dist/wallet.cjs CHANGED
@@ -264,7 +264,7 @@ var init_constants = __esm({
264
264
  "src/constants.ts"() {
265
265
  "use strict";
266
266
  SDK_NAME = "@trustware/sdk";
267
- SDK_VERSION = "1.1.11-staging.1";
267
+ SDK_VERSION = "1.1.11-staging.2";
268
268
  API_ROOT = "https://bv-staging-api.trustware.io";
269
269
  API_PREFIX = "/api";
270
270
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -287,16 +287,14 @@ var init_defaults = __esm({
287
287
  });
288
288
 
289
289
  // src/types/config.ts
290
- var DEFAULT_RETRY_CONFIG, DEFAULT_FEATURE_FLAGS;
290
+ var DEFAULT_RETRY_CONFIG, RATE_LIMIT_WAIT_BUDGET_MS, DEFAULT_FEATURE_FLAGS;
291
291
  var init_config = __esm({
292
292
  "src/types/config.ts"() {
293
293
  "use strict";
294
294
  DEFAULT_RETRY_CONFIG = {
295
- autoRetry: true,
296
- maxRetries: 3,
297
- baseDelayMs: 1e3,
298
295
  approachingThreshold: 5
299
296
  };
297
+ RATE_LIMIT_WAIT_BUDGET_MS = 1e4;
300
298
  DEFAULT_FEATURE_FLAGS = {
301
299
  tokensPagination: true,
302
300
  balanceStreaming: false,
@@ -3749,9 +3747,6 @@ function resolveConfig(input) {
3749
3747
  const theme = input.theme ?? "system";
3750
3748
  const messages = deepMerge(DEFAULT_MESSAGES, input.messages);
3751
3749
  const retry = {
3752
- autoRetry: input.retry?.autoRetry ?? DEFAULT_RETRY_CONFIG.autoRetry,
3753
- maxRetries: input.retry?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,
3754
- baseDelayMs: input.retry?.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,
3755
3750
  approachingThreshold: input.retry?.approachingThreshold ?? DEFAULT_RETRY_CONFIG.approachingThreshold,
3756
3751
  onRateLimitInfo: input.retry?.onRateLimitInfo,
3757
3752
  onRateLimited: input.retry?.onRateLimited,
@@ -3852,50 +3847,54 @@ function notifyRateLimitCallbacks(info, isRateLimited, retryCount) {
3852
3847
  retry.onRateLimitApproaching(info, retry.approachingThreshold);
3853
3848
  }
3854
3849
  }
3855
- function calculateBackoffDelay(baseDelayMs, retryCount, retryAfter) {
3856
- if (retryAfter && retryAfter > 0) {
3857
- 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;
3858
3854
  }
3859
- 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;
3860
3860
  }
3861
3861
  function sleep(ms) {
3862
3862
  return new Promise((resolve) => setTimeout(resolve, ms));
3863
3863
  }
3864
- async function rateLimitedFetch(url, options = {}) {
3865
- const { skipRateLimit, ...fetchOptions } = options;
3866
- const cfg = TrustwareConfigStore.get();
3867
- if (!cfg.retry.autoRetry || skipRateLimit) {
3868
- return fetch(url, fetchOptions);
3869
- }
3870
- const { maxRetries, baseDelayMs } = cfg.retry;
3864
+ async function withRateLimitRetry(attempt) {
3865
+ let waitedMs = 0;
3871
3866
  let retryCount = 0;
3872
3867
  while (true) {
3873
- const response = await fetch(url, fetchOptions);
3868
+ const response = await attempt();
3874
3869
  const rateLimitInfo = parseRateLimitHeaders(response);
3875
- if (response.status === 429) {
3870
+ if (response.status !== 429) {
3876
3871
  if (rateLimitInfo) {
3877
- notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
3878
- }
3879
- if (retryCount >= maxRetries) {
3880
- throw new RateLimitError(
3881
- rateLimitInfo || { limit: 0, remaining: 0, reset: 0 },
3882
- true
3883
- );
3872
+ notifyRateLimitCallbacks(rateLimitInfo, false, 0);
3884
3873
  }
3885
- const delay = calculateBackoffDelay(
3886
- baseDelayMs,
3887
- retryCount,
3888
- rateLimitInfo?.retryAfter
3889
- );
3890
- await sleep(delay);
3891
- retryCount++;
3892
- continue;
3874
+ return response;
3893
3875
  }
3894
3876
  if (rateLimitInfo) {
3895
- notifyRateLimitCallbacks(rateLimitInfo, false, 0);
3877
+ notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
3896
3878
  }
3897
- return response;
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);
3883
+ }
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);
3898
3896
  }
3897
+ return withRateLimitRetry(() => fetch(url, fetchOptions));
3899
3898
  }
3900
3899
  var RateLimitError;
3901
3900
  var init_http = __esm({
@@ -3903,9 +3902,11 @@ var init_http = __esm({
3903
3902
  "use strict";
3904
3903
  init_constants();
3905
3904
  init_config2();
3905
+ init_config();
3906
3906
  RateLimitError = class extends Error {
3907
3907
  constructor(info, retriesExhausted) {
3908
- 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.`;
3909
3910
  super(message);
3910
3911
  this.name = "RateLimitError";
3911
3912
  this.rateLimitInfo = info;