@naturalpay/sdk 0.0.2 → 0.0.4

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.

Potentially problematic release.


This version of @naturalpay/sdk might be problematic. Click here for more details.

package/dist/mcp/cli.cjs CHANGED
@@ -500,6 +500,32 @@ var BaseResource = class {
500
500
 
501
501
  // src/resources/payments.ts
502
502
  var IDEMPOTENCY_WINDOW_SECONDS = 300;
503
+ function unwrapPayment(response) {
504
+ if (!response?.data) {
505
+ throw new NaturalError('Unexpected response format: missing "data" field in payment response');
506
+ }
507
+ const { data } = response;
508
+ if (data.type !== "payment" || !data.attributes) {
509
+ throw new NaturalError(
510
+ `Unexpected resource format: expected type "payment", got "${data.type}"`
511
+ );
512
+ }
513
+ const { id, attributes, relationships } = data;
514
+ const description = attributes.description != null ? String(attributes.description) : void 0;
515
+ return {
516
+ transferId: id,
517
+ status: String(attributes.status),
518
+ amount: String(attributes.amount),
519
+ currency: String(attributes.currency),
520
+ description,
521
+ memo: description,
522
+ createdAt: attributes.createdAt != null ? String(attributes.createdAt) : void 0,
523
+ updatedAt: attributes.updatedAt != null ? String(attributes.updatedAt) : void 0,
524
+ claimLink: attributes.claimLink != null ? String(attributes.claimLink) : void 0,
525
+ counterpartyPartyId: relationships?.counterparty?.data?.id,
526
+ customerPartyId: relationships?.customerParty?.data?.id
527
+ };
528
+ }
503
529
  var PaymentsResource = class extends BaseResource {
504
530
  /**
505
531
  * Generate idempotency key based on payment details + time window.
@@ -530,20 +556,19 @@ var PaymentsResource = class extends BaseResource {
530
556
  }
531
557
  const recipient = params.recipientEmail ?? params.recipientPhone ?? params.recipientPartyId;
532
558
  const idempotencyKey = params.idempotencyKey ?? this.generateIdempotencyKey(recipient, params.amount, params.memo);
533
- const body = {
534
- amount: params.amount
559
+ const attributes = {
560
+ amount: String(params.amount),
561
+ currency: "USD",
562
+ counterparty: recipient,
563
+ customerPartyId: params.customerPartyId
535
564
  };
536
- if (params.recipientEmail) body["recipientEmail"] = params.recipientEmail;
537
- if (params.recipientPhone) body["recipientPhone"] = params.recipientPhone;
538
- if (params.recipientPartyId) body["recipientPartyId"] = params.recipientPartyId;
539
- if (params.memo) body["memo"] = params.memo;
540
- if (params.agentId) body["agentId"] = params.agentId;
541
- if (params.customerPartyId) body["customerPartyId"] = params.customerPartyId;
542
- if (params.instanceId) body["instanceId"] = params.instanceId;
543
- return this.http.post("/payments/initiate", {
565
+ if (params.memo) attributes["description"] = params.memo;
566
+ const body = { data: { attributes } };
567
+ const response = await this.http.post("/payments", {
544
568
  body,
545
569
  headers: { "Idempotency-Key": idempotencyKey }
546
570
  });
571
+ return unwrapPayment(response);
547
572
  }
548
573
  /**
549
574
  * Get payment status by transfer ID.
@@ -552,20 +577,83 @@ var PaymentsResource = class extends BaseResource {
552
577
  * @returns Payment object with current status
553
578
  */
554
579
  async retrieve(transferId) {
555
- return this.http.get(`/payments/${transferId}`);
556
- }
557
- /**
558
- * Cancel a pending payment.
559
- *
560
- * @param transferId - The transfer ID to cancel
561
- * @returns Cancellation result with status and message
562
- */
563
- async cancel(transferId) {
564
- return this.http.post(`/payments/${transferId}/cancel`);
580
+ const response = await this.http.get(`/payments/${transferId}`);
581
+ return unwrapPayment(response);
565
582
  }
566
583
  };
567
584
 
568
585
  // src/resources/wallet.ts
586
+ function unwrapBalance(response) {
587
+ if (!response?.data) {
588
+ throw new NaturalError(
589
+ 'Unexpected response format: missing "data" field in wallet balance response'
590
+ );
591
+ }
592
+ const { data } = response;
593
+ if (data.type !== "wallet_balance" || !data.attributes) {
594
+ throw new NaturalError(
595
+ `Unexpected resource format: expected type "wallet_balance", got "${data.type}"`
596
+ );
597
+ }
598
+ const { id, attributes } = data;
599
+ return {
600
+ walletId: id,
601
+ balances: attributes.balances,
602
+ pendingClaimAmountMinor: attributes.pendingClaimAmountMinor != null ? Number(attributes.pendingClaimAmountMinor) : void 0,
603
+ pendingClaimCount: attributes.pendingClaimCount != null ? Number(attributes.pendingClaimCount) : void 0
604
+ };
605
+ }
606
+ function unwrapDeposit(response) {
607
+ if (!response?.data) {
608
+ throw new NaturalError('Unexpected response format: missing "data" field in deposit response');
609
+ }
610
+ const { data } = response;
611
+ if (data.type !== "deposit" || !data.attributes) {
612
+ throw new NaturalError(
613
+ `Unexpected resource format: expected type "deposit", got "${data.type}"`
614
+ );
615
+ }
616
+ const { id, attributes } = data;
617
+ return {
618
+ transferId: id ?? void 0,
619
+ status: String(attributes.status),
620
+ amount: attributes.amount != null ? String(attributes.amount) : "",
621
+ currency: String(attributes.currency),
622
+ estimatedSettlement: attributes.estimatedSettlement != null ? String(attributes.estimatedSettlement) : void 0,
623
+ error: attributes.error != null ? String(attributes.error) : void 0,
624
+ errorDetails: attributes.errorDetails != null ? String(attributes.errorDetails) : void 0
625
+ };
626
+ }
627
+ function unwrapWithdrawal(response) {
628
+ if (!response?.data) {
629
+ throw new NaturalError(
630
+ 'Unexpected response format: missing "data" field in withdrawal response'
631
+ );
632
+ }
633
+ const { data } = response;
634
+ if (data.type !== "withdrawal" || !data.attributes) {
635
+ throw new NaturalError(
636
+ `Unexpected resource format: expected type "withdrawal", got "${data.type}"`
637
+ );
638
+ }
639
+ const { id, attributes } = data;
640
+ return {
641
+ transferId: id ?? void 0,
642
+ instructionId: attributes.instructionId != null ? String(attributes.instructionId) : void 0,
643
+ status: String(attributes.status),
644
+ amount: attributes.amount != null ? String(attributes.amount) : "",
645
+ currency: String(attributes.currency),
646
+ estimatedSettlement: attributes.estimatedSettlement != null ? String(attributes.estimatedSettlement) : void 0,
647
+ kycRequired: Boolean(attributes.kycRequired),
648
+ kycStatus: attributes.kycStatus != null ? String(attributes.kycStatus) : void 0,
649
+ kycSessionUrl: attributes.kycSessionUrl != null ? String(attributes.kycSessionUrl) : void 0,
650
+ mfaRequired: Boolean(attributes.mfaRequired),
651
+ mfaChallengeId: attributes.mfaChallengeId != null ? String(attributes.mfaChallengeId) : void 0,
652
+ mfaExpiresAt: attributes.mfaExpiresAt != null ? String(attributes.mfaExpiresAt) : void 0,
653
+ error: attributes.error != null ? String(attributes.error) : void 0,
654
+ errorDetails: attributes.errorDetails != null ? String(attributes.errorDetails) : void 0
655
+ };
656
+ }
569
657
  var WalletResource = class extends BaseResource {
570
658
  /**
571
659
  * Get current wallet balance.
@@ -573,7 +661,8 @@ var WalletResource = class extends BaseResource {
573
661
  * @returns AccountBalance with available, current, pending amounts
574
662
  */
575
663
  async balance() {
576
- return this.http.get("/wallet/balance");
664
+ const response = await this.http.get("/wallet/balance");
665
+ return unwrapBalance(response);
577
666
  }
578
667
  /**
579
668
  * Initiate a deposit from a linked bank account.
@@ -582,18 +671,20 @@ var WalletResource = class extends BaseResource {
582
671
  * @returns DepositResponse with transfer status
583
672
  */
584
673
  async deposit(params) {
585
- const body = {
674
+ const attributes = {
586
675
  amount: params.amount,
587
676
  currency: params.currency ?? "USD",
588
677
  paymentInstrumentId: params.paymentInstrumentId
589
678
  };
590
679
  if (params.description) {
591
- body["description"] = params.description;
680
+ attributes["description"] = params.description;
592
681
  }
593
- return this.http.post("/wallet/deposit", {
682
+ const body = { data: { attributes } };
683
+ const response = await this.http.post("/wallet/deposit", {
594
684
  body,
595
685
  headers: { "Idempotency-Key": params.idempotencyKey }
596
686
  });
687
+ return unwrapDeposit(response);
597
688
  }
598
689
  /**
599
690
  * Initiate a withdrawal to a linked bank account.
@@ -602,28 +693,59 @@ var WalletResource = class extends BaseResource {
602
693
  * @returns WithdrawResponse with transfer status (may require KYC/MFA)
603
694
  */
604
695
  async withdraw(params) {
605
- const body = {
696
+ const attributes = {
606
697
  amount: params.amount,
607
698
  currency: params.currency ?? "USD",
608
699
  paymentInstrumentId: params.paymentInstrumentId
609
700
  };
610
- if (params.description) {
611
- body["description"] = params.description;
612
- }
613
- return this.http.post("/wallet/withdraw", {
701
+ if (params.description) attributes["description"] = params.description;
702
+ if (params.walletId) attributes["walletId"] = params.walletId;
703
+ const body = { data: { attributes } };
704
+ const response = await this.http.post("/wallet/withdraw", {
614
705
  body,
615
706
  headers: { "Idempotency-Key": params.idempotencyKey }
616
707
  });
708
+ return unwrapWithdrawal(response);
617
709
  }
618
710
  };
619
711
 
620
712
  // src/resources/transactions.ts
713
+ function unwrapTransactionResource(resource) {
714
+ if (resource.type !== "transaction" || !resource.attributes) {
715
+ throw new NaturalError(
716
+ `Unexpected resource format: expected type "transaction", got "${resource.type}"`
717
+ );
718
+ }
719
+ const { id, attributes, relationships } = resource;
720
+ return {
721
+ transactionId: id,
722
+ amount: String(attributes.amount),
723
+ currency: String(attributes.currency),
724
+ status: String(attributes.status),
725
+ description: attributes.description != null ? String(attributes.description) : void 0,
726
+ memo: attributes.memo != null ? String(attributes.memo) : void 0,
727
+ createdAt: String(attributes.createdAt),
728
+ updatedAt: attributes.updatedAt != null ? String(attributes.updatedAt) : void 0,
729
+ isDelegated: Boolean(attributes.isDelegated),
730
+ customerName: attributes.customerName != null ? String(attributes.customerName) : void 0,
731
+ customerAgentId: attributes.customerAgentId != null ? String(attributes.customerAgentId) : void 0,
732
+ senderName: attributes.senderName != null ? String(attributes.senderName) : void 0,
733
+ recipientName: attributes.recipientName != null ? String(attributes.recipientName) : void 0,
734
+ transactionType: String(attributes.transactionType),
735
+ category: String(attributes.category),
736
+ direction: String(attributes.direction),
737
+ sourcePartyId: relationships?.sourceParty?.data?.id,
738
+ destinationPartyId: relationships?.destinationParty?.data?.id,
739
+ sourceWalletId: relationships?.sourceWallet?.data?.id,
740
+ destinationWalletId: relationships?.destinationWallet?.data?.id
741
+ };
742
+ }
621
743
  var TransactionsResource = class extends BaseResource {
622
744
  /**
623
745
  * List recent transactions.
624
746
  *
625
747
  * @param params - List parameters including agent context
626
- * @returns List of Transaction objects
748
+ * @returns TransactionListResponse with transactions and pagination info
627
749
  */
628
750
  async list(params) {
629
751
  const headers = {};
@@ -633,20 +755,69 @@ var TransactionsResource = class extends BaseResource {
633
755
  if (params?.customerPartyId) {
634
756
  headers["X-On-Behalf-Of"] = params.customerPartyId;
635
757
  }
636
- const data = await this.http.get("/transactions", {
758
+ const response = await this.http.get("/transactions", {
637
759
  params: {
638
- limit: params?.limit ?? 10,
639
- offset: params?.offset ?? 0,
640
- customerFilter: params?.customerFilter,
760
+ limit: params?.limit ?? 50,
761
+ cursor: params?.cursor,
641
762
  type: params?.type
642
763
  },
643
764
  headers: Object.keys(headers).length > 0 ? headers : void 0
644
765
  });
645
- return data.transfers ?? data.transactions ?? [];
766
+ if (!response?.data || !Array.isArray(response.data)) {
767
+ throw new NaturalError(
768
+ 'Unexpected response format: missing "data" array in transaction list response'
769
+ );
770
+ }
771
+ const transactions = response.data.map(unwrapTransactionResource);
772
+ const pagination = response.meta?.pagination ?? {};
773
+ return {
774
+ transactions,
775
+ hasMore: pagination.hasMore ?? false,
776
+ nextCursor: pagination.nextCursor ?? null
777
+ };
646
778
  }
647
779
  };
648
780
 
649
781
  // src/resources/agents.ts
782
+ function unwrapAgentResource(resource) {
783
+ if (resource.type !== "agent" || !resource.attributes) {
784
+ throw new NaturalError(
785
+ `Unexpected resource format: expected type "agent", got "${resource.type}"`
786
+ );
787
+ }
788
+ const { id, attributes, relationships } = resource;
789
+ return {
790
+ id,
791
+ name: String(attributes.name),
792
+ description: attributes.description != null ? String(attributes.description) : void 0,
793
+ status: String(attributes.status),
794
+ partyId: relationships?.party?.data?.id ?? "",
795
+ createdAt: attributes.createdAt != null ? String(attributes.createdAt) : void 0,
796
+ createdBy: attributes.createdBy != null ? String(attributes.createdBy) : void 0,
797
+ updatedAt: attributes.updatedAt != null ? String(attributes.updatedAt) : void 0,
798
+ updatedBy: attributes.updatedBy != null ? String(attributes.updatedBy) : void 0
799
+ };
800
+ }
801
+ function unwrapAgent(response) {
802
+ if (!response?.data) {
803
+ throw new NaturalError('Unexpected response format: missing "data" field in agent response');
804
+ }
805
+ return unwrapAgentResource(response.data);
806
+ }
807
+ function unwrapAgentList(response) {
808
+ if (!response?.data || !Array.isArray(response.data)) {
809
+ throw new NaturalError(
810
+ 'Unexpected response format: missing "data" array in agent list response'
811
+ );
812
+ }
813
+ const agents = response.data.map(unwrapAgentResource);
814
+ const pagination = response.meta?.pagination ?? {};
815
+ return {
816
+ agents,
817
+ hasMore: pagination.hasMore ?? false,
818
+ nextCursor: pagination.nextCursor ?? null
819
+ };
820
+ }
650
821
  var AgentsResource = class extends BaseResource {
651
822
  /**
652
823
  * List agents for the partner.
@@ -655,14 +826,15 @@ var AgentsResource = class extends BaseResource {
655
826
  * @returns AgentListResponse with list of agents
656
827
  */
657
828
  async list(params) {
658
- return this.http.get("/agents", {
829
+ const response = await this.http.get("/agents", {
659
830
  params: {
660
831
  status: params?.status,
661
832
  partyId: params?.partyId,
662
833
  limit: params?.limit ?? 50,
663
- offset: params?.offset ?? 0
834
+ cursor: params?.cursor
664
835
  }
665
836
  });
837
+ return unwrapAgentList(response);
666
838
  }
667
839
  /**
668
840
  * Get agent by ID.
@@ -671,7 +843,8 @@ var AgentsResource = class extends BaseResource {
671
843
  * @returns Agent details
672
844
  */
673
845
  async get(agentId) {
674
- return this.http.get(`/agents/${agentId}`);
846
+ const response = await this.http.get(`/agents/${agentId}`);
847
+ return unwrapAgent(response);
675
848
  }
676
849
  /**
677
850
  * Create a new agent.
@@ -680,21 +853,25 @@ var AgentsResource = class extends BaseResource {
680
853
  * @returns AgentCreateResponse with created agent details
681
854
  */
682
855
  async create(params) {
683
- const body = {
684
- name: params.name,
685
- partyId: params.partyId
856
+ const attributes = {
857
+ name: params.name
686
858
  };
687
859
  if (params.description) {
688
- body["description"] = params.description;
860
+ attributes["description"] = params.description;
861
+ }
862
+ if (params.limits) {
863
+ attributes["limits"] = params.limits;
689
864
  }
865
+ const body = { data: { attributes } };
690
866
  const headers = {};
691
867
  if (params.idempotencyKey) {
692
868
  headers["Idempotency-Key"] = params.idempotencyKey;
693
869
  }
694
- return this.http.post("/agents", {
870
+ const response = await this.http.post("/agents", {
695
871
  body,
696
872
  headers: Object.keys(headers).length > 0 ? headers : void 0
697
873
  });
874
+ return unwrapAgent(response);
698
875
  }
699
876
  /**
700
877
  * Update an existing agent.
@@ -704,18 +881,20 @@ var AgentsResource = class extends BaseResource {
704
881
  * @returns AgentUpdateResponse with updated agent details
705
882
  */
706
883
  async update(agentId, params) {
707
- const body = {};
708
- if (params.name !== void 0) body["name"] = params.name;
709
- if (params.description !== void 0) body["description"] = params.description;
710
- if (params.status !== void 0) body["status"] = params.status;
884
+ const attributes = {};
885
+ if (params.name !== void 0) attributes["name"] = params.name;
886
+ if (params.description !== void 0) attributes["description"] = params.description;
887
+ if (params.status !== void 0) attributes["status"] = params.status;
888
+ const body = { data: { attributes } };
711
889
  const headers = {};
712
890
  if (params.idempotencyKey) {
713
891
  headers["Idempotency-Key"] = params.idempotencyKey;
714
892
  }
715
- return this.http.put(`/agents/${agentId}`, {
893
+ const response = await this.http.put(`/agents/${agentId}`, {
716
894
  body,
717
895
  headers: Object.keys(headers).length > 0 ? headers : void 0
718
896
  });
897
+ return unwrapAgent(response);
719
898
  }
720
899
  /**
721
900
  * Delete an agent.
@@ -728,6 +907,52 @@ var AgentsResource = class extends BaseResource {
728
907
  };
729
908
 
730
909
  // src/resources/delegations.ts
910
+ function unwrapDelegationResource(resource) {
911
+ if (resource.type !== "delegation" || !resource.attributes) {
912
+ throw new NaturalError(
913
+ `Unexpected resource format: expected type "delegation", got "${resource.type}"`
914
+ );
915
+ }
916
+ const { id, attributes, relationships } = resource;
917
+ return {
918
+ id,
919
+ delegatingPartyId: relationships?.delegatingParty?.data?.id ?? "",
920
+ delegatedPartyId: relationships?.delegatedParty?.data?.id ?? "",
921
+ delegatingPartyName: attributes.delegatingPartyName != null ? String(attributes.delegatingPartyName) : void 0,
922
+ delegatedPartyName: attributes.delegatedPartyName != null ? String(attributes.delegatedPartyName) : void 0,
923
+ delegatingPartyEmail: attributes.delegatingPartyEmail != null ? String(attributes.delegatingPartyEmail) : void 0,
924
+ delegatedPartyEmail: attributes.delegatedPartyEmail != null ? String(attributes.delegatedPartyEmail) : void 0,
925
+ permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
926
+ sourceType: attributes.sourceType != null ? String(attributes.sourceType) : void 0,
927
+ sourceId: attributes.sourceId != null ? String(attributes.sourceId) : void 0,
928
+ expiresAt: attributes.expiresAt != null ? String(attributes.expiresAt) : void 0,
929
+ status: String(attributes.status),
930
+ createdAt: String(attributes.createdAt),
931
+ createdBy: attributes.createdBy != null ? String(attributes.createdBy) : void 0
932
+ };
933
+ }
934
+ function unwrapDelegation(response) {
935
+ if (!response?.data) {
936
+ throw new NaturalError(
937
+ 'Unexpected response format: missing "data" field in delegation response'
938
+ );
939
+ }
940
+ return unwrapDelegationResource(response.data);
941
+ }
942
+ function unwrapDelegationList(response) {
943
+ if (!response?.data || !Array.isArray(response.data)) {
944
+ throw new NaturalError(
945
+ 'Unexpected response format: missing "data" array in delegation list response'
946
+ );
947
+ }
948
+ const delegations = response.data.map(unwrapDelegationResource);
949
+ const pagination = response.meta?.pagination ?? {};
950
+ return {
951
+ delegations,
952
+ hasMore: pagination.hasMore ?? false,
953
+ nextCursor: pagination.nextCursor ?? null
954
+ };
955
+ }
731
956
  var DelegationsResource = class extends BaseResource {
732
957
  /**
733
958
  * List delegations with optional filters.
@@ -736,13 +961,16 @@ var DelegationsResource = class extends BaseResource {
736
961
  * @returns DelegationListResponse with list of delegations
737
962
  */
738
963
  async list(params) {
739
- return this.http.get("/delegations", {
964
+ const response = await this.http.get("/delegations", {
740
965
  params: {
741
966
  status: params?.status,
742
967
  delegatingPartyId: params?.delegatingPartyId,
743
- delegatedPartyId: params?.delegatedPartyId
968
+ delegatedPartyId: params?.delegatedPartyId,
969
+ limit: params?.limit ?? 50,
970
+ cursor: params?.cursor
744
971
  }
745
972
  });
973
+ return unwrapDelegationList(response);
746
974
  }
747
975
  /**
748
976
  * Get delegation by ID.
@@ -751,31 +979,8 @@ var DelegationsResource = class extends BaseResource {
751
979
  * @returns Delegation details
752
980
  */
753
981
  async get(delegationId) {
754
- return this.http.get(`/delegations/${delegationId}`);
755
- }
756
- /**
757
- * Create a new delegation (party-to-party trust relationship).
758
- *
759
- * @param params - Delegation creation parameters
760
- * @returns Created Delegation
761
- */
762
- async create(params) {
763
- const body = {
764
- delegatingPartyId: params.delegatingPartyId,
765
- delegatedPartyId: params.delegatedPartyId,
766
- permissions: params.permissions
767
- };
768
- if (params.expiresAt) {
769
- body["expiresAt"] = params.expiresAt;
770
- }
771
- const headers = {};
772
- if (params.idempotencyKey) {
773
- headers["Idempotency-Key"] = params.idempotencyKey;
774
- }
775
- return this.http.post("/delegations", {
776
- body,
777
- headers: Object.keys(headers).length > 0 ? headers : void 0
778
- });
982
+ const response = await this.http.get(`/delegations/${delegationId}`);
983
+ return unwrapDelegation(response);
779
984
  }
780
985
  /**
781
986
  * Update an existing delegation.
@@ -785,11 +990,15 @@ var DelegationsResource = class extends BaseResource {
785
990
  * @returns Updated Delegation
786
991
  */
787
992
  async update(delegationId, params) {
788
- const body = {};
789
- if (params.status !== void 0) body["status"] = params.status;
790
- if (params.permissions !== void 0) body["permissions"] = params.permissions;
791
- if (params.expiresAt !== void 0) body["expiresAt"] = params.expiresAt;
792
- return this.http.put(`/delegations/${delegationId}`, { body });
993
+ const attributes = {};
994
+ if (params.status !== void 0) attributes["status"] = params.status;
995
+ if (params.permissions !== void 0) attributes["permissions"] = params.permissions;
996
+ if (params.expiresAt !== void 0) attributes["expiresAt"] = params.expiresAt;
997
+ const body = { data: { attributes } };
998
+ const response = await this.http.put(`/delegations/${delegationId}`, {
999
+ body
1000
+ });
1001
+ return unwrapDelegation(response);
793
1002
  }
794
1003
  /**
795
1004
  * Revoke a delegation (soft delete by setting status to REVOKED).
@@ -798,19 +1007,61 @@ var DelegationsResource = class extends BaseResource {
798
1007
  * @returns Revoked Delegation
799
1008
  */
800
1009
  async revoke(delegationId) {
801
- return this.http.put(`/delegations/${delegationId}/revoke`);
1010
+ return this.update(delegationId, { status: "REVOKED" });
802
1011
  }
803
1012
  };
804
1013
 
805
1014
  // src/resources/customers.ts
1015
+ function unwrapCustomerResource(resource) {
1016
+ if (resource.type !== "customer" || !resource.attributes) {
1017
+ throw new NaturalError(
1018
+ `Unexpected resource format: expected type "customer", got "${resource.type}"`
1019
+ );
1020
+ }
1021
+ const { id, attributes, relationships } = resource;
1022
+ return {
1023
+ party: {
1024
+ id,
1025
+ type: String(attributes.partyType),
1026
+ legalName: attributes.legalName != null ? String(attributes.legalName) : void 0,
1027
+ displayName: attributes.displayName != null ? String(attributes.displayName) : void 0,
1028
+ status: attributes.partyStatus != null ? String(attributes.partyStatus) : void 0
1029
+ },
1030
+ delegationId: relationships?.delegation?.data?.id ?? "",
1031
+ permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
1032
+ delegationStatus: String(attributes.delegationStatus),
1033
+ createdAt: String(attributes.createdAt)
1034
+ };
1035
+ }
1036
+ function unwrapCustomerList(response) {
1037
+ if (!response?.data || !Array.isArray(response.data)) {
1038
+ throw new NaturalError(
1039
+ 'Unexpected response format: missing "data" array in customer list response'
1040
+ );
1041
+ }
1042
+ const items = response.data.map(unwrapCustomerResource);
1043
+ const pagination = response.meta?.pagination ?? {};
1044
+ return {
1045
+ items,
1046
+ hasMore: pagination.hasMore ?? false,
1047
+ nextCursor: pagination.nextCursor ?? null
1048
+ };
1049
+ }
806
1050
  var CustomersResource = class extends BaseResource {
807
1051
  /**
808
1052
  * List customers onboarded by the partner via delegation.
809
1053
  *
810
- * @returns List of Customer objects with party info and delegation details
1054
+ * @param params - Pagination parameters
1055
+ * @returns CustomerListResponse with items, hasMore, nextCursor
811
1056
  */
812
- async list() {
813
- return this.http.get("/customers");
1057
+ async list(params) {
1058
+ const response = await this.http.get("/customers", {
1059
+ params: {
1060
+ limit: params?.limit,
1061
+ cursor: params?.cursor
1062
+ }
1063
+ });
1064
+ return unwrapCustomerList(response);
814
1065
  }
815
1066
  };
816
1067
 
@@ -868,7 +1119,6 @@ function createServer(apiKey) {
868
1119
  description: "Send a payment to a recipient. Must provide exactly one of: recipientEmail, recipientPhone, or recipientPartyId.",
869
1120
  parameters: zod.z.object({
870
1121
  amount: zod.z.number().positive().describe("Payment amount"),
871
- agentId: zod.z.string().describe("Agent ID making the payment (agt_xxx)"),
872
1122
  memo: zod.z.string().describe("Payment memo (required)"),
873
1123
  customerPartyId: zod.z.string().describe("Customer party ID on whose behalf (pty_xxx)"),
874
1124
  recipientEmail: zod.z.string().email().optional().describe("Recipient email address"),
@@ -884,7 +1134,6 @@ function createServer(apiKey) {
884
1134
  recipientPartyId: args.recipientPartyId,
885
1135
  amount: args.amount,
886
1136
  memo: args.memo,
887
- agentId: args.agentId,
888
1137
  customerPartyId: args.customerPartyId
889
1138
  });
890
1139
  const durationMs = Date.now() - startTime;
@@ -925,30 +1174,6 @@ function createServer(apiKey) {
925
1174
  }
926
1175
  }
927
1176
  });
928
- server.addTool({
929
- name: "cancel_payment",
930
- description: "Cancel a pending payment. Only pending payments can be cancelled.",
931
- parameters: zod.z.object({
932
- transferId: zod.z.string().describe("The transfer ID to cancel")
933
- }),
934
- execute: async (args) => {
935
- const startTime = Date.now();
936
- try {
937
- const result = await getClient().payments.cancel(args.transferId);
938
- const durationMs = Date.now() - startTime;
939
- logToolCall(logger2, "cancel_payment", { success: true, durationMs });
940
- return JSON.stringify(result, null, 2);
941
- } catch (error) {
942
- const durationMs = Date.now() - startTime;
943
- logToolCall(logger2, "cancel_payment", {
944
- success: false,
945
- durationMs,
946
- error: error instanceof Error ? error : new Error(String(error))
947
- });
948
- throw error;
949
- }
950
- }
951
- });
952
1177
  server.addTool({
953
1178
  name: "get_account_balance",
954
1179
  description: "Get the current wallet balance",
@@ -993,8 +1218,8 @@ function createServer(apiKey) {
993
1218
  name: "list_transactions",
994
1219
  description: "List recent transactions with optional agent context",
995
1220
  parameters: zod.z.object({
996
- limit: zod.z.number().min(1).max(100).default(10).describe("Maximum number of transactions"),
997
- customerFilter: zod.z.string().optional().describe("Filter by customer agent_id (or '_self' for partner only)"),
1221
+ limit: zod.z.number().min(1).max(100).default(50).describe("Maximum number of transactions"),
1222
+ cursor: zod.z.string().optional().describe("Pagination cursor from previous response"),
998
1223
  agentId: zod.z.string().optional().describe("Agent ID for agent-context authentication"),
999
1224
  customerPartyId: zod.z.string().optional().describe("Customer party ID when acting on behalf of customer")
1000
1225
  }),
@@ -1003,7 +1228,7 @@ function createServer(apiKey) {
1003
1228
  try {
1004
1229
  const result = await getClient().transactions.list({
1005
1230
  limit: args.limit,
1006
- customerFilter: args.customerFilter,
1231
+ cursor: args.cursor,
1007
1232
  agentId: args.agentId,
1008
1233
  customerPartyId: args.customerPartyId
1009
1234
  });