@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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { S as SolanaProviderLike, W as WalletMeta, D as DetectedWallet, a as WalletId, b as SolanaWalletInterface } from './manager-DT8enQbE.cjs';
2
- export { c as WagmiBridge, d as WagmiConnector, e as WalletSnapshot, u as useWalletConnectConnect, f as useWalletExternalDisconnect, g as useWalletInfo, h as useWireDetectionIntoManager, w as walletManager } from './manager-DT8enQbE.cjs';
3
- export { P as POPULAR_ORDER, W as WALLETS, a as autoDetectWallet, b as buildDetectedWalletFromProvider, c as connectDetectedWallet, d as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, e as useIsMobile, f as useWagmi, g as useWalletDetection } from './metadata-DyxUcKHk.cjs';
1
+ import { S as SolanaProviderLike, W as WalletMeta, D as DetectedWallet, a as WalletId, b as SolanaWalletInterface } from './manager-DNGk1YkR.cjs';
2
+ export { c as WagmiBridge, d as WagmiConnector, e as WalletSnapshot, u as useWalletConnectConnect, f as useWalletExternalDisconnect, g as useWalletInfo, h as useWireDetectionIntoManager, w as walletManager } from './manager-DNGk1YkR.cjs';
3
+ export { P as POPULAR_ORDER, W as WALLETS, a as autoDetectWallet, b as buildDetectedWalletFromProvider, c as connectDetectedWallet, d as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, e as useIsMobile, f as useWagmi, g as useWalletDetection } from './metadata-Dk4R8_-T.cjs';
4
4
  import './blockchain-BxAFzp0s.cjs';
5
5
 
