@coinlist-co/react 0.6.0 → 0.10.0

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/{chunk-5C4TEVM7.js → chunk-7BJ2HAG7.js} +62 -92
  2. package/dist/chunk-7BJ2HAG7.js.map +1 -0
  3. package/dist/{chunk-5E3P7AMH.js → chunk-AAER5LOL.js} +3 -1
  4. package/dist/chunk-AAER5LOL.js.map +1 -0
  5. package/dist/chunk-GSSAB4K5.js +644 -0
  6. package/dist/chunk-GSSAB4K5.js.map +1 -0
  7. package/dist/chunk-TUZKKFNW.js +836 -0
  8. package/dist/chunk-TUZKKFNW.js.map +1 -0
  9. package/dist/client/index.cjs +3203 -412
  10. package/dist/client/index.cjs.map +1 -1
  11. package/dist/client/index.d.cts +996 -41
  12. package/dist/client/index.d.ts +996 -41
  13. package/dist/client/index.js +2069 -208
  14. package/dist/client/index.js.map +1 -1
  15. package/dist/collections-CJ24dOda.d.cts +28 -0
  16. package/dist/collections-ZYLKp8JB.d.ts +28 -0
  17. package/dist/requirement-CDi5NJI8.d.cts +1036 -0
  18. package/dist/requirement-CDi5NJI8.d.ts +1036 -0
  19. package/dist/server/index.cjs +588 -85
  20. package/dist/server/index.cjs.map +1 -1
  21. package/dist/server/index.d.cts +117 -17
  22. package/dist/server/index.d.ts +117 -17
  23. package/dist/server/index.js +92 -40
  24. package/dist/server/index.js.map +1 -1
  25. package/dist/shared/index.cjs +1334 -91
  26. package/dist/shared/index.cjs.map +1 -1
  27. package/dist/shared/index.d.cts +624 -3
  28. package/dist/shared/index.d.ts +624 -3
  29. package/dist/shared/index.js +220 -5
  30. package/dist/shared/index.js.map +1 -1
  31. package/package.json +7 -3
  32. package/dist/chunk-5C4TEVM7.js.map +0 -1
  33. package/dist/chunk-5E3P7AMH.js.map +0 -1
  34. package/dist/chunk-7SB2GKEU.js +0 -311
  35. package/dist/chunk-7SB2GKEU.js.map +0 -1
  36. package/dist/chunk-UEJVCU2J.js +0 -43
  37. package/dist/chunk-UEJVCU2J.js.map +0 -1
  38. package/dist/requirement-Dk6nYN1c.d.cts +0 -389
  39. package/dist/requirement-Dk6nYN1c.d.ts +0 -389
@@ -43,6 +43,9 @@ var userAgent = () => ({ userAgent: true });
43
43
  var idempotencyKey = () => ({
44
44
  idempotencyKey: true
45
45
  });
46
+ var clientCredentials = (credentials) => ({
47
+ clientCredentials: credentials
48
+ });
46
49
  var retryAttempt = (attempt) => ({
47
50
  retryAttempt: attempt
48
51
  });
@@ -54,6 +57,7 @@ var needUserAgent = (attrs) => attrs?.userAgent === true;
54
57
  var isIdempotent = (attrs) => attrs?.idempotencyKey === true;
55
58
  var getRetryAttempt = (attrs) => attrs?.retryAttempt ?? 0;
56
59
  var wasRenewAttempted = (attrs) => attrs?.renewAttempted === true;
