@coinlist-co/react 0.11.0 → 0.11.1-rc.8cfcd2a

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 (34) hide show
  1. package/dist/{chunk-B2HCVPCQ.js → chunk-5KYO7OOX.js} +26 -11
  2. package/dist/chunk-5KYO7OOX.js.map +1 -0
  3. package/dist/chunk-AQIHCFW4.js +279 -0
  4. package/dist/chunk-AQIHCFW4.js.map +1 -0
  5. package/dist/{chunk-UIIXXLA7.js → chunk-ZVB6KWZ2.js} +484 -141
  6. package/dist/chunk-ZVB6KWZ2.js.map +1 -0
  7. package/dist/client/index.cjs +1308 -462
  8. package/dist/client/index.cjs.map +1 -1
  9. package/dist/client/index.d.cts +216 -211
  10. package/dist/client/index.d.ts +216 -211
  11. package/dist/client/index.js +464 -108
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/collections-DrJFEDHl.d.cts +116 -0
  14. package/dist/collections-pLtrj6fw.d.ts +116 -0
  15. package/dist/{config-B5mwS_2l.d.cts → config-C6vlghJY.d.cts} +713 -22
  16. package/dist/{config-B5mwS_2l.d.ts → config-C6vlghJY.d.ts} +713 -22
  17. package/dist/server/index.cjs +766 -209
  18. package/dist/server/index.cjs.map +1 -1
  19. package/dist/server/index.d.cts +80 -3
  20. package/dist/server/index.d.ts +80 -3
  21. package/dist/server/index.js +120 -51
  22. package/dist/server/index.js.map +1 -1
  23. package/dist/shared/index.cjs +487 -124
  24. package/dist/shared/index.cjs.map +1 -1
  25. package/dist/shared/index.d.cts +18 -5
  26. package/dist/shared/index.d.ts +18 -5
  27. package/dist/shared/index.js +8 -2
  28. package/package.json +3 -2
  29. package/dist/chunk-B2HCVPCQ.js.map +0 -1
  30. package/dist/chunk-KDGNDAHA.js +0 -146
  31. package/dist/chunk-KDGNDAHA.js.map +0 -1
  32. package/dist/chunk-UIIXXLA7.js.map +0 -1
  33. package/dist/collections-BhDkYmzV.d.cts +0 -65
  34. package/dist/collections-CZhHoQHr.d.ts +0 -65
