@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.

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