60
+ var getClientCredentials = (attrs) => attrs?.clientCredentials;
57
61
  var Attributes = {
58
62
  empty,
59
63
  concat,
@@ -67,7 +71,9 @@ var Attributes = {
67
71
  retryAttempt,
68
72
  getRetryAttempt,
69
73
  renewAttempted,
70
- wasRenewAttempted
74
+ wasRenewAttempted,
75
+ clientCredentials,
76
+ getClientCredentials
71
77
  };
72
78
 
73
79
  // src/shared/api/http.ts
@@ -249,7 +255,13 @@ function attachSessionMiddleware(fetchAccessToken) {
249
255
  if (!Attributes.isProtected(request.attributes)) {
250
256
  return request;
251
257
  }
252
- const accessToken = await fetchAccessToken(false);
258
+ let accessToken = await fetchAccessToken(false);
259
+ if (!accessToken) {
260
+ const clientCreds = Attributes.getClientCredentials(request.attributes);
261
+ if (clientCreds) {
262
+ accessToken = clientCreds;
263
+ }
264
+ }
253
265
  if (accessToken === null) {
254
266
  return request;
255
267
  }
@@ -407,6 +419,46 @@ var WritableSessionStoreRequiredError = class extends Error {
407
419
  }
408
420
  };
409
421
 
422
+ // src/shared/types/document-submission.ts
423
+ var DocumentSubmission = {
424
+ fromDto: (dto) => ({
425
+ status: dto.status,
426
+ formType: dto.form_type
427
+ })
428
+ };
429
+
430
+ // src/shared/api/frontline/documents.ts
431
+ async function submitDocument(api, documentType, fields) {
432
+ const dto = await api.send({
433
+ method: "POST",
434
+ url: `/v1/documents/${documentType}/submission`,
435
+ body: fields,
436
+ attributes: Attributes.protected()
437
+ });
438
+ return DocumentSubmission.fromDto(dto);
439
+ }
440
+
441
+ // src/shared/types/kyc.ts
442
+ var KycToken = {
443
+ fromDto: (dto) => ({
444
+ token: dto.token
445
+ })
446
+ };
447
+
448
+ // src/shared/api/frontline/kyc.ts
449
+ async function createKycToken(api, levelName, reset) {
450
+ const dto = await api.send({
451
+ method: "POST",
452
+ url: "/v1/kyc-token",
453
+ body: {
454
+ ...levelName === void 0 ? {} : { level_name: levelName },
455
+ ...reset === void 0 ? {} : { reset }
456
+ },
457
+ attributes: Attributes.protected()
458
+ });
459
+ return KycToken.fromDto(dto);
460
+ }
461
+
410
462
  // src/shared/api/pagination.ts
411
463
  var Cursor = (value) => value;
412
464
  async function fetchAllPages(fetchPage, baseParams) {
@@ -453,11 +505,12 @@ var Offer = {
453
505
  fromDto: (dto) => ({
454
506
  id: OfferId(dto.id),
455
507
  slug: OfferSlug(dto.slug),
456
- tagline: notBlankStringOrNull(dto.tagline),
457
- bannerUrl: notBlankStringOrNull(dto.banner_url),
458
- logoUrl: notBlankStringOrNull(dto.logo_url),
508
+ type: dto.type,
509
+ tagline: dto.tagline,
510
+ bannerUrl: dto.banner_url,
511
+ logoUrl: dto.logo_url,
459
512
  startsAt: new Date(dto.starts_at),
460
- endsAt: new Date(dto.ends_at)
513
+ endsAt: dto.ends_at ? new Date(dto.ends_at) : null
461
514
  })
462
515
  };
463
516
 
@@ -499,16 +552,17 @@ var OfferDetail = {
499
552
  return {
500
553
  id: OfferId(dto.id),
501
554
  slug: OfferSlug(dto.slug),
555
+ type: dto.type,
502
556
  name: dto.name,
503
557
  asset: Asset.fromDto(dto.asset),
504
558
  fundingAssets: dto.funding_assets.map(Asset.fromDto),
505
559
  about: notBlankStringOrNull(dto.about),
506
- tagline: notBlankStringOrNull(dto.tagline),
507
- bannerUrl: notBlankStringOrNull(dto.banner_url),
508
- logoUrl: notBlankStringOrNull(dto.logo_url),
509
- category: notBlankStringOrNull(dto.category),
560
+ tagline: dto.tagline,
561
+ bannerUrl: dto.banner_url,
562
+ logoUrl: dto.logo_url,
563
+ category: dto.category,
510
564
  startsAt: new Date(dto.starts_at),
511
- endsAt: new Date(dto.ends_at),
565
+ endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
512
566
  faqs: dto.faqs.map(FaqItem.fromDto),
513
567
  links: dto.links.map(Link.fromDto),
514
568
  milestones: dto.milestones.map(Milestone.fromDto),
@@ -556,28 +610,447 @@ var Milestone = {
556
610
  };
557
611
 
558
612
  // src/shared/api/frontline/offers.ts
559
- async function fetchOffers(api) {
560
- return fetchAllPages((params) => fetchOffersPage(api, params));
613
+ async function fetchOffers(api, clientCreds) {
614
+ return fetchAllPages((params) => fetchOffersPage(api, params, clientCreds));
561
615
  }
562
- async function fetchOffersPage(api, params) {
616
+ async function fetchOffersPage(api, params, clientCreds) {
563
617
  const queryParams = PaginationParams.toQueryParams(params);
564
618
  const pageDto = await api.send({
565
619
  method: "GET",
566
620
  url: "/v1/offers",
567
621
  queryParams,
568
- attributes: Attributes.protected()
622
+ attributes: Attributes.concat(
623
+ Attributes.protected(),
624
+ Attributes.clientCredentials(clientCreds)
625
+ )
569
626
  });
570
627
  return PaginatedResponse.fromDto(pageDto, Offer.fromDto);
571
628
  }
572
- async function fetchOfferDetails(api, id) {
629
+ async function fetchOfferDetails(api, id, clientCreds) {
573
630
  const dto = await api.send({
574
631
  method: "GET",
575
632
  url: `/v1/offers/${id}`,
576
- attributes: Attributes.protected()
633
+ attributes: Attributes.concat(
634
+ Attributes.protected(),
635
+ Attributes.clientCredentials(clientCreds)
636
+ )
577
637
  });
578
638
  return OfferDetail.fromDto(dto);
579
639
  }
580
640
 
641
+ // src/shared/types/pii.ts
642
+ var Iso2CountryCode = (value) => value;
643
+ var PiiJurisdiction = {
644
+ fromDto: (dto) => ({
645
+ iso2: Iso2CountryCode(dto.iso_2),
646
+ name: dto.name
647
+ })
648
+ };
649
+ var PiiAddress = {
650
+ fromDto: (dto) => ({
651
+ street: dto.street,
652
+ city: dto.city,
653
+ state: dto.state,
654
+ postalCode: dto.postal_code,
655
+ country: dto.country
656
+ })
657
+ };
658
+ var Pii = {
659
+ fromDto: (dto) => ({
660
+ kind: dto.kind,
661
+ fullLegalName: dto.full_legal_name,
662
+ dateOfBirth: dto.date_of_birth,
663
+ jurisdiction: dto.jurisdiction ? PiiJurisdiction.fromDto(dto.jurisdiction) : null,
664
+ taxId: dto.tax_id,
665
+ permanentAddress: PiiAddress.fromDto(dto.permanent_address)
666
+ })
667
+ };
668
+
669
+ // src/shared/api/frontline/pii.ts
670
+ async function fetchPii(api) {
671
+ const dto = await api.send({
672
+ method: "GET",
673
+ url: "/v1/pii",
674
+ attributes: Attributes.protected()
675
+ });
676
+ return Pii.fromDto(dto);
677
+ }
678
+
679
+ // src/shared/types/requirement.ts
680
+ var RequirementId = (value) => value;
681
+ var Requirement = {
682
+ fromDto: (dto) => ({
683
+ id: RequirementId(dto.id),
684
+ type: dto.type,
685
+ details: dto.details
686
+ })
687
+ };
688
+ var RequirementStatusInfo = {
689
+ fromStatusesDto: (dto) => Object.entries(dto.statuses).map(
690
+ ([id, value]) => typeof value === "string" ? { id: RequirementId(id), status: value, action: null } : {
691
+ id: RequirementId(id),
692
+ status: value.status,
693
+ action: value.action ?? null,
694
+ kycLevel: value.kyc_level,
695
+ kycReset: value.kyc_reset
696
+ }
697
+ )
698
+ };
699
+
700
+ // src/shared/api/frontline/requirements.ts
701
+ async function fetchOfferRequirements(api, offerId, clientCreds) {
702
+ const response = await api.send({
703
+ method: "GET",
704
+ url: `/v1/offers/${offerId}/requirements`,
705
+ attributes: Attributes.concat(
706
+ Attributes.protected(),
707
+ Attributes.clientCredentials(clientCreds)
708
+ )
709
+ });
710
+ return Object.fromEntries(
711
+ Object.entries(response.options).map(([optionId, list]) => [
712
+ optionId,
713
+ list.data.map(Requirement.fromDto)
714
+ ])
715
+ );
716
+ }
717
+ async function fetchRequirementStatuses(api, offerId) {
718
+ const response = await api.send({
719
+ method: "GET",
720
+ url: `/v1/offers/${offerId}/requirements/statuses`,
721
+ attributes: Attributes.protected()
722
+ });
723
+ return RequirementStatusInfo.fromStatusesDto(response);
724
+ }
725
+
726
+ // src/shared/types/blockchain/core.ts
727
+ var EvmWalletAddress = (value) => value;
728
+ var EvmContractAddress = (value) => value;
729
+ var HexEncodedTransactionData = (value) => value;
730
+ var AssetDecimals = (value) => value;
731
+ var MAX_UINT_256 = 2n ** 256n - 1n;
732
+ var assertUint256 = (value) => {
733
+ if (value < 0n || value > MAX_UINT_256) {
734
+ throw new Error(`Value out of uint256 bounds: ${value}`);
735
+ }
736
+ return value;
737
+ };
738
+ var BlockchainAmount = Object.assign(
739
+ (value) => value,
740
+ {
741
+ add: (a, b) => combineAmounts(a, b, (x, y) => x + y),
742
+ sub: (a, b) => combineAmounts(a, b, (x, y) => x - y)
743
+ }
744
+ );
745
+ function combineAmounts(a, b, op) {
746
+ if (a.decimals !== b.decimals) {
747
+ throw new Error(
748
+ `Cannot combine BlockchainAmounts with different decimals: ${a.decimals} vs ${b.decimals}`
749
+ );
750
+ }
751
+ const raw = op(a.raw, b.raw);
752
+ if (raw < 0n || raw > MAX_UINT_256) {
753
+ throw new Error(`BlockchainAmount out of uint256 bounds: ${raw}`);
754
+ }
755
+ return BlockchainAmount({ raw, decimals: a.decimals });
756
+ }
757
+ var AssetSymbol = (value) => value;
758
+
759
+ // src/shared/types/offer-option-address.ts
760
+ var OfferOptionAddressId = (value) => value;
761
+ var OfferOptionAddress = {
762
+ /** Maps the API DTO into the SDK offer-option-address domain model. */
763
+ fromDto: (dto) => ({
764
+ id: OfferOptionAddressId(dto.id),
765
+ offerOptionId: OfferOptionId(dto.offer_option_id),
766
+ address: EvmWalletAddress(dto.address),
767
+ protocol: dto.protocol,
768
+ createdAt: new Date(dto.created_at)
769
+ })
770
+ };
771
+ var ConnectExternalWalletParams = {
772
+ /** Maps connect-wallet params into the API DTO payload. */
773
+ toDto: (params) => ({
774
+ offer_option_id: params.offerOptionId,
775
+ wallet_address: params.walletAddress,
776
+ chain: params.chain,
777
+ signature: params.signature
778
+ })
779
+ };
780
+
781
+ // src/shared/types/wallet-ownership-challenge.ts
782
+ var WalletOwnershipChallenge = {
783
+ /** Maps the API DTO into the SDK wallet-ownership-challenge domain model. */
784
+ fromDto: (dto) => ({
785
+ message: dto.message,
786
+ expiresAt: new Date(dto.expires_at)
787
+ })
788
+ };
789
+ var CreateWalletOwnershipChallengeParams = {
790
+ /**
791
+ * Maps challenge-request params into the API DTO payload. The discriminated
792
+ * union guarantees SIWE fields are present exactly when `challengeType` is
793
+ * `siwe`, so the mapping narrows on the discriminant.
794
+ */
795
+ toDto: (params) => {
796
+ switch (params.challengeType) {
797
+ case "plain":
798
+ return {
799
+ wallet_address: params.walletAddress,
800
+ chain: params.chain,
801
+ challenge_type: "plain"
802
+ };
803
+ case "siwe":
804
+ return {
805
+ wallet_address: params.walletAddress,
806
+ chain: params.chain,
807
+ challenge_type: "siwe",
808
+ domain: params.domain,
809
+ uri: params.uri,
810
+ statement: params.statement
811
+ };
812
+ default: {
813
+ const _exhaustive = params;
814
+ return _exhaustive;
815
+ }
816
+ }
817
+ }
818
+ };
819
+
820
+ // src/shared/api/frontline/wallet-connect.ts
821
+ async function createWalletOwnershipChallenge(api, params) {
822
+ const dto = await api.send({
823
+ method: "POST",
824
+ url: "/v1/wallet-ownership",
825
+ body: CreateWalletOwnershipChallengeParams.toDto(params),
826
+ attributes: Attributes.protected()
827
+ });
828
+ return WalletOwnershipChallenge.fromDto(dto);
829
+ }
830
+ async function connectExternalWallet(api, offerId, params) {
831
+ const dto = await api.send({
832
+ method: "POST",
833
+ url: `/v1/offers/${offerId}/addresses`,
834
+ body: ConnectExternalWalletParams.toDto(params),
835
+ attributes: Attributes.protected()
836
+ });
837
+ return OfferOptionAddress.fromDto(dto);
838
+ }
839
+ async function listOptionAddresses(api, offerId, offerOptionId) {
840
+ const { data } = await api.send({
841
+ method: "GET",
842
+ url: `/v1/offers/${offerId}/addresses`,
843
+ queryParams: { offer_option_id: offerOptionId },
844
+ attributes: Attributes.protected()
845
+ });
846
+ return data.map(OfferOptionAddress.fromDto);
847
+ }
848
+ async function removeOptionAddress(api, offerId, addressId) {
849
+ const dto = await api.send({
850
+ method: "DELETE",
851
+ url: `/v1/offers/${offerId}/addresses/${addressId}`,
852
+ attributes: Attributes.protected()
853
+ });
854
+ return OfferOptionAddress.fromDto(dto);
855
+ }
856
+
857
+ // src/shared/types/swap.ts
858
+ var SwapAuthorization = {
859
+ fromDto: (dto) => ({
860
+ authorized: dto.authorized
861
+ })
862
+ };
863
+ var SwapPreview = {
864
+ fromDto: (dto) => ({
865
+ inputAmount: assertUint256(BigInt(dto.pay_input_amount)),
866
+ fee: assertUint256(BigInt(dto.fee)),
867
+ outputAmount: assertUint256(BigInt(dto.receive_output_amount))
868
+ })
869
+ };
870
+ var SwapStatus = {
871
+ fromDto: (dto) => ({
872
+ stopped: assertUint256(BigInt(dto.stopped)),
873
+ swapLevel: assertUint256(BigInt(dto.swap_level))
874
+ })
875
+ };
876
+ var TokenAllowance = {
877
+ fromDto: (dto) => ({
878
+ allowance: assertUint256(BigInt(dto.allowance))
879
+ })
880
+ };
881
+ var TokenBalance = {
882
+ fromDto: (dto) => ({
883
+ balance: assertUint256(BigInt(dto.balance))
884
+ })
885
+ };
886
+ var AllowWalletResponse = {
887
+ fromDto: (dto) => {
888
+ switch (dto.action) {
889
+ case "broadcast_transaction":
890
+ return {
891
+ action: "broadcast_transaction",
892
+ to: EvmContractAddress(dto.to),
893
+ data: HexEncodedTransactionData(dto.data)
894
+ };
895
+ case "none":
896
+ return {
897
+ action: "none",
898
+ alreadyAllowed: dto.already_allowed
899
+ };
900
+ default: {
901
+ const _exhaustive = dto;
902
+ return _exhaustive;
903
+ }
904
+ }
905
+ }
906
+ };
907
+
908
+ // src/shared/api/frontline/swap.ts
909
+ async function getSwapAuthorization(api, params) {
910
+ const dto = await api.send({
911
+ method: "GET",
912
+ url: "/v1/wallet/authorized",
913
+ queryParams: {
914
+ chain: params.chain,
915
+ contract_address: params.contractAddress,
916
+ wallet_address: params.walletAddress
917
+ },
918
+ attributes: Attributes.protected()
919
+ });
920
+ return SwapAuthorization.fromDto(dto);
921
+ }
922
+ async function getSwapOutputToken(api, params) {
923
+ const dto = await api.send({
924
+ method: "GET",
925
+ url: "/v1/swap/output-token",
926
+ queryParams: {
927
+ chain: params.chain,
928
+ contract_address: params.contractAddress
929
+ },
930
+ attributes: Attributes.protected()
931
+ });
932
+ return toErc20Asset(dto);
933
+ }
934
+ async function getSwapPreview(api, params) {
935
+ const dto = await api.send({
936
+ method: "GET",
937
+ url: "/v1/swap/preview",
938
+ queryParams: {
939
+ chain: params.chain,
940
+ contract_address: params.contractAddress,
941
+ input_token: params.inputToken,
942
+ amount: params.amount.toString()
943
+ },
944
+ attributes: Attributes.protected()
945
+ });
946
+ return SwapPreview.fromDto(dto);
947
+ }
948
+ async function getSwapStatus(api, params) {
949
+ const dto = await api.send({
950
+ method: "GET",
951
+ url: "/v1/swap/status",
952
+ queryParams: {
953
+ chain: params.chain,
954
+ contract_address: params.contractAddress
955
+ },
956
+ attributes: Attributes.protected()
957
+ });
958
+ return SwapStatus.fromDto(dto);
959
+ }
960
+ async function getTokenAllowance(api, params) {
961
+ const dto = await api.send({
962
+ method: "GET",
963
+ url: "/v1/token/allowance",
964
+ queryParams: {
965
+ chain: params.chain,
966
+ token_address: params.tokenAddress,
967
+ owner: params.owner,
968
+ spender: params.spender
969
+ },
970
+ attributes: Attributes.protected()
971
+ });
972
+ return TokenAllowance.fromDto(dto);
973
+ }
974
+ async function getTokenBalance(api, params) {
975
+ const dto = await api.send({
976
+ method: "GET",
977
+ url: "/v1/token/balance",
978
+ queryParams: {
979
+ chain: params.chain,
980
+ token_address: params.tokenAddress,
981
+ owner: params.owner
982
+ },
983
+ attributes: Attributes.protected()
984
+ });
985
+ return TokenBalance.fromDto(dto);
986
+ }
987
+ async function allowWallet(api, params) {
988
+ const dto = await api.send({
989
+ method: "POST",
990
+ url: `/v1/offers/${encodeURIComponent(params.offerId)}/allow-wallet`,
991
+ body: {
992
+ wallet_address: params.walletAddress,
993
+ chain: params.chain,
994
+ signature: params.signature
995
+ },
996
+ attributes: Attributes.protected()
997
+ });
998
+ return AllowWalletResponse.fromDto(dto);
999
+ }
1000
+ function toErc20Asset(dto) {
1001
+ return {
1002
+ name: dto.name,
1003
+ symbol: AssetSymbol(dto.symbol),
1004
+ decimals: AssetDecimals(dto.decimals)
1005
+ };
1006
+ }
1007
+
1008
+ // src/shared/core/erc20-namespace.ts
1009
+ var Erc20NamespaceImpl = class {
1010
+ constructor(ctx) {
1011
+ this.ctx = ctx;
1012
+ }
1013
+ async getTokenAllowance(params) {
1014
+ await this.ctx.ensureUserAuthenticated();
1015
+ return getTokenAllowance(this.ctx.api, params);
1016
+ }
1017
+ async getTokenBalance(params) {
1018
+ await this.ctx.ensureUserAuthenticated();
1019
+ return getTokenBalance(this.ctx.api, params);
1020
+ }
1021
+ };
1022
+
1023
+ // src/shared/core/swap-namespace.ts
1024
+ var SwapNamespaceImpl = class {
1025
+ constructor(ctx) {
1026
+ this.ctx = ctx;
1027
+ }
1028
+ async getAuthorization(params) {
1029
+ await this.ctx.ensureUserAuthenticated();
1030
+ return getSwapAuthorization(this.ctx.api, params);
1031
+ }
1032
+ async getPreview(params) {
1033
+ await this.ctx.ensureUserAuthenticated();
1034
+ return getSwapPreview(this.ctx.api, params);
1035
+ }
1036
+ async getStatus(params) {
1037
+ await this.ctx.ensureUserAuthenticated();
1038
+ return getSwapStatus(this.ctx.api, params);
1039
+ }
1040
+ async getOutputToken(params) {
1041
+ await this.ctx.ensureUserAuthenticated();
1042
+ return getSwapOutputToken(this.ctx.api, params);
1043
+ }
1044
+ async requestWalletOwnershipChallenge(params) {
1045
+ await this.ctx.ensureUserAuthenticated();
1046
+ return createWalletOwnershipChallenge(this.ctx.api, params);
1047
+ }
1048
+ async allowWallet(params) {
1049
+ await this.ctx.ensureUserAuthenticated();
1050
+ return allowWallet(this.ctx.api, params);
1051
+ }
1052
+ };
1053
+
581
1054
  // src/shared/types/participation.ts
582
1055
  var ParticipationId = (value) => value;
583
1056
  var Blockchain = (value) => value;
@@ -659,45 +1132,29 @@ async function createParticipation(api, params) {
659
1132
  return Participation.fromDto(dto);
660
1133
  }
661
1134
 
662
- // src/shared/types/requirement.ts
663
- var RequirementId = (value) => value;
664
- var Requirement = {
665
- fromDto: (dto) => ({
666
- id: RequirementId(dto.id),
667
- type: dto.type,
668
- details: dto.details
669
- })
670
- };
671
- var RequirementStatusInfo = {
672
- fromStatusesDto: (dto) => Object.entries(dto.statuses).map(([id, status]) => ({
673
- id: RequirementId(id),
674
- status
675
- }))
1135
+ // src/shared/core/token-sale-namespace.ts
1136
+ var TokenSaleNamespaceImpl = class {
1137
+ constructor(ctx) {
1138
+ this.ctx = ctx;
1139
+ }
1140
+ async fetchParticipations(offerId) {
1141
+ await this.ctx.ensureUserAuthenticated();
1142
+ return fetchParticipations(this.ctx.api, offerId);
1143
+ }
1144
+ async fetchParticipationsPage(params) {
1145
+ await this.ctx.ensureUserAuthenticated();
1146
+ return fetchParticipationsPage(this.ctx.api, params);
1147
+ }
1148
+ async fetchParticipation(id) {
1149
+ await this.ctx.ensureUserAuthenticated();
1150
+ return fetchParticipation(this.ctx.api, id);
1151
+ }
1152
+ async createParticipation(params) {
1153
+ await this.ctx.ensureUserAuthenticated();
1154
+ return createParticipation(this.ctx.api, params);
1155
+ }
676
1156
  };
677
1157
 
678
- // src/shared/api/frontline/requirements.ts
679
- async function fetchOfferRequirements(api, offerId) {
680
- const response = await api.send({
681
- method: "GET",
682
- url: `/v1/offers/${offerId}/requirements`,
683
- attributes: Attributes.protected()
684
- });
685
- return Object.fromEntries(
686
- Object.entries(response.options).map(([optionId, list]) => [
687
- optionId,
688
- list.data.map(Requirement.fromDto)
689
- ])
690
- );
691
- }
692
- async function fetchRequirementStatuses(api, offerId) {
693
- const response = await api.send({
694
- method: "GET",
695
- url: `/v1/offers/${offerId}/requirements/statuses`,
696
- attributes: Attributes.protected()
697
- });
698
- return RequirementStatusInfo.fromStatusesDto(response);
699
- }
700
-
701
1158
  // src/shared/types/errors.ts
702
1159
  var NotAuthenticatedError = class extends Error {
703
1160
  constructor(message = "The user is not authenticated. Go through the OAuth flow first!") {
@@ -707,6 +1164,7 @@ var NotAuthenticatedError = class extends Error {
707
1164
  };
708
1165
 
709
1166
  // src/shared/types/oauth-session.ts
1167
+ var ClientCredentialsOAuth = (value) => value;
710
1168
  var OAuthRefreshToken = (value) => value;
711
1169
  var OAuthSession = {
712
1170
  fromDto: (dto) => {
@@ -740,6 +1198,13 @@ var CoinListServerImpl = class {
740
1198
  // than re-sending with the same expired token and wasting a round-trip.
741
1199
  (refresh) => refresh && !this._config.sessionStore.setSession ? Promise.resolve(null) : this.accessToken()
742
1200
  );
1201
+ const ctx = {
1202
+ api: this.api,
1203
+ ensureUserAuthenticated: () => this.ensureUserAuthenticated()
1204
+ };
1205
+ this.erc20 = new Erc20NamespaceImpl(ctx);
1206
+ this.tokenSale = new TokenSaleNamespaceImpl(ctx);
1207
+ this.swap = new SwapNamespaceImpl(ctx);
743
1208
  }
744
1209
  async completeOAuth(code, codeVerifier) {
745
1210
  const sessionStore = this._config.sessionStore;
@@ -763,6 +1228,19 @@ var CoinListServerImpl = class {
763
1228
  await setSession(session);
764
1229
  return session;
765
1230
  }
1231
+ async clientCredentialsOAuth() {
1232
+ const sessionDto = await this.api.send({
1233
+ method: "POST",
1234
+ url: `/oauth/token`,
1235
+ body: {
1236
+ grant_type: "client_credentials",
1237
+ client_id: this._config.clientId,
1238
+ client_secret: this._config.clientSecret
1239
+ }
1240
+ });
1241
+ const session = OAuthSession.fromDto(sessionDto);
1242
+ return ClientCredentialsOAuth(session.accessToken);
1243
+ }
766
1244
  async accessToken() {
767
1245
  const sessionStore = this._config.sessionStore;
768
1246
  const session = await sessionStore.getSession();
@@ -835,48 +1313,73 @@ var CoinListServerImpl = class {
835
1313
  await setSession(null);
836
1314
  }
837
1315
  }
838
- async ensureAuthenticated() {
839
- const token = await this.accessToken();
840
- if (token === null) {
841
- throw new NotAuthenticatedError();
842
- }
1316
+ async fetchOffers(clientCreds) {
1317
+ await this.ensureAuthenticated(clientCreds);
1318
+ return fetchOffers(this.api, clientCreds);
843
1319
  }
844
- async fetchOffers() {
845
- await this.ensureAuthenticated();
846
- return fetchOffers(this.api);
1320
+ async fetchOffersPage(params, clientCreds) {
1321
+ await this.ensureAuthenticated(clientCreds);
1322
+ return fetchOffersPage(this.api, params, clientCreds);
847
1323
  }
848
- async fetchOffersPage(params) {
849
- await this.ensureAuthenticated();
850
- return fetchOffersPage(this.api, params);
1324
+ async fetchOfferDetails(id, clientCreds) {
1325
+ await this.ensureAuthenticated(clientCreds);
1326
+ return fetchOfferDetails(this.api, id, clientCreds);
851
1327
  }
852
- async fetchOfferDetails(id) {
853
- await this.ensureAuthenticated();
854
- return fetchOfferDetails(this.api, id);
1328
+ async createWalletOwnershipChallenge(params) {
1329
+ await this.ensureUserAuthenticated();
1330
+ return createWalletOwnershipChallenge(this.api, params);
855
1331
  }
856
- async fetchParticipations(offerId) {
857
- await this.ensureAuthenticated();
858
- return fetchParticipations(this.api, offerId);
1332
+ async connectExternalWallet(offerId, params) {
1333
+ await this.ensureUserAuthenticated();
1334
+ return connectExternalWallet(this.api, offerId, params);
859
1335
  }
860
- async fetchParticipationsPage(params) {
861
- await this.ensureAuthenticated();
862
- return fetchParticipationsPage(this.api, params);
863
- }
864
- async fetchParticipation(id) {
865
- await this.ensureAuthenticated();
866
- return fetchParticipation(this.api, id);
1336
+ async listOptionAddresses(offerId, offerOptionId) {
1337
+ await this.ensureUserAuthenticated();
1338
+ return listOptionAddresses(
1339
+ this.api,
1340
+ offerId,
1341
+ offerOptionId
1342
+ );
867
1343
  }
868
- async createParticipation(params) {
869
- await this.ensureAuthenticated();
870
- return createParticipation(this.api, params);
1344
+ async removeOptionAddress(offerId, addressId) {
1345
+ await this.ensureUserAuthenticated();
1346
+ return removeOptionAddress(this.api, offerId, addressId);
871
1347
  }
872
- async fetchOfferRequirements(offerId) {
873
- await this.ensureAuthenticated();
874
- return fetchOfferRequirements(this.api, offerId);
1348
+ async fetchOfferRequirements(offerId, clientCreds) {
1349
+ await this.ensureAuthenticated(clientCreds);
1350
+ return fetchOfferRequirements(
1351
+ this.api,
1352
+ offerId,
1353
+ clientCreds
1354
+ );
875
1355
  }
876
1356
  async fetchRequirementStatuses(offerId) {
877
- await this.ensureAuthenticated();
1357
+ await this.ensureUserAuthenticated();
878
1358
  return fetchRequirementStatuses(this.api, offerId);
879
1359
  }
1360
+ async ensureAuthenticated(clientCreds) {
1361
+ if (!clientCreds) {
1362
+ await this.ensureUserAuthenticated();
1363
+ }
1364
+ }
1365
+ async ensureUserAuthenticated() {
1366
+ const token = await this.accessToken();
1367
+ if (token === null) {
1368
+ throw new NotAuthenticatedError();
1369
+ }
1370
+ }
1371
+ async fetchPii() {
1372
+ await this.ensureUserAuthenticated();
1373
+ return fetchPii(this.api);
1374
+ }
1375
+ async submitDocument(documentType, fields) {
1376
+ await this.ensureUserAuthenticated();
1377
+ return submitDocument(this.api, documentType, fields);
1378
+ }
1379
+ async createKycToken(levelName, reset) {
1380
+ await this.ensureUserAuthenticated();
1381
+ return createKycToken(this.api, levelName, reset);
1382
+ }
880
1383
  };
881
1384
  function createCoinListServer(config) {
882
1385
  return new CoinListServerImpl(config);