@naturalpay/sdk 0.0.3 → 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/index.js CHANGED
@@ -590,6 +590,57 @@ function unwrapBalance(response) {
590
590
  pendingClaimCount: attributes.pendingClaimCount != null ? Number(attributes.pendingClaimCount) : void 0
591
591
  };
592
592
  }
593
+ function unwrapDeposit(response) {
594
+ if (!response?.data) {
595
+ throw new NaturalError('Unexpected response format: missing "data" field in deposit response');
596
+ }
597
+ const { data } = response;
598
+ if (data.type !== "deposit" || !data.attributes) {
599
+ throw new NaturalError(
600
+ `Unexpected resource format: expected type "deposit", got "${data.type}"`
601
+ );
602
+ }
603
+ const { id, attributes } = data;
604
+ return {
605
+ transferId: id ?? void 0,
606
+ status: String(attributes.status),
607
+ amount: attributes.amount != null ? String(attributes.amount) : "",
608
+ currency: String(attributes.currency),
609
+ estimatedSettlement: attributes.estimatedSettlement != null ? String(attributes.estimatedSettlement) : void 0,
610
+ error: attributes.error != null ? String(attributes.error) : void 0,
611
+ errorDetails: attributes.errorDetails != null ? String(attributes.errorDetails) : void 0
612
+ };
613
+ }
614
+ function unwrapWithdrawal(response) {
615
+ if (!response?.data) {
616
+ throw new NaturalError(
617
+ 'Unexpected response format: missing "data" field in withdrawal response'
618
+ );
619
+ }
620
+ const { data } = response;
621
+ if (data.type !== "withdrawal" || !data.attributes) {
622
+ throw new NaturalError(
623
+ `Unexpected resource format: expected type "withdrawal", got "${data.type}"`
624
+ );
625
+ }
626
+ const { id, attributes } = data;
627
+ return {
628
+ transferId: id ?? void 0,
629
+ instructionId: attributes.instructionId != null ? String(attributes.instructionId) : void 0,
630
+ status: String(attributes.status),
631
+ amount: attributes.amount != null ? String(attributes.amount) : "",
632
+ currency: String(attributes.currency),
633
+ estimatedSettlement: attributes.estimatedSettlement != null ? String(attributes.estimatedSettlement) : void 0,
634
+ kycRequired: Boolean(attributes.kycRequired),
635
+ kycStatus: attributes.kycStatus != null ? String(attributes.kycStatus) : void 0,
636
+ kycSessionUrl: attributes.kycSessionUrl != null ? String(attributes.kycSessionUrl) : void 0,
637
+ mfaRequired: Boolean(attributes.mfaRequired),
638
+ mfaChallengeId: attributes.mfaChallengeId != null ? String(attributes.mfaChallengeId) : void 0,
639
+ mfaExpiresAt: attributes.mfaExpiresAt != null ? String(attributes.mfaExpiresAt) : void 0,
640
+ error: attributes.error != null ? String(attributes.error) : void 0,
641
+ errorDetails: attributes.errorDetails != null ? String(attributes.errorDetails) : void 0
642
+ };
643
+ }
593
644
  var WalletResource = class extends BaseResource {
594
645
  /**
595
646
  * Get current wallet balance.
@@ -607,18 +658,20 @@ var WalletResource = class extends BaseResource {
607
658
  * @returns DepositResponse with transfer status
608
659
  */
609
660
  async deposit(params) {
610
- const body = {
661
+ const attributes = {
611
662
  amount: params.amount,
612
663
  currency: params.currency ?? "USD",
613
664
  paymentInstrumentId: params.paymentInstrumentId
614
665
  };
615
666
  if (params.description) {
616
- body["description"] = params.description;
667
+ attributes["description"] = params.description;
617
668
  }
618
- return this.http.post("/wallet/deposit", {
669
+ const body = { data: { attributes } };
670
+ const response = await this.http.post("/wallet/deposit", {
619
671
  body,
620
672
  headers: { "Idempotency-Key": params.idempotencyKey }
621
673
  });
674
+ return unwrapDeposit(response);
622
675
  }
623
676
  /**
624
677
  * Initiate a withdrawal to a linked bank account.
@@ -627,21 +680,19 @@ var WalletResource = class extends BaseResource {
627
680
  * @returns WithdrawResponse with transfer status (may require KYC/MFA)
628
681
  */
629
682
  async withdraw(params) {
630
- const body = {
683
+ const attributes = {
631
684
  amount: params.amount,
632
685
  currency: params.currency ?? "USD",
633
686
  paymentInstrumentId: params.paymentInstrumentId
634
687
  };
635
- if (params.description) {
636
- body["description"] = params.description;
637
- }
638
- if (params.walletId) {
639
- body["walletId"] = params.walletId;
640
- }
641
- return this.http.post("/wallet/withdraw", {
688
+ if (params.description) attributes["description"] = params.description;
689
+ if (params.walletId) attributes["walletId"] = params.walletId;
690
+ const body = { data: { attributes } };
691
+ const response = await this.http.post("/wallet/withdraw", {
642
692
  body,
643
693
  headers: { "Idempotency-Key": params.idempotencyKey }
644
694
  });
695
+ return unwrapWithdrawal(response);
645
696
  }
646
697
  };
647
698
 
@@ -843,6 +894,52 @@ var AgentsResource = class extends BaseResource {
843
894
  };
844
895
 
845
896
  // src/resources/delegations.ts
897
+ function unwrapDelegationResource(resource) {
898
+ if (resource.type !== "delegation" || !resource.attributes) {
899
+ throw new NaturalError(
900
+ `Unexpected resource format: expected type "delegation", got "${resource.type}"`
901
+ );
902
+ }
903
+ const { id, attributes, relationships } = resource;
904
+ return {
905
+ id,
906
+ delegatingPartyId: relationships?.delegatingParty?.data?.id ?? "",
907
+ delegatedPartyId: relationships?.delegatedParty?.data?.id ?? "",
908
+ delegatingPartyName: attributes.delegatingPartyName != null ? String(attributes.delegatingPartyName) : void 0,
909
+ delegatedPartyName: attributes.delegatedPartyName != null ? String(attributes.delegatedPartyName) : void 0,
910
+ delegatingPartyEmail: attributes.delegatingPartyEmail != null ? String(attributes.delegatingPartyEmail) : void 0,
911
+ delegatedPartyEmail: attributes.delegatedPartyEmail != null ? String(attributes.delegatedPartyEmail) : void 0,
912
+ permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
913
+ sourceType: attributes.sourceType != null ? String(attributes.sourceType) : void 0,
914
+ sourceId: attributes.sourceId != null ? String(attributes.sourceId) : void 0,
915
+ expiresAt: attributes.expiresAt != null ? String(attributes.expiresAt) : void 0,
916
+ status: String(attributes.status),
917
+ createdAt: String(attributes.createdAt),
918
+ createdBy: attributes.createdBy != null ? String(attributes.createdBy) : void 0
919
+ };
920
+ }
921
+ function unwrapDelegation(response) {
922
+ if (!response?.data) {
923
+ throw new NaturalError(
924
+ 'Unexpected response format: missing "data" field in delegation response'
925
+ );
926
+ }
927
+ return unwrapDelegationResource(response.data);
928
+ }
929
+ function unwrapDelegationList(response) {
930
+ if (!response?.data || !Array.isArray(response.data)) {
931
+ throw new NaturalError(
932
+ 'Unexpected response format: missing "data" array in delegation list response'
933
+ );
934
+ }
935
+ const delegations = response.data.map(unwrapDelegationResource);
936
+ const pagination = response.meta?.pagination ?? {};
937
+ return {
938
+ delegations,
939
+ hasMore: pagination.hasMore ?? false,
940
+ nextCursor: pagination.nextCursor ?? null
941
+ };
942
+ }
846
943
  var DelegationsResource = class extends BaseResource {
847
944
  /**
848
945
  * List delegations with optional filters.
@@ -851,7 +948,7 @@ var DelegationsResource = class extends BaseResource {
851
948
  * @returns DelegationListResponse with list of delegations
852
949
  */
853
950
  async list(params) {
854
- return this.http.get("/delegations", {
951
+ const response = await this.http.get("/delegations", {
855
952
  params: {
856
953
  status: params?.status,
857
954
  delegatingPartyId: params?.delegatingPartyId,
@@ -860,6 +957,7 @@ var DelegationsResource = class extends BaseResource {
860
957
  cursor: params?.cursor
861
958
  }
862
959
  });
960
+ return unwrapDelegationList(response);
863
961
  }
864
962
  /**
865
963
  * Get delegation by ID.
@@ -868,7 +966,8 @@ var DelegationsResource = class extends BaseResource {
868
966
  * @returns Delegation details
869
967
  */
870
968
  async get(delegationId) {
871
- return this.http.get(`/delegations/${delegationId}`);
969
+ const response = await this.http.get(`/delegations/${delegationId}`);
970
+ return unwrapDelegation(response);
872
971
  }
873
972
  /**
874
973
  * Update an existing delegation.
@@ -878,11 +977,15 @@ var DelegationsResource = class extends BaseResource {
878
977
  * @returns Updated Delegation
879
978
  */
880
979
  async update(delegationId, params) {
881
- const body = {};
882
- if (params.status !== void 0) body["status"] = params.status;
883
- if (params.permissions !== void 0) body["permissions"] = params.permissions;
884
- if (params.expiresAt !== void 0) body["expiresAt"] = params.expiresAt;
885
- return this.http.put(`/delegations/${delegationId}`, { body });
980
+ const attributes = {};
981
+ if (params.status !== void 0) attributes["status"] = params.status;
982
+ if (params.permissions !== void 0) attributes["permissions"] = params.permissions;
983
+ if (params.expiresAt !== void 0) attributes["expiresAt"] = params.expiresAt;
984
+ const body = { data: { attributes } };
985
+ const response = await this.http.put(`/delegations/${delegationId}`, {
986
+ body
987
+ });
988
+ return unwrapDelegation(response);
886
989
  }
887
990
  /**
888
991
  * Revoke a delegation (soft delete by setting status to REVOKED).
@@ -896,6 +999,41 @@ var DelegationsResource = class extends BaseResource {
896
999
  };
897
1000
 
898
1001
  // src/resources/customers.ts
1002
+ function unwrapCustomerResource(resource) {
1003
+ if (resource.type !== "customer" || !resource.attributes) {
1004
+ throw new NaturalError(
1005
+ `Unexpected resource format: expected type "customer", got "${resource.type}"`
1006
+ );
1007
+ }
1008
+ const { id, attributes, relationships } = resource;
1009
+ return {
1010
+ party: {
1011
+ id,
1012
+ type: String(attributes.partyType),
1013
+ legalName: attributes.legalName != null ? String(attributes.legalName) : void 0,
1014
+ displayName: attributes.displayName != null ? String(attributes.displayName) : void 0,
1015
+ status: attributes.partyStatus != null ? String(attributes.partyStatus) : void 0
1016
+ },
1017
+ delegationId: relationships?.delegation?.data?.id ?? "",
1018
+ permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
1019
+ delegationStatus: String(attributes.delegationStatus),
1020
+ createdAt: String(attributes.createdAt)
1021
+ };
1022
+ }
1023
+ function unwrapCustomerList(response) {
1024
+ if (!response?.data || !Array.isArray(response.data)) {
1025
+ throw new NaturalError(
1026
+ 'Unexpected response format: missing "data" array in customer list response'
1027
+ );
1028
+ }
1029
+ const items = response.data.map(unwrapCustomerResource);
1030
+ const pagination = response.meta?.pagination ?? {};
1031
+ return {
1032
+ items,
1033
+ hasMore: pagination.hasMore ?? false,
1034
+ nextCursor: pagination.nextCursor ?? null
1035
+ };
1036
+ }
899
1037
  var CustomersResource = class extends BaseResource {
900
1038
  /**
901
1039
  * List customers onboarded by the partner via delegation.
@@ -904,12 +1042,13 @@ var CustomersResource = class extends BaseResource {
904
1042
  * @returns CustomerListResponse with items, hasMore, nextCursor
905
1043
  */
906
1044
  async list(params) {
907
- return this.http.get("/customers", {
1045
+ const response = await this.http.get("/customers", {
908
1046
  params: {
909
1047
  limit: params?.limit,
910
1048
  cursor: params?.cursor
911
1049
  }
912
1050
  });
1051
+ return unwrapCustomerList(response);
913
1052
  }
914
1053
  };
915
1054