@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/core.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { T as Trustware, a as TrustwareCore } from './core-
|
|
2
|
-
|
|
1
|
+
export { T as Trustware, a as TrustwareCore } from './core-CeNTuqPz.cjs';
|
|
2
|
+
export { B as BuildRouteBody, m as BuildRouteResponse, a5 as assertValidPostHook } from './manager-DNGk1YkR.cjs';
|
|
3
3
|
import './blockchain-BxAFzp0s.cjs';
|
|
4
4
|
import './types-DX3HtFcn.cjs';
|
package/dist/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { T as Trustware, a as TrustwareCore } from './core-
|
|
2
|
-
|
|
1
|
+
export { T as Trustware, a as TrustwareCore } from './core-B1WCJfDI.js';
|
|
2
|
+
export { B as BuildRouteBody, m as BuildRouteResponse, a5 as assertValidPostHook } from './manager-Bw8b1wSD.js';
|
|
3
3
|
import './blockchain-BxAFzp0s.js';
|
|
4
4
|
import './types-BJY9r-mz.js';
|
package/dist/core.mjs
CHANGED
|
@@ -25,16 +25,14 @@ 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
38
|
balanceStreaming: false,
|
|
@@ -53,7 +51,7 @@ var init_constants = __esm({
|
|
|
53
51
|
"src/constants.ts"() {
|
|
54
52
|
"use strict";
|
|
55
53
|
SDK_NAME = "@trustware/sdk";
|
|
56
|
-
SDK_VERSION = "1.1.11-staging.
|
|
54
|
+
SDK_VERSION = "1.1.11-staging.2";
|
|
57
55
|
API_ROOT = "https://bv-staging-api.trustware.io";
|
|
58
56
|
API_PREFIX = "/api";
|
|
59
57
|
WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
|
|
@@ -135,60 +133,66 @@ function notifyRateLimitCallbacks(info, isRateLimited, retryCount) {
|
|
|
135
133
|
retry.onRateLimitApproaching(info, retry.approachingThreshold);
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
|
-
function
|
|
139
|
-
if (
|
|
140
|
-
|
|
136
|
+
function serverDirectedWaitMs(info) {
|
|
137
|
+
if (!info) return null;
|
|
138
|
+
if (typeof info.retryAfter === "number" && info.retryAfter > 0) {
|
|
139
|
+
return info.retryAfter * 1e3;
|
|
141
140
|
}
|
|
142
|
-
|
|
141
|
+
if (typeof info.reset === "number" && info.reset > 0) {
|
|
142
|
+
const untilReset = info.reset * 1e3 - Date.now();
|
|
143
|
+
if (untilReset > 0) return untilReset;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
143
146
|
}
|
|
144
147
|
function sleep(ms) {
|
|
145
148
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
146
149
|
}
|
|
147
|
-
async function
|
|
148
|
-
|
|
149
|
-
const cfg = TrustwareConfigStore.get();
|
|
150
|
-
if (!cfg.retry.autoRetry || skipRateLimit) {
|
|
151
|
-
return fetch(url, fetchOptions);
|
|
152
|
-
}
|
|
153
|
-
const { maxRetries, baseDelayMs } = cfg.retry;
|
|
150
|
+
async function withRateLimitRetry(attempt) {
|
|
151
|
+
let waitedMs = 0;
|
|
154
152
|
let retryCount = 0;
|
|
155
153
|
while (true) {
|
|
156
|
-
const response = await
|
|
154
|
+
const response = await attempt();
|
|
157
155
|
const rateLimitInfo = parseRateLimitHeaders(response);
|
|
158
|
-
if (response.status
|
|
156
|
+
if (response.status !== 429) {
|
|
159
157
|
if (rateLimitInfo) {
|
|
160
|
-
notifyRateLimitCallbacks(rateLimitInfo,
|
|
158
|
+
notifyRateLimitCallbacks(rateLimitInfo, false, 0);
|
|
161
159
|
}
|
|
162
|
-
|
|
163
|
-
throw new RateLimitError(
|
|
164
|
-
rateLimitInfo || { limit: 0, remaining: 0, reset: 0 },
|
|
165
|
-
true
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
const delay = calculateBackoffDelay(
|
|
169
|
-
baseDelayMs,
|
|
170
|
-
retryCount,
|
|
171
|
-
rateLimitInfo?.retryAfter
|
|
172
|
-
);
|
|
173
|
-
await sleep(delay);
|
|
174
|
-
retryCount++;
|
|
175
|
-
continue;
|
|
160
|
+
return response;
|
|
176
161
|
}
|
|
177
162
|
if (rateLimitInfo) {
|
|
178
|
-
notifyRateLimitCallbacks(rateLimitInfo,
|
|
163
|
+
notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
|
|
164
|
+
}
|
|
165
|
+
const waitMs = serverDirectedWaitMs(rateLimitInfo);
|
|
166
|
+
const info = rateLimitInfo || { limit: 0, remaining: 0, reset: 0 };
|
|
167
|
+
if (waitMs === null) {
|
|
168
|
+
throw new RateLimitError(info, true);
|
|
169
|
+
}
|
|
170
|
+
if (waitedMs + waitMs > RATE_LIMIT_WAIT_BUDGET_MS) {
|
|
171
|
+
throw new RateLimitError(info, false);
|
|
179
172
|
}
|
|
180
|
-
|
|
173
|
+
await sleep(waitMs);
|
|
174
|
+
waitedMs += waitMs;
|
|
175
|
+
retryCount++;
|
|
181
176
|
}
|
|
182
177
|
}
|
|
178
|
+
async function rateLimitedFetch(url, options = {}) {
|
|
179
|
+
const { skipRateLimit, ...fetchOptions } = options;
|
|
180
|
+
if (skipRateLimit) {
|
|
181
|
+
return fetch(url, fetchOptions);
|
|
182
|
+
}
|
|
183
|
+
return withRateLimitRetry(() => fetch(url, fetchOptions));
|
|
184
|
+
}
|
|
183
185
|
var RateLimitError;
|
|
184
186
|
var init_http = __esm({
|
|
185
187
|
"src/core/http.ts"() {
|
|
186
188
|
"use strict";
|
|
187
189
|
init_constants();
|
|
188
190
|
init_config2();
|
|
191
|
+
init_config();
|
|
189
192
|
RateLimitError = class extends Error {
|
|
190
193
|
constructor(info, retriesExhausted) {
|
|
191
|
-
const
|
|
194
|
+
const seconds = info.retryAfter ?? (info.reset > 0 ? Math.max(0, Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)) : null);
|
|
195
|
+
const message = seconds === null ? "Rate limit exceeded. The server did not say when to retry." : `Rate limit exceeded. Try again in ${seconds} seconds.`;
|
|
192
196
|
super(message);
|
|
193
197
|
this.name = "RateLimitError";
|
|
194
198
|
this.rateLimitInfo = info;
|
|
@@ -1845,7 +1849,7 @@ async function getBalances(chainRef, address, opts) {
|
|
|
1845
1849
|
if (cached) return cached;
|
|
1846
1850
|
}
|
|
1847
1851
|
const url = `${apiBase()}/v1/data/wallets/${encodeURIComponent(chainKey)}/${trimmedAddress}/balances`;
|
|
1848
|
-
const response = await
|
|
1852
|
+
const response = await rateLimitedFetch(url, {
|
|
1849
1853
|
method: "GET",
|
|
1850
1854
|
credentials: "omit",
|
|
1851
1855
|
headers: jsonHeaders()
|
|
@@ -4093,7 +4097,18 @@ async function getStatus(intentId) {
|
|
|
4093
4097
|
);
|
|
4094
4098
|
await assertOK(r);
|
|
4095
4099
|
const j = await r.json();
|
|
4096
|
-
return j.data;
|
|
4100
|
+
return normalizeStatusPayload(j.data);
|
|
4101
|
+
}
|
|
4102
|
+
function normalizeStatusPayload(raw) {
|
|
4103
|
+
if (!raw || typeof raw !== "object") return raw;
|
|
4104
|
+
const wire = raw;
|
|
4105
|
+
const out = { ...wire };
|
|
4106
|
+
for (const [snake, camel] of Object.entries(STATUS_WIRE_TO_CAMEL)) {
|
|
4107
|
+
if (out[camel] !== void 0) continue;
|
|
4108
|
+
if (!(snake in wire)) continue;
|
|
4109
|
+
out[camel] = wire[snake];
|
|
4110
|
+
}
|
|
4111
|
+
return out;
|
|
4097
4112
|
}
|
|
4098
4113
|
async function pollStatus(intentId, { intervalMs = 2e3, timeoutMs = 5 * 6e4 } = {}) {
|
|
4099
4114
|
const t0 = Date.now();
|
|
@@ -4104,12 +4119,39 @@ async function pollStatus(intentId, { intervalMs = 2e3, timeoutMs = 5 * 6e4 } =
|
|
|
4104
4119
|
await new Promise((r) => setTimeout(r, intervalMs));
|
|
4105
4120
|
}
|
|
4106
4121
|
}
|
|
4122
|
+
var STATUS_WIRE_TO_CAMEL;
|
|
4107
4123
|
var init_routes = __esm({
|
|
4108
4124
|
"src/core/routes.ts"() {
|
|
4109
4125
|
"use strict";
|
|
4110
4126
|
init_http();
|
|
4111
4127
|
init_store();
|
|
4112
4128
|
init_address();
|
|
4129
|
+
STATUS_WIRE_TO_CAMEL = {
|
|
4130
|
+
intent_id: "intentId",
|
|
4131
|
+
from_address: "fromAddress",
|
|
4132
|
+
to_address: "toAddress",
|
|
4133
|
+
from_chain_id: "fromChainId",
|
|
4134
|
+
to_chain_id: "toChainId",
|
|
4135
|
+
source_tx_hash: "sourceTxHash",
|
|
4136
|
+
dest_tx_hash: "destTxHash",
|
|
4137
|
+
request_id: "requestId",
|
|
4138
|
+
provider_request_id: "providerRequestId",
|
|
4139
|
+
transaction_request: "transactionRequest",
|
|
4140
|
+
status_raw: "statusRaw",
|
|
4141
|
+
route_path: "routePath",
|
|
4142
|
+
route_status: "routeStatus",
|
|
4143
|
+
to_amount_wei: "toAmountWei",
|
|
4144
|
+
from_chain_block: "fromChainBlock",
|
|
4145
|
+
to_chain_block: "toChainBlock",
|
|
4146
|
+
from_chain_tx_url: "fromChainTxUrl",
|
|
4147
|
+
to_chain_tx_url: "toChainTxUrl",
|
|
4148
|
+
gas_status: "gasStatus",
|
|
4149
|
+
is_gmp_transaction: "isGMPTransaction",
|
|
4150
|
+
axelar_transaction_url: "axelarTransactionUrl",
|
|
4151
|
+
create_date: "createdDate",
|
|
4152
|
+
update_date: "updatedDate",
|
|
4153
|
+
time_spent_ms: "timeSpentMs"
|
|
4154
|
+
};
|
|
4113
4155
|
}
|
|
4114
4156
|
});
|
|
4115
4157
|
|
|
@@ -6582,9 +6624,6 @@ function resolveConfig(input) {
|
|
|
6582
6624
|
const theme = input.theme ?? "system";
|
|
6583
6625
|
const messages = deepMerge(DEFAULT_MESSAGES, input.messages);
|
|
6584
6626
|
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
6627
|
approachingThreshold: input.retry?.approachingThreshold ?? DEFAULT_RETRY_CONFIG.approachingThreshold,
|
|
6589
6628
|
onRateLimitInfo: input.retry?.onRateLimitInfo,
|
|
6590
6629
|
onRateLimited: input.retry?.onRateLimited,
|
|
@@ -6717,6 +6756,7 @@ var init_core = __esm({
|
|
|
6717
6756
|
init_store();
|
|
6718
6757
|
init_wallets();
|
|
6719
6758
|
init_routes();
|
|
6759
|
+
init_routes();
|
|
6720
6760
|
init_balances();
|
|
6721
6761
|
init_tx();
|
|
6722
6762
|
init_http();
|
|
@@ -6876,6 +6916,7 @@ var init_core2 = __esm({
|
|
|
6876
6916
|
});
|
|
6877
6917
|
init_core2();
|
|
6878
6918
|
export {
|
|
6879
|
-
Trustware
|
|
6919
|
+
Trustware,
|
|
6920
|
+
assertValidPostHook
|
|
6880
6921
|
};
|
|
6881
6922
|
//# sourceMappingURL=core.mjs.map
|