@rhea-finance/cross-chain-aggregation-dex 2.1.5 → 2.1.6
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 +3 -10
- package/dist/index.d.mts +2 -12
- package/dist/index.d.ts +2 -12
- package/dist/index.js +11 -96
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -96
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -441,8 +441,7 @@ Terminal statuses are `completed`, `failed`, `refunded`, and `expired`.
|
|
|
441
441
|
| `fetch` | `typeof globalThis.fetch` | No | Custom fetch implementation. The SDK binds its invocation context to avoid browser `Illegal invocation` errors. It is normally required on Node.js 16. |
|
|
442
442
|
| `headers` | `Record<string,string>` or function | No | Additional request headers. The function form may return a promise. |
|
|
443
443
|
| `timeoutMs` | `number` | No | Timeout for each HTTP request in milliseconds. Default: `15000`. |
|
|
444
|
-
| `
|
|
445
|
-
| `logger` | `SdkLogger` | No | Receives structured `api.request`, `api.response`, and `api.retry` entries. |
|
|
444
|
+
| `logger` | `SdkLogger` | No | Receives structured `api.request` and `api.response` entries. |
|
|
446
445
|
| `executors` | `readonly ChainExecutor[]` | Required for execution | Wallet executors. May be omitted when only calling `quote()` or `buildSwap()`. |
|
|
447
446
|
| `tokenListCacheTtlMs` | `number` | No | Successful token-list cache lifetime in milliseconds. Default: `600000` (10 minutes). Set to `0` to disable. |
|
|
448
447
|
| `reportMode` | `"auto" \| "manual" \| "disabled"` | No | Reporting policy. Default: `"auto"`. A reporting failure does not turn a submitted swap into a failed swap. |
|
|
@@ -778,18 +777,12 @@ await promise;
|
|
|
778
777
|
|
|
779
778
|
Cancellation only stops the SDK's current work. It cannot revert an approval, signature, or transaction that has already been submitted.
|
|
780
779
|
|
|
781
|
-
## 10.
|
|
780
|
+
## 10. Logging and credentials
|
|
782
781
|
|
|
783
782
|
```ts
|
|
784
783
|
const client = new SwapClient({
|
|
785
784
|
baseUrl: "https://api.rhea.finance",
|
|
786
785
|
getAccessToken: async () => authStore.getToken(),
|
|
787
|
-
retry: {
|
|
788
|
-
maxRetries: 2,
|
|
789
|
-
baseDelayMs: 250,
|
|
790
|
-
maxDelayMs: 2000,
|
|
791
|
-
jitter: true,
|
|
792
|
-
},
|
|
793
786
|
logger: {
|
|
794
787
|
log(entry) {
|
|
795
788
|
console.log("SDK API", entry);
|
|
@@ -798,7 +791,7 @@ const client = new SwapClient({
|
|
|
798
791
|
});
|
|
799
792
|
```
|
|
800
793
|
|
|
801
|
-
The SDK
|
|
794
|
+
The SDK does not automatically retry HTTP requests. Callers that need retries should handle them outside the SDK. Network failures preserve the underlying error name and message to help diagnose CORS failures, connection resets, timeouts, or fetch invocation problems. Errors may still expose a `retryable` flag as guidance for application-level handling.
|
|
802
795
|
|
|
803
796
|
## 11. Raw API, reporting, and history
|
|
804
797
|
|
package/dist/index.d.mts
CHANGED
|
@@ -23,10 +23,9 @@ declare function asSwapSdkError(error: unknown, stage: SwapErrorStage): SwapSdkE
|
|
|
23
23
|
type SdkLogLevel = "debug" | "warn";
|
|
24
24
|
interface SdkLogEntry {
|
|
25
25
|
level: SdkLogLevel;
|
|
26
|
-
event: "api.request" | "api.response"
|
|
26
|
+
event: "api.request" | "api.response";
|
|
27
27
|
path: string;
|
|
28
28
|
stage: SwapErrorStage;
|
|
29
|
-
attempt: number;
|
|
30
29
|
status?: number;
|
|
31
30
|
durationMs?: number;
|
|
32
31
|
code?: SwapErrorCode;
|
|
@@ -42,19 +41,12 @@ interface ApiClientConfig {
|
|
|
42
41
|
fetch?: typeof globalThis.fetch;
|
|
43
42
|
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
44
43
|
timeoutMs?: number;
|
|
45
|
-
retry?: Partial<RetryConfig>;
|
|
46
44
|
logger?: SdkLogger;
|
|
47
45
|
}
|
|
48
46
|
interface ApiRequestOptions {
|
|
49
47
|
signal?: AbortSignal;
|
|
50
48
|
idempotencyKey?: string;
|
|
51
49
|
}
|
|
52
|
-
interface RetryConfig {
|
|
53
|
-
maxRetries: number;
|
|
54
|
-
baseDelayMs: number;
|
|
55
|
-
maxDelayMs: number;
|
|
56
|
-
jitter: boolean;
|
|
57
|
-
}
|
|
58
50
|
declare class ApiClient {
|
|
59
51
|
private readonly config;
|
|
60
52
|
private readonly baseUrl;
|
|
@@ -74,8 +66,6 @@ declare class ApiClient {
|
|
|
74
66
|
private requestOnce;
|
|
75
67
|
private buildUrl;
|
|
76
68
|
private buildHeaders;
|
|
77
|
-
private retryConfig;
|
|
78
|
-
private retryDelay;
|
|
79
69
|
private log;
|
|
80
70
|
private parseResponse;
|
|
81
71
|
private isEnvelope;
|
|
@@ -406,4 +396,4 @@ declare function resolveSourceTxHash(input: {
|
|
|
406
396
|
declare function parseUnits(value: string, decimals: number): BaseUnitAmount;
|
|
407
397
|
declare function formatUnits(value: BaseUnitAmount, decimals: number): string;
|
|
408
398
|
|
|
409
|
-
export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderReference, type OrderStatusLookup, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaRequiredCollateralDecreaseInput, type ResolveMcaWithdrawPolicyInput, type
|
|
399
|
+
export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderReference, type OrderStatusLookup, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaRequiredCollateralDecreaseInput, type ResolveMcaWithdrawPolicyInput, type SdkLogEntry, type SdkLogLevel, type SdkLogger, SwapBuild, SwapBuildDataRaw, SwapBuildRequestRaw, SwapClient, type SwapClientConfig, SwapCrossChainToTokensDataRaw, type SwapErrorCode, type SwapErrorStage, SwapExecutionResult, SwapFromTokensDataRaw, SwapHistoryAuthChallengeRaw, SwapHistoryAuthChallengeRequestRaw, SwapHistoryAuthProofRaw, SwapHistoryAuthTokenRaw, SwapHistoryAuthVerifyRequestRaw, SwapHistoryDataRaw, type SwapHistoryItem, type SwapHistoryPage, SwapHistoryParamsRaw, SwapHistoryRecordRaw, SwapInput, SwapLifecycleEvent, SwapMcaPayloadRaw, SwapMcaRelayerRequestRaw, SwapOrderStatusDataRaw, SwapOrderStatusParamsRaw, SwapOrderSubmitDataRaw, SwapOrderSubmitRequestRaw, SwapQuoteDataRaw, SwapQuoteRequestRaw, SwapReportDataRaw, SwapReportRequestRaw, SwapSdkError, type SwapSdkErrorOptions, type SwapTokenListItem, type TokenListRequest, WaitForOrderInput, WaitMode, asSwapSdkError, assertOrderStatusParams, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, buildOrderStatusQuery, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeQuote, orderStatusParamsFromHistoryItem, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, resolveOrderStatusLookup, resolveSourceTxHash, resolveSwapReportRecordId, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, shouldPollSwapOrderStatus, toApiAssetAddress, toApiChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,10 +23,9 @@ declare function asSwapSdkError(error: unknown, stage: SwapErrorStage): SwapSdkE
|
|
|
23
23
|
type SdkLogLevel = "debug" | "warn";
|
|
24
24
|
interface SdkLogEntry {
|
|
25
25
|
level: SdkLogLevel;
|
|
26
|
-
event: "api.request" | "api.response"
|
|
26
|
+
event: "api.request" | "api.response";
|
|
27
27
|
path: string;
|
|
28
28
|
stage: SwapErrorStage;
|
|
29
|
-
attempt: number;
|
|
30
29
|
status?: number;
|
|
31
30
|
durationMs?: number;
|
|
32
31
|
code?: SwapErrorCode;
|
|
@@ -42,19 +41,12 @@ interface ApiClientConfig {
|
|
|
42
41
|
fetch?: typeof globalThis.fetch;
|
|
43
42
|
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
44
43
|
timeoutMs?: number;
|
|
45
|
-
retry?: Partial<RetryConfig>;
|
|
46
44
|
logger?: SdkLogger;
|
|
47
45
|
}
|
|
48
46
|
interface ApiRequestOptions {
|
|
49
47
|
signal?: AbortSignal;
|
|
50
48
|
idempotencyKey?: string;
|
|
51
49
|
}
|
|
52
|
-
interface RetryConfig {
|
|
53
|
-
maxRetries: number;
|
|
54
|
-
baseDelayMs: number;
|
|
55
|
-
maxDelayMs: number;
|
|
56
|
-
jitter: boolean;
|
|
57
|
-
}
|
|
58
50
|
declare class ApiClient {
|
|
59
51
|
private readonly config;
|
|
60
52
|
private readonly baseUrl;
|
|
@@ -74,8 +66,6 @@ declare class ApiClient {
|
|
|
74
66
|
private requestOnce;
|
|
75
67
|
private buildUrl;
|
|
76
68
|
private buildHeaders;
|
|
77
|
-
private retryConfig;
|
|
78
|
-
private retryDelay;
|
|
79
69
|
private log;
|
|
80
70
|
private parseResponse;
|
|
81
71
|
private isEnvelope;
|
|
@@ -406,4 +396,4 @@ declare function resolveSourceTxHash(input: {
|
|
|
406
396
|
declare function parseUnits(value: string, decimals: number): BaseUnitAmount;
|
|
407
397
|
declare function formatUnits(value: BaseUnitAmount, decimals: number): string;
|
|
408
398
|
|
|
409
|
-
export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderReference, type OrderStatusLookup, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaRequiredCollateralDecreaseInput, type ResolveMcaWithdrawPolicyInput, type
|
|
399
|
+
export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderReference, type OrderStatusLookup, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaRequiredCollateralDecreaseInput, type ResolveMcaWithdrawPolicyInput, type SdkLogEntry, type SdkLogLevel, type SdkLogger, SwapBuild, SwapBuildDataRaw, SwapBuildRequestRaw, SwapClient, type SwapClientConfig, SwapCrossChainToTokensDataRaw, type SwapErrorCode, type SwapErrorStage, SwapExecutionResult, SwapFromTokensDataRaw, SwapHistoryAuthChallengeRaw, SwapHistoryAuthChallengeRequestRaw, SwapHistoryAuthProofRaw, SwapHistoryAuthTokenRaw, SwapHistoryAuthVerifyRequestRaw, SwapHistoryDataRaw, type SwapHistoryItem, type SwapHistoryPage, SwapHistoryParamsRaw, SwapHistoryRecordRaw, SwapInput, SwapLifecycleEvent, SwapMcaPayloadRaw, SwapMcaRelayerRequestRaw, SwapOrderStatusDataRaw, SwapOrderStatusParamsRaw, SwapOrderSubmitDataRaw, SwapOrderSubmitRequestRaw, SwapQuoteDataRaw, SwapQuoteRequestRaw, SwapReportDataRaw, SwapReportRequestRaw, SwapSdkError, type SwapSdkErrorOptions, type SwapTokenListItem, type TokenListRequest, WaitForOrderInput, WaitMode, asSwapSdkError, assertOrderStatusParams, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, buildOrderStatusQuery, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeQuote, orderStatusParamsFromHistoryItem, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, resolveOrderStatusLookup, resolveSourceTxHash, resolveSwapReportRecordId, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, shouldPollSwapOrderStatus, toApiAssetAddress, toApiChain };
|
package/dist/index.js
CHANGED
|
@@ -116,12 +116,6 @@ function resolveSourceTxHash(input) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
// src/api/ApiClient.ts
|
|
119
|
-
var DEFAULT_RETRY = {
|
|
120
|
-
maxRetries: 2,
|
|
121
|
-
baseDelayMs: 250,
|
|
122
|
-
maxDelayMs: 2e3,
|
|
123
|
-
jitter: true
|
|
124
|
-
};
|
|
125
119
|
var ApiClient = class {
|
|
126
120
|
constructor(config) {
|
|
127
121
|
this.config = config;
|
|
@@ -140,8 +134,7 @@ var ApiClient = class {
|
|
|
140
134
|
return this.request("/api/v2/swap/quote", "quote", {
|
|
141
135
|
...options,
|
|
142
136
|
method: "POST",
|
|
143
|
-
body
|
|
144
|
-
retryableOperation: true
|
|
137
|
+
body
|
|
145
138
|
});
|
|
146
139
|
}
|
|
147
140
|
build(body, options = {}) {
|
|
@@ -170,7 +163,6 @@ var ApiClient = class {
|
|
|
170
163
|
return this.request("/api/swap/order-status", "status", {
|
|
171
164
|
...options,
|
|
172
165
|
method: "GET",
|
|
173
|
-
retryableOperation: true,
|
|
174
166
|
query
|
|
175
167
|
});
|
|
176
168
|
}
|
|
@@ -185,7 +177,6 @@ var ApiClient = class {
|
|
|
185
177
|
return this.request("/api/swap/history", "history", {
|
|
186
178
|
...options,
|
|
187
179
|
method: "GET",
|
|
188
|
-
retryableOperation: true,
|
|
189
180
|
query: {
|
|
190
181
|
sender: params.sender,
|
|
191
182
|
mode: params.mode,
|
|
@@ -213,7 +204,6 @@ var ApiClient = class {
|
|
|
213
204
|
return this.request("/get_chain_prices", "tokens", {
|
|
214
205
|
...options,
|
|
215
206
|
method: "GET",
|
|
216
|
-
retryableOperation: true,
|
|
217
207
|
query: { chain: chainId }
|
|
218
208
|
});
|
|
219
209
|
}
|
|
@@ -221,7 +211,6 @@ var ApiClient = class {
|
|
|
221
211
|
return this.request("/api/swap/supported_to_tokens", "tokens", {
|
|
222
212
|
...options,
|
|
223
213
|
method: "GET",
|
|
224
|
-
retryableOperation: true,
|
|
225
214
|
query: { chain: chainId }
|
|
226
215
|
});
|
|
227
216
|
}
|
|
@@ -231,39 +220,15 @@ var ApiClient = class {
|
|
|
231
220
|
options.idempotencyKey,
|
|
232
221
|
options.authenticationToken
|
|
233
222
|
);
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
stage,
|
|
242
|
-
attempt
|
|
243
|
-
});
|
|
244
|
-
try {
|
|
245
|
-
return await this.requestOnce(url, path, stage, options, headers, attempt);
|
|
246
|
-
} catch (error) {
|
|
247
|
-
const sdkError = error instanceof SwapSdkError ? error : new SwapSdkError("HTTP_ERROR", stage, "Network request failed", {
|
|
248
|
-
cause: error,
|
|
249
|
-
retryable: true
|
|
250
|
-
});
|
|
251
|
-
const canRetry = options.retryableOperation === true && sdkError.retryable && sdkError.code !== "REQUEST_ABORTED" && attempt <= retry.maxRetries;
|
|
252
|
-
if (!canRetry) throw sdkError;
|
|
253
|
-
this.log({
|
|
254
|
-
level: "warn",
|
|
255
|
-
event: "api.retry",
|
|
256
|
-
path,
|
|
257
|
-
stage,
|
|
258
|
-
attempt,
|
|
259
|
-
code: sdkError.code
|
|
260
|
-
});
|
|
261
|
-
await waitForRetry(this.retryDelay(attempt, retry), options.signal, stage);
|
|
262
|
-
attempt += 1;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
223
|
+
this.log({
|
|
224
|
+
level: "debug",
|
|
225
|
+
event: "api.request",
|
|
226
|
+
path,
|
|
227
|
+
stage
|
|
228
|
+
});
|
|
229
|
+
return this.requestOnce(url, path, stage, options, headers);
|
|
265
230
|
}
|
|
266
|
-
async requestOnce(url, path, stage, options, headers
|
|
231
|
+
async requestOnce(url, path, stage, options, headers) {
|
|
267
232
|
if (options.signal?.aborted) {
|
|
268
233
|
throw new SwapSdkError("REQUEST_ABORTED", stage, "Request aborted", {
|
|
269
234
|
cause: options.signal.reason
|
|
@@ -300,7 +265,6 @@ var ApiClient = class {
|
|
|
300
265
|
event: "api.response",
|
|
301
266
|
path,
|
|
302
267
|
stage,
|
|
303
|
-
attempt,
|
|
304
268
|
status: response.status,
|
|
305
269
|
durationMs: Date.now() - startedAt
|
|
306
270
|
});
|
|
@@ -347,12 +311,7 @@ var ApiClient = class {
|
|
|
347
311
|
{ cause: error, retryable: timedOut }
|
|
348
312
|
);
|
|
349
313
|
}
|
|
350
|
-
const details = networkFailureDetails(
|
|
351
|
-
error,
|
|
352
|
-
options.method,
|
|
353
|
-
path,
|
|
354
|
-
attempt
|
|
355
|
-
);
|
|
314
|
+
const details = networkFailureDetails(error, options.method, path);
|
|
356
315
|
console.error("SDK network request failed", {
|
|
357
316
|
...details,
|
|
358
317
|
stage
|
|
@@ -393,24 +352,6 @@ var ApiClient = class {
|
|
|
393
352
|
...configured
|
|
394
353
|
};
|
|
395
354
|
}
|
|
396
|
-
retryConfig() {
|
|
397
|
-
const configured = { ...DEFAULT_RETRY, ...this.config.retry };
|
|
398
|
-
if (!Number.isSafeInteger(configured.maxRetries) || configured.maxRetries < 0 || !Number.isFinite(configured.baseDelayMs) || configured.baseDelayMs < 0 || !Number.isFinite(configured.maxDelayMs) || configured.maxDelayMs < configured.baseDelayMs) {
|
|
399
|
-
throw new SwapSdkError(
|
|
400
|
-
"INVALID_REQUEST",
|
|
401
|
-
"quote",
|
|
402
|
-
"Invalid retry configuration"
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
return configured;
|
|
406
|
-
}
|
|
407
|
-
retryDelay(attempt, retry) {
|
|
408
|
-
const exponential = Math.min(
|
|
409
|
-
retry.maxDelayMs,
|
|
410
|
-
retry.baseDelayMs * 2 ** (attempt - 1)
|
|
411
|
-
);
|
|
412
|
-
return retry.jitter ? Math.min(retry.maxDelayMs, exponential * (0.5 + Math.random())) : exponential;
|
|
413
|
-
}
|
|
414
355
|
log(entry) {
|
|
415
356
|
try {
|
|
416
357
|
this.config.logger?.log(entry);
|
|
@@ -443,7 +384,7 @@ var ApiClient = class {
|
|
|
443
384
|
return typeof value.msg === "string" && value.msg.trim() ? value.msg.trim() : void 0;
|
|
444
385
|
}
|
|
445
386
|
};
|
|
446
|
-
function networkFailureDetails(error, method, path
|
|
387
|
+
function networkFailureDetails(error, method, path) {
|
|
447
388
|
const causeName = error instanceof Error && error.name.trim() ? error.name.trim() : "Error";
|
|
448
389
|
const rawMessage = error instanceof Error && error.message.trim() ? error.message.trim() : String(error);
|
|
449
390
|
const causeMessage = rawMessage.replace(
|
|
@@ -453,36 +394,10 @@ function networkFailureDetails(error, method, path, attempt) {
|
|
|
453
394
|
return {
|
|
454
395
|
method,
|
|
455
396
|
path,
|
|
456
|
-
attempt,
|
|
457
397
|
causeName,
|
|
458
398
|
causeMessage
|
|
459
399
|
};
|
|
460
400
|
}
|
|
461
|
-
function waitForRetry(delayMs, signal, stage) {
|
|
462
|
-
return new Promise((resolve, reject) => {
|
|
463
|
-
if (signal?.aborted) {
|
|
464
|
-
reject(
|
|
465
|
-
new SwapSdkError("REQUEST_ABORTED", stage, "Request aborted", {
|
|
466
|
-
cause: signal.reason
|
|
467
|
-
})
|
|
468
|
-
);
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
const onAbort = () => {
|
|
472
|
-
clearTimeout(timeout);
|
|
473
|
-
reject(
|
|
474
|
-
new SwapSdkError("REQUEST_ABORTED", stage, "Request aborted", {
|
|
475
|
-
cause: signal?.reason
|
|
476
|
-
})
|
|
477
|
-
);
|
|
478
|
-
};
|
|
479
|
-
const timeout = setTimeout(() => {
|
|
480
|
-
signal?.removeEventListener("abort", onAbort);
|
|
481
|
-
resolve();
|
|
482
|
-
}, delayMs);
|
|
483
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
401
|
|
|
487
402
|
// src/core/lifecycle.ts
|
|
488
403
|
var ORDER_STATUS_MAP = {
|