@@ -60,6 +60,7 @@ __export(shared_exports, {
60
60
  FormattedPercentUi: () => FormattedPercentUi,
61
61
  HexEncodedTransactionData: () => HexEncodedTransactionData,
62
62
  HttpError: () => HttpError,
63
+ InvariantError: () => InvariantError,
63
64
  Iso2CountryCode: () => Iso2CountryCode,
64
65
  KnownAssetSymbol: () => KnownAssetSymbol,
65
66
  KycToken: () => KycToken,
@@ -99,6 +100,7 @@ __export(shared_exports, {
99
100
  Pii: () => Pii,
100
101
  PiiAddress: () => PiiAddress,
101
102
  PiiJurisdiction: () => PiiJurisdiction,
103
+ RedactedWalletError: () => RedactedWalletError,
102
104
  RedirectUri: () => RedirectUri,
103
105
  Requirement: () => Requirement,
104
106
  RequirementId: () => RequirementId,
@@ -164,6 +166,7 @@ __export(shared_exports, {
164
166
  isStopped: () => isStopped,
165
167
  ondoSwapContractAddress: () => ondoSwapContractAddress,
166
168
  parseBlockchainAmount: () => parseBlockchainAmount,
169
+ parseUint256: () => parseUint256,
167
170
  shortenAddress: () => shortenAddress,
168
171
  superstateSwapContractAddress: () => superstateSwapContractAddress,
169
172
  txExplorerUrl: () => txExplorerUrl,
@@ -198,6 +201,8 @@ var retryAttempt = (attempt) => ({
198
201
  var renewAttempted = (value) => ({
199
202
  renewAttempted: value
200
203
  });
204
+ var requestId = (id) => ({ requestId: id });
205
+ var getRequestId = (attrs) => attrs?.requestId ?? null;
201
206
  var isProtected = (attrs) => attrs?.protected === true;
202
207
  var needUserAgent = (attrs) => attrs?.userAgent === true;
203
208
  var isIdempotent = (attrs) => attrs?.idempotencyKey === true;
@@ -219,7 +224,9 @@ var Attributes = {
219
224
  renewAttempted,
220
225
  wasRenewAttempted,
221
226
  clientCredentials,
222
- getClientCredentials
227
+ getClientCredentials,
228
+ requestId,
229
+ getRequestId
223
230
  };
224
231
 
225
232
  // src/shared/api/http.ts
@@ -229,6 +236,16 @@ var HttpError = class extends Error {
229
236
  this.name = "HttpError";
230
237
  this.response = response;
231
238
  }
239
+ /**
240
+ * Correlates this failure with the `[HTTP]` log lines for the same request,
241
+ * which carry the method, the URL, the duration and every retry. `null` when
242
+ * the response did not come from an {@link HttpClient}.
243
+ *
244
+ * Worth quoting in a bug report: it is what makes a log excerpt readable.
245
+ */
246
+ get requestId() {
247
+ return this.response.requestId ?? null;
248
+ }
232
249
  };
233
250
  function apiErrorCode(error) {
234
251
  if (!(error instanceof HttpError)) return null;
@@ -419,6 +436,12 @@ var ValidationError = class extends Error {
419
436
  this.name = "ValidationError";
420
437
  }
421
438
  };
439
+ var InvariantError = class extends Error {
440
+ constructor(message) {
441
+ super(message);
442
+ this.name = "InvariantError";
443
+ }
444
+ };
422
445
 
423
446
  // src/shared/types/blockchain/core.ts
424
447
  var ETHEREUM_CHAINS = {
@@ -466,11 +489,14 @@ var STABLE_DECIMALS = AssetDecimals(6);
466
489
  var DecimalString = (value) => value;
467
490
  var MAX_UINT_256 = 2n ** 256n - 1n;
468
491
  var assertUint256 = (value) => {
469
- if (value < 0n || value > MAX_UINT_256) {
470
- throw new Error(`Value out of uint256 bounds: ${value}`);
471
- }
472
- return value;
492
+ if (isUint256(value)) return value;
493
+ throw new InvariantError(`Value out of uint256 bounds: ${value}`);
473
494
  };
495
+ var parseUint256 = (value, label) => {
496
+ if (isUint256(value)) return value;
497
+ throw new ValidationError(`${label}: out of uint256 bounds (${value})`);
498
+ };
499
+ var isUint256 = (value) => value >= 0n && value <= MAX_UINT_256;
474
500
  var BlockchainAmount = Object.assign(
475
501
  (value) => value,
476
502
  {
@@ -480,13 +506,13 @@ var BlockchainAmount = Object.assign(
480
506
  );
481
507
  function combineAmounts(a, b, op) {
482
508
  if (a.decimals !== b.decimals) {
483
- throw new Error(
509
+ throw new InvariantError(
484
510
  `Cannot combine BlockchainAmounts with different decimals: ${a.decimals} vs ${b.decimals}`
485
511
  );
486
512
  }
487
513
  const raw = op(a.raw, b.raw);
488
514
  if (raw < 0n || raw > MAX_UINT_256) {
489
- throw new Error(`BlockchainAmount out of uint256 bounds: ${raw}`);
515
+ throw new InvariantError(`BlockchainAmount out of uint256 bounds: ${raw}`);
490
516
  }
491
517
  return BlockchainAmount({ raw, decimals: a.decimals });
492
518
  }
@@ -661,25 +687,31 @@ var SwapAuthorization = {
661
687
  };
662
688
  var SwapPreview = {
663
689
  fromDto: (dto) => ({
664
- inputAmount: assertUint256(BigInt(dto.pay_input_amount)),
665
- fee: assertUint256(BigInt(dto.fee)),
666
- outputAmount: assertUint256(BigInt(dto.receive_output_amount))
690
+ inputAmount: parseUint256(
691
+ BigInt(dto.pay_input_amount),
692
+ "SwapPreview.pay_input_amount"
693
+ ),
694
+ fee: parseUint256(BigInt(dto.fee), "SwapPreview.fee"),
695
+ outputAmount: parseUint256(
696
+ BigInt(dto.receive_output_amount),
697
+ "SwapPreview.receive_output_amount"
698
+ )
667
699
  })
668
700
  };
669
701
  var SwapStatus = {
670
702
  fromDto: (dto) => ({
671
- stopped: assertUint256(BigInt(dto.stopped)),
672
- swapLevel: assertUint256(BigInt(dto.swap_level))
703
+ stopped: parseUint256(BigInt(dto.stopped), "SwapStatus.stopped"),
704
+ swapLevel: parseUint256(BigInt(dto.swap_level), "SwapStatus.swap_level")
673
705
  })
674
706
  };
675
707
  var TokenAllowance = {
676
708
  fromDto: (dto) => ({
677
- allowance: assertUint256(BigInt(dto.allowance))
709
+ allowance: parseUint256(BigInt(dto.allowance), "TokenAllowance.allowance")
678
710
  })
679
711
  };
680
712
  var TokenBalance = {
681
713
  fromDto: (dto) => ({
682
- balance: assertUint256(BigInt(dto.balance))
714
+ balance: parseUint256(BigInt(dto.balance), "TokenBalance.balance")
683
715
  })
684
716
  };
685
717
  var AllowWalletResponse = {
@@ -804,18 +836,169 @@ function toErc20Asset(dto) {
804
836
  };
805
837
  }
806
838
 
839
+ // src/shared/core/observability/log-cause.ts
840
+ function classifyLogCause(error) {
841
+ if (error instanceof HttpError) {
842
+ return httpCause(error);
843
+ }
844
+ if (error instanceof ValidationError) {
845
+ return { type: "validation", message: error.message };
846
+ }
847
+ if (error instanceof InvariantError) {
848
+ return { type: "invariant", message: error.message };
849
+ }
850
+ if (error instanceof NotAuthenticatedError) {
851
+ return { type: "not-authenticated" };
852
+ }
853
+ if (error instanceof NotImplementedError) {
854
+ return { type: "not-implemented" };
855
+ }
856
+ return { type: "generic-error", name: errorName(error) };
857
+ }
858
+ function describeErrorUnredacted(error) {
859
+ if (error instanceof HttpError) {
860
+ return describeHttpErrorRedacted(error);
861
+ }
862
+ if (error instanceof Error) {
863
+ return `${error.name}: ${error.message}`;
864
+ }
865
+ return `thrown non-error: ${stringifyUnredacted(error)}`;
866
+ }
867
+ function stringifyUnredacted(value) {
868
+ if (value === void 0) return "";
869
+ try {
870
+ return JSON.stringify(
871
+ value,
872
+ (_key, item) => typeof item === "bigint" ? `${item}` : item
873
+ ) ?? String(value);
874
+ } catch (_) {
875
+ return "<unserializable>";
876
+ }
877
+ }
878
+ function describeHttpErrorRedacted(error) {
879
+ const code = apiErrorCode(error);
880
+ const status = error.response.status;
881
+ return code === null ? `HttpError ${status}` : `HttpError ${status} (${code})`;
882
+ }
883
+ function errorName(error) {
884
+ return error instanceof Error ? error.name : `non-error ${typeof error}`;
885
+ }
886
+ function httpCause(error) {
887
+ return {
888
+ type: "http",
889
+ requestId: error.requestId,
890
+ status: error.response.status,
891
+ code: apiErrorCode(error),
892
+ eventId: apiErrorEventId(error)
893
+ };
894
+ }
895
+ function apiErrorEventId(error) {
896
+ const body = error.response.body;
897
+ if (typeof body !== "object" || body === null) return null;
898
+ const eventId = body.event_id;
899
+ return typeof eventId === "string" ? eventId : null;
900
+ }
901
+
902
+ // src/shared/core/observability/internal-logger.ts
903
+ function internalLogger(logger, scope) {
904
+ return logger ? scopedLogger(logger, scope, {}) : noopInternalLogger;
905
+ }
906
+ var LEVEL_RANK = {
907
+ none: 0,
908
+ error: 1,
909
+ warn: 2,
910
+ info: 3,
911
+ debug: 4
912
+ };
913
+ function scopedLogger(logger, scope, bindings) {
914
+ const admits = (level) => LEVEL_RANK[logger.level()] >= LEVEL_RANK[level];
915
+ const safe = (event) => ({
916
+ msg: event.msg,
917
+ scope,
918
+ bindings,
919
+ fields: event.fields ?? {},
920
+ ...event.cause === void 0 ? {} : { cause: event.cause }
921
+ });
922
+ const unredacted = (event) => ({
923
+ msg: event.msg,
924
+ scope,
925
+ bindings,
926
+ fields: event.fields ?? {}
927
+ });
928
+ const self = {
929
+ child: (binding) => scopedLogger(logger, scope, { ...bindings, ...binding }),
930
+ debug: (event) => {
931
+ if (admits("debug")) logger.debug(() => unredacted(event()));
932
+ },
933
+ info: (event) => {
934
+ if (admits("info")) logger.info(() => safe(event()));
935
+ },
936
+ warn: (event) => {
937
+ if (admits("warn")) logger.warn(() => safe(event()));
938
+ },
939
+ error: (event) => {
940
+ if (admits("error")) logger.error(() => safe(event()));
941
+ },
942
+ failure: (event, error) => {
943
+ if (admits("debug"))
944
+ logger.debug(() => unredacted(verbatim(event(), error)));
945
+ if (admits("error")) logger.error(() => safe(classified(event(), error)));
946
+ },
947
+ warning: (event, error) => {
948
+ if (admits("debug"))
949
+ logger.debug(() => unredacted(verbatim(event(), error)));
950
+ if (admits("warn")) logger.warn(() => safe(classified(event(), error)));
951
+ },
952
+ wrap: async (op, params, run) => {
953
+ const opLog = self.child({ op });
954
+ opLog.debug(() => ({ msg: "call", fields: { params } }));
955
+ try {
956
+ return await run();
957
+ } catch (error) {
958
+ opLog.failure(() => ({ msg: "call failed" }), error);
959
+ throw error;
960
+ }
961
+ }
962
+ };
963
+ return self;
964
+ }
965
+ function verbatim(event, error) {
966
+ return {
967
+ msg: event.msg,
968
+ fields: { ...event.fields, error: describeErrorUnredacted(error) }
969
+ };
970
+ }
971
+ function classified(event, error) {
972
+ return { ...event, cause: event.cause ?? classifyLogCause(error) };
973
+ }
974
+ var noopInternalLogger = {
975
+ child: () => noopInternalLogger,
976
+ debug: () => void 0,
977
+ info: () => void 0,
978
+ warn: () => void 0,
979
+ error: () => void 0,
980
+ failure: () => void 0,
981
+ warning: () => void 0,
982
+ wrap: (_op, _params, run) => run()
983
+ };
984
+
807
985
  // src/shared/core/blockchain/erc20/erc20-namespace.ts
808
986
  var Erc20NamespaceImpl = class {
809
987
  constructor(ctx) {
810
988
  this.ctx = ctx;
989
+ this.log = internalLogger(ctx.logger, "ERC20");
811
990
  }
812
991
  async getAllowance(params) {
813
- await this.ctx.ensureUserAuthenticated();
814
- return getTokenAllowance(this.ctx.api, params);
992
+ return this.log.wrap("getAllowance", params, async () => {
993
+ await this.ctx.ensureUserAuthenticated();
994
+ return getTokenAllowance(this.ctx.api, params);
995
+ });
815
996
  }
816
997
  async getBalance(params) {
817
- await this.ctx.ensureUserAuthenticated();
818
- return getTokenBalance(this.ctx.api, params);
998
+ return this.log.wrap("getBalance", params, async () => {
999
+ await this.ctx.ensureUserAuthenticated();
1000
+ return getTokenBalance(this.ctx.api, params);
1001
+ });
819
1002
  }
820
1003
  };
821
1004
 
@@ -1007,7 +1190,7 @@ var TOKEN_REGISTRY = {
1007
1190
  case "USDT":
1008
1191
  return USDT;
1009
1192
  default:
1010
- throw new Error(`Unknown asset symbol: ${symbol}`);
1193
+ throw new InvariantError(`Unknown asset symbol: ${symbol}`);
1011
1194
  }
1012
1195
  },
1013
1196
  contractAddress: (symbol, chain) => {
@@ -1017,7 +1200,7 @@ var TOKEN_REGISTRY = {
1017
1200
  case "USDT":
1018
1201
  return USDT_ADDRESSES[chain];
1019
1202
  default:
1020
- throw new Error(`Unknown asset symbol: ${symbol}`);
1203
+ throw new InvariantError(`Unknown asset symbol: ${symbol}`);
1021
1204
  }
1022
1205
  }
1023
1206
  };
@@ -1063,15 +1246,30 @@ var Asset = {
1063
1246
  var OfferId = (value) => value;
1064
1247
  var OfferSlug = (value) => value;
1065
1248
  var Offer = {
1249
+ fromDto: (dto) => {
1250
+ if (!Array.isArray(dto.tokens)) {
1251
+ throw new ValidationError(
1252
+ `Offer.tokens: expected an array, got ${typeof dto.tokens}`
1253
+ );
1254
+ }
1255
+ return {
1256
+ id: OfferId(dto.id),
1257
+ slug: OfferSlug(dto.slug),
1258
+ type: dto.type,
1259
+ tagline: dto.tagline,
1260
+ bannerUrl: dto.banner_url,
1261
+ logoUrl: dto.logo_url,
1262
+ startsAt: new Date(dto.starts_at),
1263
+ endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
1264
+ tokens: dto.tokens.map(OfferToken.fromDto)
1265
+ };
1266
+ }
1267
+ };
1268
+ var OfferToken = {
1066
1269
  fromDto: (dto) => ({
1067
- id: OfferId(dto.id),
1068
- slug: OfferSlug(dto.slug),
1069
- type: dto.type,
1070
- tagline: dto.tagline,
1071
- bannerUrl: dto.banner_url,
1072
- logoUrl: dto.logo_url,
1073
- startsAt: new Date(dto.starts_at),
1074
- endsAt: dto.ends_at ? new Date(dto.ends_at) : null
1270
+ role: dto.role,
1271
+ chain: Chain(dto.chain),
1272
+ address: EvmContractAddress(dto.address)
1075
1273
  })
1076
1274
  };
1077
1275
 
@@ -1081,25 +1279,39 @@ var OfferOptionSlug = (value) => value;
1081
1279
  var OfferDetail = {
1082
1280
  fromDto: (dto) => {
1083
1281
  if (!Array.isArray(dto.funding_assets)) {
1084
- throw new Error(`funding_assets must be an array`);
1282
+ throw new ValidationError(
1283
+ `OfferDetail.funding_assets: expected an array, got ${typeof dto.funding_assets}`
1284
+ );
1085
1285
  }
1086
1286
  if (!Array.isArray(dto.options)) {
1087
- throw new Error(`options must be an array`);
1287
+ throw new ValidationError(
1288
+ `OfferDetail.options: expected an array, got ${typeof dto.options}`
1289
+ );
1088
1290
  }
1089
1291
  if (!Array.isArray(dto.terms)) {
1090
- throw new Error(`terms must be an array`);
1292
+ throw new ValidationError(
1293
+ `OfferDetail.terms: expected an array, got ${typeof dto.terms}`
1294
+ );
1091
1295
  }
1092
1296
  if (!Array.isArray(dto.links)) {
1093
- throw new Error(`links must be an array`);
1297
+ throw new ValidationError(
1298
+ `OfferDetail.links: expected an array, got ${typeof dto.links}`
1299
+ );
1094
1300
  }
1095
1301
  if (!Array.isArray(dto.faqs)) {
1096
- throw new Error(`faqs must be an array`);
1302
+ throw new ValidationError(
1303
+ `OfferDetail.faqs: expected an array, got ${typeof dto.faqs}`
1304
+ );
1097
1305
  }
1098
1306
  if (!Array.isArray(dto.milestones)) {
1099
- throw new Error(`milestones must be an array`);
1307
+ throw new ValidationError(
1308
+ `OfferDetail.milestones: expected an array, got ${typeof dto.milestones}`
1309
+ );
1100
1310
  }
1101
1311
  if (!Array.isArray(dto.tokens)) {
1102
- throw new Error(`tokens must be an array`);
1312
+ throw new ValidationError(
1313
+ `OfferDetail.tokens: expected an array, got ${typeof dto.tokens}`
1314
+ );
1103
1315
  }
1104
1316
  return {
1105
1317
  id: OfferId(dto.id),
@@ -1161,13 +1373,6 @@ var Milestone = {
1161
1373
  status: dto.status
1162
1374
  })
1163
1375
  };
1164
- var OfferToken = {
1165
- fromDto: (dto) => ({
1166
- role: dto.role,
1167
- chain: Chain(dto.chain),
1168
- address: EvmContractAddress(dto.address)
1169
- })
1170
- };
1171
1376
 
1172
1377
  // src/shared/types/providers/coin-list/token-sale.ts
1173
1378
  var ParticipationId = (value) => value;
@@ -1254,29 +1459,38 @@ async function createParticipation(api, params) {
1254
1459
  var CoinListTokenSaleNamespaceImpl = class {
1255
1460
  constructor(ctx) {
1256
1461
  this.ctx = ctx;
1462
+ this.log = internalLogger(ctx.logger, "TOKEN_SALE");
1257
1463
  }
1258
1464
  async list(offerId) {
1259
- await this.ctx.ensureUserAuthenticated();
1260
- return fetchParticipations(this.ctx.api, offerId);
1465
+ return this.log.wrap("list", offerId, async () => {
1466
+ await this.ctx.ensureUserAuthenticated();
1467
+ return fetchParticipations(this.ctx.api, offerId);
1468
+ });
1261
1469
  }
1262
1470
  async listPage(params) {
1263
- await this.ctx.ensureUserAuthenticated();
1264
- return fetchParticipationsPage(this.ctx.api, params);
1471
+ return this.log.wrap("listPage", params, async () => {
1472
+ await this.ctx.ensureUserAuthenticated();
1473
+ return fetchParticipationsPage(this.ctx.api, params);
1474
+ });
1265
1475
  }
1266
1476
  async get(id) {
1267
- await this.ctx.ensureUserAuthenticated();
1268
- return fetchParticipation(this.ctx.api, id);
1477
+ return this.log.wrap("get", id, async () => {
1478
+ await this.ctx.ensureUserAuthenticated();
1479
+ return fetchParticipation(this.ctx.api, id);
1480
+ });
1269
1481
  }
1270
1482
  async createParticipation(params) {
1271
- await this.ctx.ensureUserAuthenticated();
1272
- return createParticipation(this.ctx.api, params);
1483
+ return this.log.wrap("createParticipation", params, async () => {
1484
+ await this.ctx.ensureUserAuthenticated();
1485
+ return createParticipation(this.ctx.api, params);
1486
+ });
1273
1487
  }
1274
1488
  };
1275
1489
 
1276
1490
  // src/shared/core/checkout/ondo/constants.ts
1277
1491
  var ONDO_SWAP_CONTRACT_ADDRESSES = {
1278
1492
  ethereum_sepolia: EvmContractAddress(
1279
- "0xFF9c5Ade32d9B4102469Bd5F3817CB0061b25feC"
1493
+ "0x7014019ed51Edab984a71D30F2707D2dB2316A7A"
1280
1494
  )
1281
1495
  };
1282
1496
  function ondoSwapContractAddress(chain) {
@@ -1475,18 +1689,25 @@ function sizeParam(params) {
1475
1689
  var OndoNamespaceImpl = class {
1476
1690
  constructor(ctx) {
1477
1691
  this.ctx = ctx;
1692
+ this.log = internalLogger(ctx.logger, "ONDO");
1478
1693
  }
1479
1694
  async getTradingStatus(params) {
1480
- await this.ctx.ensureUserAuthenticated();
1481
- return getOndoTradingStatus(this.ctx.api, params);
1695
+ return this.log.wrap("getTradingStatus", params, async () => {
1696
+ await this.ctx.ensureUserAuthenticated();
1697
+ return getOndoTradingStatus(this.ctx.api, params);
1698
+ });
1482
1699
  }
1483
1700
  async getQuote(params) {
1484
- await this.ctx.ensureUserAuthenticated();
1485
- return getOndoQuote(this.ctx.api, params);
1701
+ return this.log.wrap("getQuote", params, async () => {
1702
+ await this.ctx.ensureUserAuthenticated();
1703
+ return getOndoQuote(this.ctx.api, params);
1704
+ });
1486
1705
  }
1487
1706
  async buildSwapTransaction(params) {
1488
- await this.ctx.ensureUserAuthenticated();
1489
- return buildOndoSwapTransaction(this.ctx.api, params);
1707
+ return this.log.wrap("buildSwapTransaction", params, async () => {
1708
+ await this.ctx.ensureUserAuthenticated();
1709
+ return buildOndoSwapTransaction(this.ctx.api, params);
1710
+ });
1490
1711
  }
1491
1712
  };
1492
1713
 
@@ -1800,26 +2021,37 @@ function formattedPricePerShare(quote, locale) {
1800
2021
  var SuperstateSwapNamespaceImpl = class {
1801
2022
  constructor(ctx) {
1802
2023
  this.ctx = ctx;
2024
+ this.log = internalLogger(ctx.logger, "SUPERSTATE");
1803
2025
  }
1804
2026
  async getAuthorization(params) {
1805
- await this.ctx.ensureUserAuthenticated();
1806
- return getSwapAuthorization(this.ctx.api, params);
2027
+ return this.log.wrap("getAuthorization", params, async () => {
2028
+ await this.ctx.ensureUserAuthenticated();
2029
+ return getSwapAuthorization(this.ctx.api, params);
2030
+ });
1807
2031
  }
1808
2032
  async getPreview(params) {
1809
- await this.ctx.ensureUserAuthenticated();
1810
- return getSwapPreview(this.ctx.api, params);
2033
+ return this.log.wrap("getPreview", params, async () => {
2034
+ await this.ctx.ensureUserAuthenticated();
2035
+ return getSwapPreview(this.ctx.api, params);
2036
+ });
1811
2037
  }
1812
2038
  async getStatus(params) {
1813
- await this.ctx.ensureUserAuthenticated();
1814
- return getSwapStatus(this.ctx.api, params);
2039
+ return this.log.wrap("getStatus", params, async () => {
2040
+ await this.ctx.ensureUserAuthenticated();
2041
+ return getSwapStatus(this.ctx.api, params);
2042
+ });
1815
2043
  }
1816
2044
  async getOutputToken(params) {
1817
- await this.ctx.ensureUserAuthenticated();
1818
- return getSwapOutputToken(this.ctx.api, params);
2045
+ return this.log.wrap("getOutputToken", params, async () => {
2046
+ await this.ctx.ensureUserAuthenticated();
2047
+ return getSwapOutputToken(this.ctx.api, params);
2048
+ });
1819
2049
  }
1820
2050
  async allowWallet(params) {
1821
- await this.ctx.ensureUserAuthenticated();
1822
- return allowWallet(this.ctx.api, params);
2051
+ return this.log.wrap("allowWallet", params, async () => {
2052
+ await this.ctx.ensureUserAuthenticated();
2053
+ return allowWallet(this.ctx.api, params);
2054
+ });
1823
2055
  }
1824
2056
  };
1825
2057
 
@@ -1856,18 +2088,25 @@ async function fetchOfferDetails(api, id, clientCreds) {
1856
2088
  var OffersNamespaceImpl = class {
1857
2089
  constructor(ctx) {
1858
2090
  this.ctx = ctx;
2091
+ this.log = internalLogger(ctx.logger, "OFFERS");
1859
2092
  }
1860
2093
  async list() {
1861
- await this.ctx.ensureUserAuthenticated();
1862
- return fetchOffers(this.ctx.api, void 0);
2094
+ return this.log.wrap("list", void 0, async () => {
2095
+ await this.ctx.ensureUserAuthenticated();
2096
+ return fetchOffers(this.ctx.api, void 0);
2097
+ });
1863
2098
  }
1864
2099
  async listPage(params) {
1865
- await this.ctx.ensureUserAuthenticated();
1866
- return fetchOffersPage(this.ctx.api, params, void 0);
2100
+ return this.log.wrap("listPage", params, async () => {
2101
+ await this.ctx.ensureUserAuthenticated();
2102
+ return fetchOffersPage(this.ctx.api, params, void 0);
2103
+ });
1867
2104
  }
1868
2105
  async get(id) {
1869
- await this.ctx.ensureUserAuthenticated();
1870
- return fetchOfferDetails(this.ctx.api, id, void 0);
2106
+ return this.log.wrap("get", id, async () => {
2107
+ await this.ctx.ensureUserAuthenticated();
2108
+ return fetchOfferDetails(this.ctx.api, id, void 0);
2109
+ });
1871
2110
  }
1872
2111
  };
1873
2112
 
@@ -2000,38 +2239,49 @@ async function fetchRequirementStatuses(api, offerId) {
2000
2239
  var RequirementsNamespaceImpl = class {
2001
2240
  constructor(ctx) {
2002
2241
  this.ctx = ctx;
2242
+ this.log = internalLogger(ctx.logger, "REQUIREMENTS");
2003
2243
  }
2004
2244
  async forOffer(offerId) {
2005
- await this.ctx.ensureUserAuthenticated();
2006
- return fetchOfferRequirements(
2007
- this.ctx.api,
2008
- offerId,
2009
- void 0
2010
- );
2245
+ return this.log.wrap("forOffer", offerId, async () => {
2246
+ await this.ctx.ensureUserAuthenticated();
2247
+ return fetchOfferRequirements(
2248
+ this.ctx.api,
2249
+ offerId,
2250
+ void 0
2251
+ );
2252
+ });
2011
2253
  }
2012
2254
  async statuses(offerId) {
2013
- await this.ctx.ensureUserAuthenticated();
2014
- return fetchRequirementStatuses(this.ctx.api, offerId);
2255
+ return this.log.wrap("statuses", offerId, async () => {
2256
+ await this.ctx.ensureUserAuthenticated();
2257
+ return fetchRequirementStatuses(this.ctx.api, offerId);
2258
+ });
2015
2259
  }
2016
2260
  async createKycToken(params) {
2017
- await this.ctx.ensureUserAuthenticated();
2018
- return createKycToken(
2019
- this.ctx.api,
2020
- params?.levelName,
2021
- params?.reset
2022
- );
2261
+ return this.log.wrap("createKycToken", params, async () => {
2262
+ await this.ctx.ensureUserAuthenticated();
2263
+ return createKycToken(
2264
+ this.ctx.api,
2265
+ params?.levelName,
2266
+ params?.reset
2267
+ );
2268
+ });
2023
2269
  }
2024
2270
  async getPii() {
2025
- await this.ctx.ensureUserAuthenticated();
2026
- return fetchPii(this.ctx.api);
2271
+ return this.log.wrap("getPii", void 0, async () => {
2272
+ await this.ctx.ensureUserAuthenticated();
2273
+ return fetchPii(this.ctx.api);
2274
+ });
2027
2275
  }
2028
2276
  async submitDocument(params) {
2029
- await this.ctx.ensureUserAuthenticated();
2030
- return submitDocument(
2031
- this.ctx.api,
2032
- params.documentType,
2033
- params.fields
2034
- );
2277
+ return this.log.wrap("submitDocument", params, async () => {
2278
+ await this.ctx.ensureUserAuthenticated();
2279
+ return submitDocument(
2280
+ this.ctx.api,
2281
+ params.documentType,
2282
+ params.fields
2283
+ );
2284
+ });
2035
2285
  }
2036
2286
  };
2037
2287
 
@@ -2043,9 +2293,11 @@ var HEADER_API_VERSION = "X-API-Version";
2043
2293
 
2044
2294
  // src/shared/api/http-client.ts
2045
2295
  var HttpClient = class {
2046
- constructor(config, middleware = {}) {
2296
+ constructor(config, middleware = {}, logger = null, options = {}) {
2047
2297
  this.config = config;
2048
2298
  this.middleware = middleware;
2299
+ this.log = internalLogger(logger, "HTTP");
2300
+ this.makeRequestId = options.makeRequestId ?? defaultMakeRequestId;
2049
2301
  }
2050
2302
  async send(request) {
2051
2303
  return this.runRequestWithAfterMiddleware(request);
@@ -2081,7 +2333,13 @@ var HttpClient = class {
2081
2333
  return {
2082
2334
  ...request,
2083
2335
  url,
2084
- headers
2336
+ headers,
2337
+ // Only when absent: a retry or a post-renewal re-send arrives with the
2338
+ // first attempt's id already on it, and keeping it is the whole point.
2339
+ attributes: Attributes.getRequestId(request.attributes) === null ? Attributes.concat(
2340
+ request.attributes ?? Attributes.empty,
2341
+ Attributes.requestId(this.makeRequestId())
2342
+ ) : request.attributes
2085
2343
  };
2086
2344
  }
2087
2345
  /**
@@ -2105,10 +2363,89 @@ var HttpClient = class {
2105
2363
  }
2106
2364
  return request;
2107
2365
  }
2108
- executeRequest(request) {
2109
- return makeRequest(request);
2366
+ /**
2367
+ * One physical attempt, logged as one line.
2368
+ *
2369
+ * A non-2xx is a `warn` rather than an `error` because the wire does not
2370
+ * know whether it is a failure: the retry middleware may turn a 503 into a
2371
+ * success, and the token registry reads a 404 as "not listed". The namespace
2372
+ * above decides, and logs the `error` when it does.
2373
+ */
2374
+ async executeRequest(request) {
2375
+ const requestId2 = Attributes.getRequestId(request.attributes);
2376
+ const log = requestId2 === null ? this.log : this.log.child({ requestId: requestId2 });
2377
+ const attempt = Attributes.getRetryAttempt(request.attributes) + 1;
2378
+ const startedAt = Date.now();
2379
+ log.debug(() => ({
2380
+ msg: "request sent",
2381
+ fields: describeRequestUnredacted(request)
2382
+ }));
2383
+ try {
2384
+ const response = await makeRequest(request);
2385
+ const elapsed = Date.now() - startedAt;
2386
+ const outcome = () => ({
2387
+ msg: "request completed",
2388
+ fields: {
2389
+ ...identifyRequest(request),
2390
+ "http.response.status_code": response.status,
2391
+ duration_ms: elapsed,
2392
+ attempt
2393
+ }
2394
+ });
2395
+ if (response.status >= 200 && response.status < 300) {
2396
+ log.info(outcome);
2397
+ } else {
2398
+ log.warn(outcome);
2399
+ }
2400
+ log.debug(() => ({
2401
+ msg: "response received",
2402
+ fields: { body: response.body }
2403
+ }));
2404
+ return requestId2 === null ? response : { ...response, requestId: requestId2 };
2405
+ } catch (error) {
2406
+ const elapsed = Date.now() - startedAt;
2407
+ log.warning(
2408
+ () => ({
2409
+ msg: "request threw",
2410
+ fields: {
2411
+ ...identifyRequest(request),
2412
+ duration_ms: elapsed,
2413
+ attempt
2414
+ }
2415
+ }),
2416
+ error
2417
+ );
2418
+ throw error;
2419
+ }
2110
2420
  }
2111
2421
  };
2422
+ function identifyRequest(request) {
2423
+ const { host, path } = splitUrl(request.url);
2424
+ return {
2425
+ "http.request.method": request.method,
2426
+ "server.address": host,
2427
+ "url.path": path
2428
+ };
2429
+ }
2430
+ function splitUrl(url) {
2431
+ try {
2432
+ const parsed = new URL(url);
2433
+ return { host: parsed.host, path: parsed.pathname };
2434
+ } catch (_) {
2435
+ return { host: null, path: url };
2436
+ }
2437
+ }
2438
+ function defaultMakeRequestId() {
2439
+ return Math.random().toString(36).slice(2, 10).padEnd(8, "0");
2440
+ }
2441
+ function describeRequestUnredacted(request) {
2442
+ return {
2443
+ "http.request.method": request.method,
2444
+ "url.full": buildUrlWithQueryParams(request.url, request.queryParams),
2445
+ headers: request.headers,
2446
+ ...request.method === "POST" ? { body: request.body } : {}
2447
+ };
2448
+ }
2112
2449
 
2113
2450
  // src/shared/types/token-metadata.ts
2114
2451
  var TokenLogoUrl = (value) => value;
@@ -2174,8 +2511,8 @@ var resolveLogoUrl = (url, baseUrl) => TokenLogoUrl(
2174
2511
  );
2175
2512
 
2176
2513
  // src/shared/api/nabu/tokens.ts
2177
- function createNabuApiClient(baseUrl) {
2178
- return new HttpClient({ baseUrl });
2514
+ function createNabuApiClient(baseUrl, logger = null) {
2515
+ return new HttpClient({ baseUrl }, {}, logger);
2179
2516
  }
2180
2517
  async function fetchTokenMetadata(client, token) {
2181
2518
  const address = checksummed(token.address);
@@ -2248,14 +2585,23 @@ var TokensNamespaceImpl = class {
2248
2585
  * registry is unauthenticated and on its own host, so the frontline sender
2249
2586
  * and the auth check would both be dead weight here.
2250
2587
  */
2251
- constructor(baseUrl) {
2252
- this.api = createNabuApiClient(baseUrl);
2588
+ constructor(baseUrl, logger = null) {
2589
+ this.api = createNabuApiClient(baseUrl, logger);
2590
+ this.log = internalLogger(logger, "TOKENS");
2253
2591
  }
2254
2592
  get(token) {
2255
- return fetchTokenMetadata(this.api, token);
2593
+ return this.log.wrap(
2594
+ "get",
2595
+ token,
2596
+ () => fetchTokenMetadata(this.api, token)
2597
+ );
2256
2598
  }
2257
2599
  list(chain) {
2258
- return fetchTokensMetadata(this.api, chain);
2600
+ return this.log.wrap(
2601
+ "list",
2602
+ chain,
2603
+ () => fetchTokensMetadata(this.api, chain)
2604
+ );
2259
2605
  }
2260
2606
  };
2261
2607
 
@@ -2361,36 +2707,50 @@ async function removeOptionAddress(api, offerId, addressId) {
2361
2707
  var WalletsNamespaceImpl = class {
2362
2708
  constructor(ctx) {
2363
2709
  this.ctx = ctx;
2710
+ this.log = internalLogger(ctx.logger, "WALLETS");
2364
2711
  }
2365
2712
  async createOwnershipChallenge(params) {
2366
- await this.ctx.ensureUserAuthenticated();
2367
- return createWalletOwnershipChallenge(
2368
- this.ctx.api,
2369
- params
2370
- );
2713
+ return this.log.wrap("createOwnershipChallenge", params, async () => {
2714
+ await this.ctx.ensureUserAuthenticated();
2715
+ return createWalletOwnershipChallenge(
2716
+ this.ctx.api,
2717
+ params
2718
+ );
2719
+ });
2371
2720
  }
2372
2721
  async connectExternal(params) {
2373
- await this.ctx.ensureUserAuthenticated();
2374
- return connectExternalWallet(this.ctx.api, params);
2722
+ return this.log.wrap("connectExternal", params, async () => {
2723
+ await this.ctx.ensureUserAuthenticated();
2724
+ return connectExternalWallet(this.ctx.api, params);
2725
+ });
2375
2726
  }
2376
2727
  async list(params) {
2377
- await this.ctx.ensureUserAuthenticated();
2378
- return listOptionAddresses(
2379
- this.ctx.api,
2380
- params.offerId,
2381
- params.offerOptionId
2382
- );
2728
+ return this.log.wrap("list", params, async () => {
2729
+ await this.ctx.ensureUserAuthenticated();
2730
+ return listOptionAddresses(
2731
+ this.ctx.api,
2732
+ params.offerId,
2733
+ params.offerOptionId
2734
+ );
2735
+ });
2383
2736
  }
2384
2737
  async remove(params) {
2385
- await this.ctx.ensureUserAuthenticated();
2386
- return removeOptionAddress(
2387
- this.ctx.api,
2388
- params.offerId,
2389
- params.addressId
2390
- );
2738
+ return this.log.wrap("remove", params, async () => {
2739
+ await this.ctx.ensureUserAuthenticated();
2740
+ return removeOptionAddress(
2741
+ this.ctx.api,
2742
+ params.offerId,
2743
+ params.addressId
2744
+ );
2745
+ });
2391
2746
  }
2392
2747
  };
2393
2748
 
2749
+ // src/shared/types/blockchain/wallet-error.ts
2750
+ var RedactedWalletError = {
2751
+ fromWalletError: (error) => error.type === "unknown" ? { type: "unknown" } : error
2752
+ };
2753
+
2394
2754
  // src/shared/types/oauth-session.ts
2395
2755
  var ClientCredentialsOAuth = (value) => value;
2396
2756
  var OAuthRefreshToken = (value) => value;
@@ -2458,6 +2818,7 @@ var User = {
2458
2818
  FormattedPercentUi,
2459
2819
  HexEncodedTransactionData,
2460
2820
  HttpError,
2821
+ InvariantError,
2461
2822
  Iso2CountryCode,
2462
2823
  KnownAssetSymbol,
2463
2824
  KycToken,
@@ -2497,6 +2858,7 @@ var User = {
2497
2858
  Pii,
2498
2859
  PiiAddress,
2499
2860
  PiiJurisdiction,
2861
+ RedactedWalletError,
2500
2862
  RedirectUri,
2501
2863
  Requirement,
2502
2864
  RequirementId,
@@ -2562,6 +2924,7 @@ var User = {
2562
2924
  isStopped,
2563
2925
  ondoSwapContractAddress,
2564
2926
  parseBlockchainAmount,
2927
+ parseUint256,
2565
2928
  shortenAddress,
2566
2929
  superstateSwapContractAddress,
2567
2930
  txExplorerUrl,