6
6
  type SolanaEventHandlers = {
package/dist/wallet.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { S as SolanaProviderLike, W as WalletMeta, D as DetectedWallet, a as WalletId, b as SolanaWalletInterface } from './manager-BY3NHAks.js';
2
- export { c as WagmiBridge, d as WagmiConnector, e as WalletSnapshot, u as useWalletConnectConnect, f as useWalletExternalDisconnect, g as useWalletInfo, h as useWireDetectionIntoManager, w as walletManager } from './manager-BY3NHAks.js';
3
- export { P as POPULAR_ORDER, W as WALLETS, a as autoDetectWallet, b as buildDetectedWalletFromProvider, c as connectDetectedWallet, d as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, e as useIsMobile, f as useWagmi, g as useWalletDetection } from './metadata-BPvFYMlc.js';
1
+ import { S as SolanaProviderLike, W as WalletMeta, D as DetectedWallet, a as WalletId, b as SolanaWalletInterface } from './manager-Bw8b1wSD.js';
2
+ export { c as WagmiBridge, d as WagmiConnector, e as WalletSnapshot, u as useWalletConnectConnect, f as useWalletExternalDisconnect, g as useWalletInfo, h as useWireDetectionIntoManager, w as walletManager } from './manager-Bw8b1wSD.js';
3
+ export { P as POPULAR_ORDER, W as WALLETS, a as autoDetectWallet, b as buildDetectedWalletFromProvider, c as connectDetectedWallet, d as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, e as useIsMobile, f as useWagmi, g as useWalletDetection } from './metadata-C__KMeuz.js';
4
4
  import './blockchain-BxAFzp0s.js';
5
5
 
6
6
  type SolanaEventHandlers = {
package/dist/wallet.mjs CHANGED
@@ -238,7 +238,7 @@ var init_constants = __esm({
238
238
  "src/constants.ts"() {
239
239
  "use strict";
240
240
  SDK_NAME = "@trustware/sdk";
241
- SDK_VERSION = "1.1.11-staging.1";
241
+ SDK_VERSION = "1.1.11-staging.2";
242
242
  API_ROOT = "https://bv-staging-api.trustware.io";
243
243
  API_PREFIX = "/api";
244
244
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -261,16 +261,14 @@ var init_defaults = __esm({
261
261
  });
262
262
 
263
263
  // src/types/config.ts
264
- var DEFAULT_RETRY_CONFIG, DEFAULT_FEATURE_FLAGS;
264
+ var DEFAULT_RETRY_CONFIG, RATE_LIMIT_WAIT_BUDGET_MS, DEFAULT_FEATURE_FLAGS;
265
265
  var init_config = __esm({
266
266
  "src/types/config.ts"() {
267
267
  "use strict";
268
268
  DEFAULT_RETRY_CONFIG = {
269
- autoRetry: true,
270
- maxRetries: 3,
271
- baseDelayMs: 1e3,
272
269
  approachingThreshold: 5
273
270
  };
271
+ RATE_LIMIT_WAIT_BUDGET_MS = 1e4;
274
272
  DEFAULT_FEATURE_FLAGS = {
275
273
  tokensPagination: true,
276
274
  balanceStreaming: false,
@@ -3723,9 +3721,6 @@ function resolveConfig(input) {
3723
3721
  const theme = input.theme ?? "system";
3724
3722
  const messages = deepMerge(DEFAULT_MESSAGES, input.messages);
3725
3723
  const retry = {
3726
- autoRetry: input.retry?.autoRetry ?? DEFAULT_RETRY_CONFIG.autoRetry,
3727
- maxRetries: input.retry?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,
3728
- baseDelayMs: input.retry?.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,
3729
3724
  approachingThreshold: input.retry?.approachingThreshold ?? DEFAULT_RETRY_CONFIG.approachingThreshold,
3730
3725
  onRateLimitInfo: input.retry?.onRateLimitInfo,
3731
3726
  onRateLimited: input.retry?.onRateLimited,
@@ -3826,50 +3821,54 @@ function notifyRateLimitCallbacks(info, isRateLimited, retryCount) {
3826
3821
  retry.onRateLimitApproaching(info, retry.approachingThreshold);
3827
3822
  }
3828
3823
  }
3829
- function calculateBackoffDelay(baseDelayMs, retryCount, retryAfter) {
3830
- if (retryAfter && retryAfter > 0) {
3831
- return retryAfter * 1e3;
3824
+ function serverDirectedWaitMs(info) {
3825
+ if (!info) return null;
3826
+ if (typeof info.retryAfter === "number" && info.retryAfter > 0) {
3827
+ return info.retryAfter * 1e3;
3832
3828
  }
3833
- return baseDelayMs * Math.pow(2, retryCount);
3829
+ if (typeof info.reset === "number" && info.reset > 0) {
3830
+ const untilReset = info.reset * 1e3 - Date.now();
3831
+ if (untilReset > 0) return untilReset;
3832
+ }
3833
+ return null;
3834
3834
  }
3835
3835
  function sleep(ms) {
3836
3836
  return new Promise((resolve) => setTimeout(resolve, ms));
3837
3837
  }
3838
- async function rateLimitedFetch(url, options = {}) {
3839
- const { skipRateLimit, ...fetchOptions } = options;
3840
- const cfg = TrustwareConfigStore.get();
3841
- if (!cfg.retry.autoRetry || skipRateLimit) {
3842
- return fetch(url, fetchOptions);
3843
- }
3844
- const { maxRetries, baseDelayMs } = cfg.retry;
3838
+ async function withRateLimitRetry(attempt) {
3839
+ let waitedMs = 0;
3845
3840
  let retryCount = 0;
3846
3841
  while (true) {
3847
- const response = await fetch(url, fetchOptions);
3842
+ const response = await attempt();
3848
3843
  const rateLimitInfo = parseRateLimitHeaders(response);
3849
- if (response.status === 429) {
3844
+ if (response.status !== 429) {
3850
3845
  if (rateLimitInfo) {
3851
- notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
3852
- }
3853
- if (retryCount >= maxRetries) {
3854
- throw new RateLimitError(
3855
- rateLimitInfo || { limit: 0, remaining: 0, reset: 0 },
3856
- true
3857
- );
3846
+ notifyRateLimitCallbacks(rateLimitInfo, false, 0);
3858
3847
  }
3859
- const delay = calculateBackoffDelay(
3860
- baseDelayMs,
3861
- retryCount,
3862
- rateLimitInfo?.retryAfter
3863
- );
3864
- await sleep(delay);
3865
- retryCount++;
3866
- continue;
3848
+ return response;
3867
3849
  }
3868
3850
  if (rateLimitInfo) {
3869
- notifyRateLimitCallbacks(rateLimitInfo, false, 0);
3851
+ notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
3870
3852
  }
3871
- return response;
3853
+ const waitMs = serverDirectedWaitMs(rateLimitInfo);
3854
+ const info = rateLimitInfo || { limit: 0, remaining: 0, reset: 0 };
3855
+ if (waitMs === null) {
3856
+ throw new RateLimitError(info, true);
3857
+ }
3858
+ if (waitedMs + waitMs > RATE_LIMIT_WAIT_BUDGET_MS) {
3859
+ throw new RateLimitError(info, false);
3860
+ }
3861
+ await sleep(waitMs);
3862
+ waitedMs += waitMs;
3863
+ retryCount++;
3864
+ }
3865
+ }
3866
+ async function rateLimitedFetch(url, options = {}) {
3867
+ const { skipRateLimit, ...fetchOptions } = options;
3868
+ if (skipRateLimit) {
3869
+ return fetch(url, fetchOptions);
3872
3870
  }
3871
+ return withRateLimitRetry(() => fetch(url, fetchOptions));
3873
3872
  }
3874
3873
  var RateLimitError;
3875
3874
  var init_http = __esm({
@@ -3877,9 +3876,11 @@ var init_http = __esm({
3877
3876
  "use strict";
3878
3877
  init_constants();
3879
3878
  init_config2();
3879
+ init_config();
3880
3880
  RateLimitError = class extends Error {
3881
3881
  constructor(info, retriesExhausted) {
3882
- 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.`;
3882
+ const seconds = info.retryAfter ?? (info.reset > 0 ? Math.max(0, Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)) : null);
3883
+ const message = seconds === null ? "Rate limit exceeded. The server did not say when to retry." : `Rate limit exceeded. Try again in ${seconds} seconds.`;
3883
3884
  super(message);
3884
3885
  this.name = "RateLimitError";
3885
3886
  this.rateLimitInfo = info;