@trustware/sdk-staging 1.1.11-staging.1 → 1.1.12-staging.1

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 (44) hide show
  1. package/README.md +54 -21
  2. package/dist/{blockchain-BxAFzp0s.d.cts → blockchain-DmCPxnxr.d.cts} +25 -1
  3. package/dist/{blockchain-BxAFzp0s.d.ts → blockchain-DmCPxnxr.d.ts} +25 -1
  4. package/dist/constants.cjs +1 -1
  5. package/dist/constants.mjs +1 -1
  6. package/dist/{core-BgYLe9Q7.d.ts → core-B4YDGtJT.d.ts} +3 -3
  7. package/dist/{core-fLSt4qD2.d.cts → core-Ck7dinYj.d.cts} +3 -3
  8. package/dist/core.cjs +141 -52
  9. package/dist/core.cjs.map +1 -1
  10. package/dist/core.d.cts +4 -4
  11. package/dist/core.d.ts +4 -4
  12. package/dist/core.mjs +139 -51
  13. package/dist/core.mjs.map +1 -1
  14. package/dist/index.cjs +166 -75
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +14 -8
  17. package/dist/index.d.ts +14 -8
  18. package/dist/index.mjs +164 -75
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/{manager-DT8enQbE.d.cts → manager-BZ8gyHGT.d.cts} +90 -23
  21. package/dist/{manager-BY3NHAks.d.ts → manager-D8nQsod2.d.ts} +90 -23
  22. package/dist/{metadata-DyxUcKHk.d.cts → metadata-B23D0oO9.d.cts} +1 -1
  23. package/dist/{metadata-BPvFYMlc.d.ts → metadata-BOjEF7oo.d.ts} +1 -1
  24. package/dist/smart-account.cjs +62 -47
  25. package/dist/smart-account.cjs.map +1 -1
  26. package/dist/smart-account.d.cts +6 -0
  27. package/dist/smart-account.d.ts +6 -0
  28. package/dist/smart-account.mjs +62 -47
  29. package/dist/smart-account.mjs.map +1 -1
  30. package/dist/{types-BJY9r-mz.d.ts → types-CMmx0S4U.d.ts} +1 -1
  31. package/dist/{types-DX3HtFcn.d.cts → types-DEUb5IZA.d.cts} +1 -1
  32. package/dist/wallet.cjs +51 -40
  33. package/dist/wallet.cjs.map +1 -1
  34. package/dist/wallet.d.cts +4 -4
  35. package/dist/wallet.d.ts +4 -4
  36. package/dist/wallet.mjs +51 -40
  37. package/dist/wallet.mjs.map +1 -1
  38. package/dist/widget.cjs +160 -75
  39. package/dist/widget.cjs.map +1 -1
  40. package/dist/widget.d.cts +2 -2
  41. package/dist/widget.d.ts +2 -2
  42. package/dist/widget.mjs +160 -75
  43. package/dist/widget.mjs.map +1 -1
  44. package/package.json +74 -5
package/dist/core.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { T as Trustware, a as TrustwareCore } from './core-fLSt4qD2.cjs';
2
- import './manager-DT8enQbE.cjs';
3
- import './blockchain-BxAFzp0s.cjs';
4
- import './types-DX3HtFcn.cjs';
1
+ export { T as Trustware, a as TrustwareCore } from './core-Ck7dinYj.cjs';
2
+ export { B as BuildRouteBody, m as BuildRouteResponse, a5 as assertValidPostHook } from './manager-BZ8gyHGT.cjs';
3
+ import './blockchain-DmCPxnxr.cjs';
4
+ import './types-DEUb5IZA.cjs';
package/dist/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { T as Trustware, a as TrustwareCore } from './core-BgYLe9Q7.js';
2
- import './manager-BY3NHAks.js';
3
- import './blockchain-BxAFzp0s.js';
4
- import './types-BJY9r-mz.js';
1
+ export { T as Trustware, a as TrustwareCore } from './core-B4YDGtJT.js';
2
+ export { B as BuildRouteBody, m as BuildRouteResponse, a5 as assertValidPostHook } from './manager-D8nQsod2.js';
3
+ import './blockchain-DmCPxnxr.js';
4
+ import './types-CMmx0S4U.js';
package/dist/core.mjs CHANGED
@@ -25,19 +25,27 @@ var init_defaults = __esm({
25
25
  });
