@rhea-finance/cross-chain-aggregation-dex 2.1.7 → 2.1.8

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 (39) hide show
  1. package/dist/executors/aptos.js +2 -0
  2. package/dist/executors/aptos.js.map +1 -1
  3. package/dist/executors/aptos.mjs +2 -0
  4. package/dist/executors/aptos.mjs.map +1 -1
  5. package/dist/executors/bitcoin.js +2 -0
  6. package/dist/executors/bitcoin.js.map +1 -1
  7. package/dist/executors/bitcoin.mjs +2 -0
  8. package/dist/executors/bitcoin.mjs.map +1 -1
  9. package/dist/executors/evm.js +2 -0
  10. package/dist/executors/evm.js.map +1 -1
  11. package/dist/executors/evm.mjs +2 -0
  12. package/dist/executors/evm.mjs.map +1 -1
  13. package/dist/executors/near.js +2 -0
  14. package/dist/executors/near.js.map +1 -1
  15. package/dist/executors/near.mjs +2 -0
  16. package/dist/executors/near.mjs.map +1 -1
  17. package/dist/executors/solana.js +2 -0
  18. package/dist/executors/solana.js.map +1 -1
  19. package/dist/executors/solana.mjs +2 -0
  20. package/dist/executors/solana.mjs.map +1 -1
  21. package/dist/executors/sui.js +2 -0
  22. package/dist/executors/sui.js.map +1 -1
  23. package/dist/executors/sui.mjs +2 -0
  24. package/dist/executors/sui.mjs.map +1 -1
  25. package/dist/executors/tron.js +2 -0
  26. package/dist/executors/tron.js.map +1 -1
  27. package/dist/executors/tron.mjs +2 -0
  28. package/dist/executors/tron.mjs.map +1 -1
  29. package/dist/executors/zcash.js +2 -0
  30. package/dist/executors/zcash.js.map +1 -1
  31. package/dist/executors/zcash.mjs +2 -0
  32. package/dist/executors/zcash.mjs.map +1 -1
  33. package/dist/index.d.mts +14 -1
  34. package/dist/index.d.ts +14 -1
  35. package/dist/index.js +83 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/index.mjs +81 -1
  38. package/dist/index.mjs.map +1 -1
  39. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,5 +1,67 @@
1
1
  import { z, ZodError } from 'zod';
2
2
 
