@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.js CHANGED
@@ -2,6 +2,68 @@
2
2
 
3
3
  var zod = require('zod');
4
4
 
5
+ // src/core/catchLog.ts
6
+ var MAX_CAUSE_DEPTH = 8;
7
+ var catchLoggingEnabled = false;
8
+ function setSdkCatchLogging(enabled) {
9
+ catchLoggingEnabled = Boolean(enabled);
10
+ }
11
+ function isSdkCatchLoggingEnabled() {
12
+ return catchLoggingEnabled;
13
+ }
14
+ function readProp(value, key) {
15
+ if (typeof value !== "object" || value === null) return void 0;
16
+ return Reflect.get(value, key);
17
+ }
18
+ function redactSensitive(text) {
19
+ return text.replace(/(https?:\/\/[^\s?'"`]+)\?[^\s'"`]*/gi, "$1?[redacted]");
20
+ }
21
+ function serializeCaughtError(error, depth = 0) {
22
+ if (error === null || error === void 0) {
23
+ return { value: error };
24
+ }
25
+ if (typeof error !== "object") {
26
+ return {
27
+ value: typeof error === "string" ? redactSensitive(error) : error
28
+ };
29
+ }
30
+ const name = typeof readProp(error, "name") === "string" ? readProp(error, "name") : void 0;
31
+ const message = typeof readProp(error, "message") === "string" ? redactSensitive(readProp(error, "message")) : void 0;
32
+ const code = readProp(error, "code");
33
+ const stage = readProp(error, "stage");
34
+ const details = readProp(error, "details");
35
+ const stack = typeof readProp(error, "stack") === "string" ? redactSensitive(readProp(error, "stack")) : void 0;
36
+ const options = readProp(error, "options");
37
+ const optionsCause = typeof options === "object" && options !== null ? Reflect.get(options, "cause") : void 0;
38
+ const directCause = readProp(error, "cause");
39
+ const cause = optionsCause ?? directCause;
40
+ const out = {
41
+ ...name ? { name } : {},
42
+ ...message !== void 0 ? { message } : {},
43
+ ...code !== void 0 ? { code } : {},
44
+ ...stage !== void 0 ? { stage } : {},
45
+ ...details !== void 0 ? { details } : {},
46
+ ...stack ? { stack } : {}
47
+ };
48
+ if (cause !== void 0 && depth < MAX_CAUSE_DEPTH) {
49
+ out.cause = serializeCaughtError(cause, depth + 1);
50
+ } else if (Object.keys(out).length === 0) {
51
+ try {
52
+ out.raw = JSON.parse(
53
+ redactSensitive(JSON.stringify(error) ?? "null")
54
+ );
55
+ } catch {
56
+ out.raw = redactSensitive(String(error));
57
+ }
58
+ }
59
+ return out;
60
+ }
61
+ function logSdkCaughtError(scope, error) {
62
+ if (!catchLoggingEnabled) return;
63
+ const payload = serializeCaughtError(error);
64
+ console.error(`[cross-chain-aggregation-dex] catch:${scope}`, payload);
65
+ }
66
+
5
67
  // src/core/errors.ts
6
68
  var SwapSdkError = class extends Error {
7
69
  constructor(code, stage, message, options = {}) {
@@ -23,6 +85,7 @@ var SwapSdkError = class extends Error {
23
85
  }
24
86
  };
25
87
  function asSwapSdkError(error, stage) {
88
+ logSdkCaughtError(`asSwapSdkError:${stage}`, error);
26
89
  if (error instanceof SwapSdkError) return error;
27
90
  const message = error instanceof Error ? error.message : String(error);
28
91
  return new SwapSdkError("API_ERROR", stage, message, { cause: error });
@@ -120,6 +183,9 @@ var ApiClient = class {
120
183
  constructor(config) {
121
184
  this.config = config;
122
185
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
186
+ if (config.debugCatchLogging !== void 0) {
187
+ setSdkCatchLogging(config.debugCatchLogging);
188
+ }
123
189
  const fetchImpl = config.fetch ?? globalThis.fetch;
124
190
  if (typeof fetchImpl !== "function") {
125
191
  throw new SwapSdkError(
@@ -302,6 +368,7 @@ var ApiClient = class {
302
368
  }
303
369
  return parsed.data;
304
370
  } catch (error) {
371
+ logSdkCaughtError("api/ApiClient.ts", error);
305
372
  if (error instanceof SwapSdkError) throw error;
306
373
  if (controller.signal.aborted) {
307
374
  throw new SwapSdkError(
@@ -362,6 +429,7 @@ var ApiClient = class {
362
429
  try {
363
430
  return text ? JSON.parse(text) : {};
364
431
  } catch (error) {
432
+ logSdkCaughtError("api/ApiClient.ts", error);
365
433
  throw new SwapSdkError(
366
434
  status >= 400 ? "HTTP_ERROR" : "INVALID_API_RESPONSE",
367
435
  stage,
@@ -713,6 +781,7 @@ function normalizeBuild(raw, executionId = createExecutionId(), request) {
713
781
  raw
714
782
  };
715
783
  } catch (error) {
784
+ logSdkCaughtError("normalizers/build.ts", error);
716
785
  if (error instanceof SwapSdkError) throw error;
717
786
  throw invalidBuild(error);
718
787
  }
@@ -1212,6 +1281,7 @@ function validateResponseAmount(value, field) {
1212
1281
  try {
1213
1282
  return assertBaseUnitAmount(value);
1214
1283
  } catch (error) {
1284
+ logSdkCaughtError("normalizers/quote.ts", error);
1215
1285
  throw invalidQuote(`Quote response has invalid ${field}`, error);
1216
1286
  }
1217
1287
  }
@@ -1974,6 +2044,7 @@ function normalizeDeposit2(value) {
1974
2044
  try {
1975
2045
  return parseUnits(decimal, 24);
1976
2046
  } catch (error) {
2047
+ logSdkCaughtError("mca/withdraw.ts", error);
1977
2048
  throw new SwapSdkError(
1978
2049
  "INVALID_API_RESPONSE",
1979
2050
  "build",
@@ -2195,6 +2266,7 @@ var McaSwapService = class {
2195
2266
  }
2196
2267
  })).trim();
2197
2268
  } catch (error) {
2269
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2198
2270
  if (error instanceof SwapSdkError) throw error;
2199
2271
  throw new SwapSdkError(
2200
2272
  "SIGNING_FAILED",
@@ -2284,6 +2356,7 @@ var McaSwapService = class {
2284
2356
  ...reportRecordId ? { recordId: reportRecordId } : {}
2285
2357
  };
2286
2358
  } catch (error) {
2359
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2287
2360
  const warning = {
2288
2361
  code: "REPORT_FAILED",
2289
2362
  message: "MCA withdraw submitted but report failed",
@@ -2318,6 +2391,7 @@ var McaSwapService = class {
2318
2391
  }
2319
2392
  return result;
2320
2393
  } catch (error) {
2394
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2321
2395
  const sdkError = asSwapSdkError(error, "submit");
2322
2396
  emit({ type: "failed", executionId, error: sdkError });
2323
2397
  throw sdkError;
@@ -2328,6 +2402,7 @@ var McaSwapService = class {
2328
2402
  try {
2329
2403
  identityKey = (await provider.getIdentityKey()).trim();
2330
2404
  } catch (error) {
2405
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2331
2406
  if (error instanceof SwapSdkError) throw error;
2332
2407
  throw new SwapSdkError(
2333
2408
  "SIGNING_FAILED",
@@ -2389,6 +2464,9 @@ var SwapClient = class {
2389
2464
  this.reportRequests = /* @__PURE__ */ new Map();
2390
2465
  this.tokenListCache = /* @__PURE__ */ new Map();
2391
2466
  this.tokenListInflight = /* @__PURE__ */ new Map();
2467
+ if (config.debugCatchLogging !== void 0) {
2468
+ setSdkCatchLogging(config.debugCatchLogging);
2469
+ }
2392
2470
  this.config = config;
2393
2471
  this.api = new ApiClient(config);
2394
2472
  this.registry = new ExecutorRegistry(config.executors ?? []);
@@ -2594,6 +2672,7 @@ var SwapClient = class {
2594
2672
  ...reportRecordId ? { recordId: reportRecordId } : {}
2595
2673
  };
2596
2674
  } catch (error) {
2675
+ logSdkCaughtError("client/SwapClient.ts", error);
2597
2676
  const warning = {
2598
2677
  code: "REPORT_FAILED",
2599
2678
  message: "Swap submitted but report failed",
@@ -2639,6 +2718,7 @@ var SwapClient = class {
2639
2718
  }
2640
2719
  return result;
2641
2720
  } catch (error) {
2721
+ logSdkCaughtError("client/SwapClient.ts", error);
2642
2722
  const sdkError = asSwapSdkError(error, "broadcast");
2643
2723
  emit({ type: "failed", executionId: build.executionId, error: sdkError });
2644
2724
  throw sdkError;
@@ -2909,6 +2989,8 @@ exports.formatMcaWallet = formatMcaWallet;
2909
2989
  exports.formatUnits = formatUnits;
2910
2990
  exports.fromApiChain = fromApiChain;
2911
2991
  exports.isSameMcaSignerIdentity = isSameMcaSignerIdentity;
2992
+ exports.isSdkCatchLoggingEnabled = isSdkCatchLoggingEnabled;
2993
+ exports.logSdkCaughtError = logSdkCaughtError;
2912
2994
  exports.normalizeBuild = normalizeBuild;
2913
2995
  exports.normalizeCrossChainToTokenList = normalizeCrossChainToTokenList;
2914
2996
  exports.normalizeFromTokenList = normalizeFromTokenList;
@@ -2928,6 +3010,7 @@ exports.resolveSwapReportRecordId = resolveSwapReportRecordId;
2928
3010
  exports.selectMcaSigner = selectMcaSigner;
2929
3011
  exports.serializeMcaQuoteRequest = serializeMcaQuoteRequest;
2930
3012
  exports.serializeQuoteRequest = serializeQuoteRequest;
3013
+ exports.setSdkCatchLogging = setSdkCatchLogging;
2931
3014
  exports.shouldPollSwapOrderStatus = shouldPollSwapOrderStatus;
2932
3015
  exports.toApiAssetAddress = toApiAssetAddress;
2933
3016
  exports.toApiChain = toApiChain;