26
26
 
27
27
  // src/types/config.ts
28
- var DEFAULT_RETRY_CONFIG, DEFAULT_FEATURE_FLAGS;
28
+ var DEFAULT_RETRY_CONFIG, RATE_LIMIT_WAIT_BUDGET_MS, DEFAULT_FEATURE_FLAGS;
29
29
  var init_config = __esm({
30
30
  "src/types/config.ts"() {
31
31
  "use strict";
32
32
  DEFAULT_RETRY_CONFIG = {
33
- autoRetry: true,
34
- maxRetries: 3,
35
- baseDelayMs: 1e3,
36
33
  approachingThreshold: 5
37
34
  };
35
+ RATE_LIMIT_WAIT_BUDGET_MS = 1e4;
38
36
  DEFAULT_FEATURE_FLAGS = {
39
37
  tokensPagination: true,
40
- balanceStreaming: false,
38
+ // On by default: an address scan covers every configured chain and takes
39
+ // seconds end to end, so streaming turns one long wait into a wallet that
40
+ // fills in as results land — first chunk in ~200ms against a ~2.3s buffered
41
+ // response, measured on a live backend.
42
+ //
43
+ // Safe to default because the path degrades on its own: a backend with
44
+ // BALANCE_STREAM_ENABLED off refuses the stream, and the SDK falls back to
45
+ // the buffered endpoint (emitting balance_stream_fallback), as does any
46
+ // runtime whose fetch has no readable body — React Native, most notably.
47
+ // The cost of defaulting ahead of a backend is one refused request per scan.
48
+ balanceStreaming: true,
41
49
  shouldAllowGA4: true,
42
50
  swapMode: false,
43
51
  swapDefaultDestToken: null,
@@ -53,7 +61,7 @@ var init_constants = __esm({
53
61
  "src/constants.ts"() {
54
62
  "use strict";
55
63
  SDK_NAME = "@trustware/sdk";
56
- SDK_VERSION = "1.1.11-staging.1";
64
+ SDK_VERSION = "1.1.12-staging.1";
57
65
  API_ROOT = "https://bv-staging-api.trustware.io";
58
66
  API_PREFIX = "/api";
59
67
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -96,7 +104,7 @@ async function assertOK(r) {
96
104
  throw new Error(`HTTP ${r.status}: ${msg}`);
97
105
  }
98
106
  async function validateSdkAccess() {
99
- const r = await fetch(`${apiBase()}/sdk/validate`, {
107
+ const r = await fetch(`${apiBase()}/v1/sdk/validate`, {
100
108
  method: "GET",
101
109
  headers: jsonHeaders()
102
110
  });
@@ -135,50 +143,54 @@ function notifyRateLimitCallbacks(info, isRateLimited, retryCount) {
135
143
  retry.onRateLimitApproaching(info, retry.approachingThreshold);
136
144
  }
137
145
  }
138
- function calculateBackoffDelay(baseDelayMs, retryCount, retryAfter) {
139
- if (retryAfter && retryAfter > 0) {
140
- return retryAfter * 1e3;
146
+ function serverDirectedWaitMs(info) {
147
+ if (!info) return null;
148
+ if (typeof info.retryAfter === "number" && info.retryAfter > 0) {
149
+ return info.retryAfter * 1e3;
141
150
  }
142
- return baseDelayMs * Math.pow(2, retryCount);
151
+ if (typeof info.reset === "number" && info.reset > 0) {
152
+ const untilReset = info.reset * 1e3 - Date.now();
153
+ if (untilReset > 0) return untilReset;
154
+ }
155
+ return null;
143
156
  }
144
157
  function sleep(ms) {
145
158
  return new Promise((resolve) => setTimeout(resolve, ms));
146
159
  }
147
- async function rateLimitedFetch(url, options = {}) {
148
- const { skipRateLimit, ...fetchOptions } = options;
149
- const cfg = TrustwareConfigStore.get();
150
- if (!cfg.retry.autoRetry || skipRateLimit) {
151
- return fetch(url, fetchOptions);
152
- }
153
- const { maxRetries, baseDelayMs } = cfg.retry;
160
+ async function withRateLimitRetry(attempt) {
161
+ let waitedMs = 0;
154
162
  let retryCount = 0;
155
163
  while (true) {
156
- const response = await fetch(url, fetchOptions);
164
+ const response = await attempt();
157
165
  const rateLimitInfo = parseRateLimitHeaders(response);
158
- if (response.status === 429) {
166
+ if (response.status !== 429) {
159
167
  if (rateLimitInfo) {
160
- notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
161
- }
162
- if (retryCount >= maxRetries) {
163
- throw new RateLimitError(
164
- rateLimitInfo || { limit: 0, remaining: 0, reset: 0 },
165
- true
166
- );
168
+ notifyRateLimitCallbacks(rateLimitInfo, false, 0);
167
169
  }
168
- const delay = calculateBackoffDelay(
169
- baseDelayMs,
170
- retryCount,
171
- rateLimitInfo?.retryAfter
172
- );
173
- await sleep(delay);
174
- retryCount++;
175
- continue;
170
+ return response;
176
171
  }
177
172
  if (rateLimitInfo) {
178
- notifyRateLimitCallbacks(rateLimitInfo, false, 0);
173
+ notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
174
+ }
175
+ const waitMs = serverDirectedWaitMs(rateLimitInfo);
176
+ const info = rateLimitInfo || { limit: 0, remaining: 0, reset: 0 };
177
+ if (waitMs === null) {
178
+ throw new RateLimitError(info, true);
179
179
  }
180
- return response;
180
+ if (waitedMs + waitMs > RATE_LIMIT_WAIT_BUDGET_MS) {
181
+ throw new RateLimitError(info, false);
182
+ }
183
+ await sleep(waitMs);
184
+ waitedMs += waitMs;
185
+ retryCount++;
186
+ }
187
+ }
188
+ async function rateLimitedFetch(url, options = {}) {
189
+ const { skipRateLimit, ...fetchOptions } = options;
190
+ if (skipRateLimit) {
191
+ return fetch(url, fetchOptions);
181
192
  }
193
+ return withRateLimitRetry(() => fetch(url, fetchOptions));
182
194
  }
183
195
  var RateLimitError;
184
196
  var init_http = __esm({
@@ -186,9 +198,11 @@ var init_http = __esm({
186
198
  "use strict";
187
199
  init_constants();
188
200
  init_config2();
201
+ init_config();
189
202
  RateLimitError = class extends Error {
190
203
  constructor(info, retriesExhausted) {
191
- 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.`;
204
+ const seconds = info.retryAfter ?? (info.reset > 0 ? Math.max(0, Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)) : null);
205
+ const message = seconds === null ? "Rate limit exceeded. The server did not say when to retry." : `Rate limit exceeded. Try again in ${seconds} seconds.`;
192
206
  super(message);
193
207
  this.name = "RateLimitError";
194
208
  this.rateLimitInfo = info;
@@ -1773,6 +1787,16 @@ function mergeBalanceWrappers(current, incoming) {
1773
1787
  }
1774
1788
  return Array.from(merged.values());
1775
1789
  }
1790
+ function toSummary(frame, address) {
1791
+ const total = toNumberOrUndefined(frame.total) ?? 0;
1792
+ return {
1793
+ address: toStringOrUndefined(frame.address) ?? address,
1794
+ partial: Boolean(frame.partial),
1795
+ completed: toNumberOrUndefined(frame.completed) ?? 0,
1796
+ total,
1797
+ elapsedMs: toNumberOrUndefined(frame.elapsed)
1798
+ };
1799
+ }
1776
1800
  async function parseStreamingBalances(response, address, options = {}) {
1777
1801
  if (!response.body) {
1778
1802
  throw new Error("balances stream: empty response body");
@@ -1793,7 +1817,12 @@ async function parseStreamingBalances(response, address, options = {}) {
1793
1817
  if (!trimmed) continue;
1794
1818
  try {
1795
1819
  const parsed = JSON.parse(trimmed);
1796
- if (!parsed.chain_id) continue;
1820
+ if (!parsed.chain_id) {
1821
+ if (parsed.type === "summary") {
1822
+ options.onSummary?.(toSummary(parsed, address));
1823
+ }
1824
+ continue;
1825
+ }
1797
1826
  const chunk = normalizeStreamChunk(parsed);
1798
1827
  emitBalanceStreamChunk(address, chunk.length);
1799
1828
  yield chunk;
@@ -1812,6 +1841,8 @@ async function parseStreamingBalances(response, address, options = {}) {
1812
1841
  const chunk = normalizeStreamChunk(parsed);
1813
1842
  emitBalanceStreamChunk(address, chunk.length);
1814
1843
  yield chunk;
1844
+ } else if (parsed.type === "summary") {
1845
+ options.onSummary?.(toSummary(parsed, address));
1815
1846
  }
1816
1847
  } catch (error) {
1817
1848
  if (options.strict) {
@@ -1845,7 +1876,7 @@ async function getBalances(chainRef, address, opts) {
1845
1876
  if (cached) return cached;
1846
1877
  }
1847
1878
  const url = `${apiBase()}/v1/data/wallets/${encodeURIComponent(chainKey)}/${trimmedAddress}/balances`;
1848
- const response = await fetch(url, {
1879
+ const response = await rateLimitedFetch(url, {
1849
1880
  method: "GET",
1850
1881
  credentials: "omit",
1851
1882
  headers: jsonHeaders()
@@ -1866,7 +1897,7 @@ async function getBalancesByAddress(address, opts) {
1866
1897
  }
1867
1898
  return merged;
1868
1899
  }
1869
- const url = `${apiBase()}/data/balances/${address}`;
1900
+ const url = `${apiBase()}/v1/data/balances/${address}`;
1870
1901
  const r = await rateLimitedFetch(url, {
1871
1902
  method: "GET",
1872
1903
  credentials: "omit",
@@ -1874,14 +1905,27 @@ async function getBalancesByAddress(address, opts) {
1874
1905
  });
1875
1906
  if (!r.ok) throw new Error(`balances: HTTP ${r.status}`);
1876
1907
  const j = await r.json();
1877
- return Array.isArray(j) ? j : j.results ?? [];
1908
+ const results = Array.isArray(j) ? j : j.results ?? [];
1909
+ if (opts?.onSummary) {
1910
+ const completed = results.length;
1911
+ opts.onSummary({
1912
+ address,
1913
+ partial: Array.isArray(j) ? false : Boolean(j.partial),
1914
+ completed,
1915
+ total: completed
1916
+ });
1917
+ }
1918
+ return results;
1919
+ }
1920
+ function bufferedOptions(opts) {
1921
+ return { ...opts, stream: false };
1878
1922
  }
1879
1923
  async function* getBalancesByAddressStream(address, opts = {}) {
1880
1924
  if (!TrustwareConfigStore.get().features.balanceStreaming) {
1881
- yield await getBalancesByAddress(address);
1925
+ yield await getBalancesByAddress(address, bufferedOptions(opts));
1882
1926
  return;
1883
1927
  }
1884
- const url = `${apiBase()}/data/balances/${address}?stream=1`;
1928
+ const url = `${apiBase()}/v1/data/balances/${address}?stream=1`;
1885
1929
  try {
1886
1930
  const response = await rateLimitedFetch(url, {
1887
1931
  method: "GET",
@@ -1897,7 +1941,14 @@ async function* getBalancesByAddressStream(address, opts = {}) {
1897
1941
  const contentType = response.headers.get("content-type") ?? "";
1898
1942
  if (contentType.includes("application/json")) {
1899
1943
  const payload = await response.json();
1900
- yield Array.isArray(payload) ? payload : payload.results ?? [];
1944
+ const results = Array.isArray(payload) ? payload : payload.results ?? [];
1945
+ opts.onSummary?.({
1946
+ address,
1947
+ partial: Array.isArray(payload) ? false : Boolean(payload.partial),
1948
+ completed: results.length,
1949
+ total: results.length
1950
+ });
1951
+ yield results;
1901
1952
  return;
1902
1953
  }
1903
1954
  const stream = await parseStreamingBalances(response, address, opts);
@@ -1906,7 +1957,7 @@ async function* getBalancesByAddressStream(address, opts = {}) {
1906
1957
  }
1907
1958
  } catch (error) {
1908
1959
  emitBalanceStreamFallback(address, error);
1909
- yield await getBalancesByAddress(address);
1960
+ yield await getBalancesByAddress(address, bufferedOptions(opts));
1910
1961
  }
1911
1962
  }
1912
1963
  async function ensureRegistry() {
@@ -4093,7 +4144,18 @@ async function getStatus(intentId) {
4093
4144
  );
4094
4145
  await assertOK(r);
4095
4146
  const j = await r.json();
4096
- return j.data;
4147
+ return normalizeStatusPayload(j.data);
4148
+ }
4149
+ function normalizeStatusPayload(raw) {
4150
+ if (!raw || typeof raw !== "object") return raw;
4151
+ const wire = raw;
4152
+ const out = { ...wire };
4153
+ for (const [snake, camel] of Object.entries(STATUS_WIRE_TO_CAMEL)) {
4154
+ if (out[camel] !== void 0) continue;
4155
+ if (!(snake in wire)) continue;
4156
+ out[camel] = wire[snake];
4157
+ }
4158
+ return out;
4097
4159
  }
4098
4160
  async function pollStatus(intentId, { intervalMs = 2e3, timeoutMs = 5 * 6e4 } = {}) {
4099
4161
  const t0 = Date.now();
@@ -4104,12 +4166,39 @@ async function pollStatus(intentId, { intervalMs = 2e3, timeoutMs = 5 * 6e4 } =
4104
4166
  await new Promise((r) => setTimeout(r, intervalMs));
4105
4167
  }
4106
4168
  }
4169
+ var STATUS_WIRE_TO_CAMEL;
4107
4170
  var init_routes = __esm({
4108
4171
  "src/core/routes.ts"() {
4109
4172
  "use strict";
4110
4173
  init_http();
4111
4174
  init_store();
4112
4175
  init_address();
4176
+ STATUS_WIRE_TO_CAMEL = {
4177
+ intent_id: "intentId",
4178
+ from_address: "fromAddress",
4179
+ to_address: "toAddress",
4180
+ from_chain_id: "fromChainId",
4181
+ to_chain_id: "toChainId",
4182
+ source_tx_hash: "sourceTxHash",
4183
+ dest_tx_hash: "destTxHash",
4184
+ request_id: "requestId",
4185
+ provider_request_id: "providerRequestId",
4186
+ transaction_request: "transactionRequest",
4187
+ status_raw: "statusRaw",
4188
+ route_path: "routePath",
4189
+ route_status: "routeStatus",
4190
+ to_amount_wei: "toAmountWei",
4191
+ from_chain_block: "fromChainBlock",
4192
+ to_chain_block: "toChainBlock",
4193
+ from_chain_tx_url: "fromChainTxUrl",
4194
+ to_chain_tx_url: "toChainTxUrl",
4195
+ gas_status: "gasStatus",
4196
+ is_gmp_transaction: "isGMPTransaction",
4197
+ axelar_transaction_url: "axelarTransactionUrl",
4198
+ create_date: "createdDate",
4199
+ update_date: "updatedDate",
4200
+ time_spent_ms: "timeSpentMs"
4201
+ };
4113
4202
  }
4114
4203
  });
4115
4204
 
@@ -6582,9 +6671,6 @@ function resolveConfig(input) {
6582
6671
  const theme = input.theme ?? "system";
6583
6672
  const messages = deepMerge(DEFAULT_MESSAGES, input.messages);
6584
6673
  const retry = {
6585
- autoRetry: input.retry?.autoRetry ?? DEFAULT_RETRY_CONFIG.autoRetry,
6586
- maxRetries: input.retry?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,
6587
- baseDelayMs: input.retry?.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,
6588
6674
  approachingThreshold: input.retry?.approachingThreshold ?? DEFAULT_RETRY_CONFIG.approachingThreshold,
6589
6675
  onRateLimitInfo: input.retry?.onRateLimitInfo,
6590
6676
  onRateLimited: input.retry?.onRateLimited,
@@ -6717,6 +6803,7 @@ var init_core = __esm({
6717
6803
  init_store();
6718
6804
  init_wallets();
6719
6805
  init_routes();
6806
+ init_routes();
6720
6807
  init_balances();
6721
6808
  init_tx();
6722
6809
  init_http();
@@ -6876,6 +6963,7 @@ var init_core2 = __esm({
6876
6963
  });
6877
6964
  init_core2();
6878
6965
  export {
6879
- Trustware
6966
+ Trustware,
6967
+ assertValidPostHook
6880
6968
  };
6881
6969
  //# sourceMappingURL=core.mjs.map