3
+ // src/core/catchLog.ts
4
+ var MAX_CAUSE_DEPTH = 8;
5
+ var catchLoggingEnabled = false;
6
+ function setSdkCatchLogging(enabled) {
7
+ catchLoggingEnabled = Boolean(enabled);
8
+ }
9
+ function isSdkCatchLoggingEnabled() {
10
+ return catchLoggingEnabled;
11
+ }
12
+ function readProp(value, key) {
13
+ if (typeof value !== "object" || value === null) return void 0;
14
+ return Reflect.get(value, key);
15
+ }
16
+ function redactSensitive(text) {
17
+ return text.replace(/(https?:\/\/[^\s?'"`]+)\?[^\s'"`]*/gi, "$1?[redacted]");
18
+ }
19
+ function serializeCaughtError(error, depth = 0) {
20
+ if (error === null || error === void 0) {
21
+ return { value: error };
22
+ }
23
+ if (typeof error !== "object") {
24
+ return {
25
+ value: typeof error === "string" ? redactSensitive(error) : error
26
+ };
27
+ }
28
+ const name = typeof readProp(error, "name") === "string" ? readProp(error, "name") : void 0;
29
+ const message = typeof readProp(error, "message") === "string" ? redactSensitive(readProp(error, "message")) : void 0;
30
+ const code = readProp(error, "code");
31
+ const stage = readProp(error, "stage");
32
+ const details = readProp(error, "details");
33
+ const stack = typeof readProp(error, "stack") === "string" ? redactSensitive(readProp(error, "stack")) : void 0;
34
+ const options = readProp(error, "options");
35
+ const optionsCause = typeof options === "object" && options !== null ? Reflect.get(options, "cause") : void 0;
36
+ const directCause = readProp(error, "cause");
37
+ const cause = optionsCause ?? directCause;
38
+ const out = {
39
+ ...name ? { name } : {},
40
+ ...message !== void 0 ? { message } : {},
41
+ ...code !== void 0 ? { code } : {},
42
+ ...stage !== void 0 ? { stage } : {},
43
+ ...details !== void 0 ? { details } : {},
44
+ ...stack ? { stack } : {}
45
+ };
46
+ if (cause !== void 0 && depth < MAX_CAUSE_DEPTH) {
47
+ out.cause = serializeCaughtError(cause, depth + 1);
48
+ } else if (Object.keys(out).length === 0) {
49
+ try {
50
+ out.raw = JSON.parse(
51
+ redactSensitive(JSON.stringify(error) ?? "null")
52
+ );
53
+ } catch {
54
+ out.raw = redactSensitive(String(error));
55
+ }
56
+ }
57
+ return out;
58
+ }
59
+ function logSdkCaughtError(scope, error) {
60
+ if (!catchLoggingEnabled) return;
61
+ const payload = serializeCaughtError(error);
62
+ console.error(`[cross-chain-aggregation-dex] catch:${scope}`, payload);
63
+ }
64
+
3
65
  // src/core/errors.ts
4
66
  var SwapSdkError = class extends Error {
5
67
  constructor(code, stage, message, options = {}) {
@@ -21,6 +83,7 @@ var SwapSdkError = class extends Error {
21
83
  }
22
84
  };
23
85
  function asSwapSdkError(error, stage) {
86
+ logSdkCaughtError(`asSwapSdkError:${stage}`, error);
24
87
  if (error instanceof SwapSdkError) return error;
25
88
  const message = error instanceof Error ? error.message : String(error);
26
89
  return new SwapSdkError("API_ERROR", stage, message, { cause: error });
@@ -118,6 +181,9 @@ var ApiClient = class {
118
181
  constructor(config) {
119
182
  this.config = config;
120
183
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
184
+ if (config.debugCatchLogging !== void 0) {
185
+ setSdkCatchLogging(config.debugCatchLogging);
186
+ }
121
187
  const fetchImpl = config.fetch ?? globalThis.fetch;
122
188
  if (typeof fetchImpl !== "function") {
123
189
  throw new SwapSdkError(
@@ -300,6 +366,7 @@ var ApiClient = class {
300
366
  }
301
367
  return parsed.data;
302
368
  } catch (error) {
369
+ logSdkCaughtError("api/ApiClient.ts", error);
303
370
  if (error instanceof SwapSdkError) throw error;
304
371
  if (controller.signal.aborted) {
305
372
  throw new SwapSdkError(
@@ -360,6 +427,7 @@ var ApiClient = class {
360
427
  try {
361
428
  return text ? JSON.parse(text) : {};
362
429
  } catch (error) {
430
+ logSdkCaughtError("api/ApiClient.ts", error);
363
431
  throw new SwapSdkError(
364
432
  status >= 400 ? "HTTP_ERROR" : "INVALID_API_RESPONSE",
365
433
  stage,
@@ -711,6 +779,7 @@ function normalizeBuild(raw, executionId = createExecutionId(), request) {
711
779
  raw
712
780
  };
713
781
  } catch (error) {
782
+ logSdkCaughtError("normalizers/build.ts", error);
714
783
  if (error instanceof SwapSdkError) throw error;
715
784
  throw invalidBuild(error);
716
785
  }
@@ -1210,6 +1279,7 @@ function validateResponseAmount(value, field) {
1210
1279
  try {
1211
1280
  return assertBaseUnitAmount(value);
1212
1281
  } catch (error) {
1282
+ logSdkCaughtError("normalizers/quote.ts", error);
1213
1283
  throw invalidQuote(`Quote response has invalid ${field}`, error);
1214
1284
  }
1215
1285
  }
@@ -1972,6 +2042,7 @@ function normalizeDeposit2(value) {
1972
2042
  try {
1973
2043
  return parseUnits(decimal, 24);
1974
2044
  } catch (error) {
2045
+ logSdkCaughtError("mca/withdraw.ts", error);
1975
2046
  throw new SwapSdkError(
1976
2047
  "INVALID_API_RESPONSE",
1977
2048
  "build",
@@ -2193,6 +2264,7 @@ var McaSwapService = class {
2193
2264
  }
2194
2265
  })).trim();
2195
2266
  } catch (error) {
2267
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2196
2268
  if (error instanceof SwapSdkError) throw error;
2197
2269
  throw new SwapSdkError(
2198
2270
  "SIGNING_FAILED",
@@ -2282,6 +2354,7 @@ var McaSwapService = class {
2282
2354
  ...reportRecordId ? { recordId: reportRecordId } : {}
2283
2355
  };
2284
2356
  } catch (error) {
2357
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2285
2358
  const warning = {
2286
2359
  code: "REPORT_FAILED",
2287
2360
  message: "MCA withdraw submitted but report failed",
@@ -2316,6 +2389,7 @@ var McaSwapService = class {
2316
2389
  }
2317
2390
  return result;
2318
2391
  } catch (error) {
2392
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2319
2393
  const sdkError = asSwapSdkError(error, "submit");
2320
2394
  emit({ type: "failed", executionId, error: sdkError });
2321
2395
  throw sdkError;
@@ -2326,6 +2400,7 @@ var McaSwapService = class {
2326
2400
  try {
2327
2401
  identityKey = (await provider.getIdentityKey()).trim();
2328
2402
  } catch (error) {
2403
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2329
2404
  if (error instanceof SwapSdkError) throw error;
2330
2405
  throw new SwapSdkError(
2331
2406
  "SIGNING_FAILED",
@@ -2387,6 +2462,9 @@ var SwapClient = class {
2387
2462
  this.reportRequests = /* @__PURE__ */ new Map();
2388
2463
  this.tokenListCache = /* @__PURE__ */ new Map();
2389
2464
  this.tokenListInflight = /* @__PURE__ */ new Map();
2465
+ if (config.debugCatchLogging !== void 0) {
2466
+ setSdkCatchLogging(config.debugCatchLogging);
2467
+ }
2390
2468
  this.config = config;
2391
2469
  this.api = new ApiClient(config);
2392
2470
  this.registry = new ExecutorRegistry(config.executors ?? []);
@@ -2592,6 +2670,7 @@ var SwapClient = class {
2592
2670
  ...reportRecordId ? { recordId: reportRecordId } : {}
2593
2671
  };
2594
2672
  } catch (error) {
2673
+ logSdkCaughtError("client/SwapClient.ts", error);
2595
2674
  const warning = {
2596
2675
  code: "REPORT_FAILED",
2597
2676
  message: "Swap submitted but report failed",
@@ -2637,6 +2716,7 @@ var SwapClient = class {
2637
2716
  }
2638
2717
  return result;
2639
2718
  } catch (error) {
2719
+ logSdkCaughtError("client/SwapClient.ts", error);
2640
2720
  const sdkError = asSwapSdkError(error, "broadcast");
2641
2721
  emit({ type: "failed", executionId: build.executionId, error: sdkError });
2642
2722
  throw sdkError;
@@ -2888,6 +2968,6 @@ function delay(ms, signal) {
2888
2968
  });
2889
2969
  }
2890
2970
 
2891
- export { ApiClient, DEFAULT_MCA_SIGNER_PRIORITY, ExecutorRegistry, SwapClient, SwapSdkError, asSwapSdkError, assertBaseUnitAmount, assertOrderStatusParams, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, buildOrderStatusQuery, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeOrderStatus, normalizeQuote, orderStatusParamsFromHistoryItem, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, resolveOrderStatusLookup, resolveSourceTxHash, resolveSwapReportRecordId, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, shouldPollSwapOrderStatus, toApiAssetAddress, toApiChain };
2971
+ export { ApiClient, DEFAULT_MCA_SIGNER_PRIORITY, ExecutorRegistry, SwapClient, SwapSdkError, asSwapSdkError, assertBaseUnitAmount, assertOrderStatusParams, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, buildOrderStatusQuery, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, isSdkCatchLoggingEnabled, logSdkCaughtError, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeOrderStatus, normalizeQuote, orderStatusParamsFromHistoryItem, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, resolveOrderStatusLookup, resolveSourceTxHash, resolveSwapReportRecordId, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, setSdkCatchLogging, shouldPollSwapOrderStatus, toApiAssetAddress, toApiChain };
2892
2972
  //# sourceMappingURL=index.mjs.map
2893
2973
  //# sourceMappingURL=index.mjs.map