@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.
package/dist/index.cjs CHANGED
@@ -688,6 +688,57 @@ function unwrapBalance(response) {
688
688
  pendingClaimCount: attributes.pendingClaimCount != null ? Number(attributes.pendingClaimCount) : void 0
689
689
  };
690
690
  }
691
+ function unwrapDeposit(response) {
692
+ if (!response?.data) {
693
+ throw new NaturalError('Unexpected response format: missing "data" field in deposit response');
694
+ }
695
+ const { data } = response;
696
+ if (data.type !== "deposit" || !data.attributes) {
697
+ throw new NaturalError(
698
+ `Unexpected resource format: expected type "deposit", got "${data.type}"`
699
+ );
700
+ }
701
+ const { id, attributes } = data;
702
+ return {
703
+ transferId: id ?? void 0,
704
+ status: String(attributes.status),
705
+ amount: attributes.amount != null ? String(attributes.amount) : "",
706
+ currency: String(attributes.currency),
707
+ estimatedSettlement: attributes.estimatedSettlement != null ? String(attributes.estimatedSettlement) : void 0,
708
+ error: attributes.error != null ? String(attributes.error) : void 0,
709
+ errorDetails: attributes.errorDetails != null ? String(attributes.errorDetails) : void 0
710
+ };
711
+ }
712
+ function unwrapWithdrawal(response) {
713
+ if (!response?.data) {
714
+ throw new NaturalError(
715
+ 'Unexpected response format: missing "data" field in withdrawal response'
716
+ );
717
+ }
718
+ const { data } = response;
719
+ if (data.type !== "withdrawal" || !data.attributes) {
720
+ throw new NaturalError(
721
+ `Unexpected resource format: expected type "withdrawal", got "${data.type}"`
722
+ );
723
+ }
724
+ const { id, attributes } = data;
725
+ return {
726
+ transferId: id ?? void 0,
727
+ instructionId: attributes.instructionId != null ? String(attributes.instructionId) : void 0,
728
+ status: String(attributes.status),
729
+ amount: attributes.amount != null ? String(attributes.amount) : "",
730
+ currency: String(attributes.currency),
731
+ estimatedSettlement: attributes.estimatedSettlement != null ? String(attributes.estimatedSettlement) : void 0,
732
+ kycRequired: Boolean(attributes.kycRequired),
733
+ kycStatus: attributes.kycStatus != null ? String(attributes.kycStatus) : void 0,
734
+ kycSessionUrl: attributes.kycSessionUrl != null ? String(attributes.kycSessionUrl) : void 0,
735
+ mfaRequired: Boolean(attributes.mfaRequired),
736
+ mfaChallengeId: attributes.mfaChallengeId != null ? String(attributes.mfaChallengeId) : void 0,
737
+ mfaExpiresAt: attributes.mfaExpiresAt != null ? String(attributes.mfaExpiresAt) : void 0,
738
+ error: attributes.error != null ? String(attributes.error) : void 0,
739
+ errorDetails: attributes.errorDetails != null ? String(attributes.errorDetails) : void 0
740
+ };
741
+ }
691
742
  var WalletResource = class extends BaseResource {
692
743
  /**
693
744
  * Get current wallet balance.
@@ -705,18 +756,20 @@ var WalletResource = class extends BaseResource {
705
756
  * @returns DepositResponse with transfer status
706
757
  */
707
758
  async deposit(params) {
708
- const body = {
759
+ const attributes = {
709
760
  amount: params.amount,
710
761
  currency: params.currency ?? "USD",
711
762
  paymentInstrumentId: params.paymentInstrumentId
712
763
  };
713
764
  if (params.description) {
714
- body["description"] = params.description;
765
+ attributes["description"] = params.description;
715
766
  }
716
- return this.http.post("/wallet/deposit", {
767
+ const body = { data: { attributes } };
768
+ const response = await this.http.post("/wallet/deposit", {
717
769
  body,
718
770
  headers: { "Idempotency-Key": params.idempotencyKey }
719
771
  });
772
+ return unwrapDeposit(response);
720
773
  }
721
774
  /**
722
775
  * Initiate a withdrawal to a linked bank account.
@@ -725,21 +778,19 @@ var WalletResource = class extends BaseResource {
725
778
  * @returns WithdrawResponse with transfer status (may require KYC/MFA)
726
779
  */
727
780
  async withdraw(params) {
728
- const body = {
781
+ const attributes = {
729
782
  amount: params.amount,
730
783
  currency: params.currency ?? "USD",
731
784
  paymentInstrumentId: params.paymentInstrumentId
732
785
  };
733
- if (params.description) {
734
- body["description"] = params.description;
735
- }
736
- if (params.walletId) {
737
- body["walletId"] = params.walletId;
738
- }
739
- return this.http.post("/wallet/withdraw", {
786
+ if (params.description) attributes["description"] = params.description;
787
+ if (params.walletId) attributes["walletId"] = params.walletId;
788
+ const body = { data: { attributes } };
789
+ const response = await this.http.post("/wallet/withdraw", {
740
790
  body,
741
791
  headers: { "Idempotency-Key": params.idempotencyKey }
742
792
  });
793
+ return unwrapWithdrawal(response);
743
794
  }
744
795
  };
745
796
 
@@ -941,6 +992,52 @@ var AgentsResource = class extends BaseResource {
941
992
  };
942
993
 
943
994
  // src/resources/delegations.ts
995
+ function unwrapDelegationResource(resource) {
996
+ if (resource.type !== "delegation" || !resource.attributes) {
997
+ throw new NaturalError(
998
+ `Unexpected resource format: expected type "delegation", got "${resource.type}"`
999
+ );
1000
+ }
1001
+ const { id, attributes, relationships } = resource;
1002
+ return {
1003
+ id,
1004
+ delegatingPartyId: relationships?.delegatingParty?.data?.id ?? "",
1005
+ delegatedPartyId: relationships?.delegatedParty?.data?.id ?? "",
1006
+ delegatingPartyName: attributes.delegatingPartyName != null ? String(attributes.delegatingPartyName) : void 0,
1007
+ delegatedPartyName: attributes.delegatedPartyName != null ? String(attributes.delegatedPartyName) : void 0,
1008
+ delegatingPartyEmail: attributes.delegatingPartyEmail != null ? String(attributes.delegatingPartyEmail) : void 0,
1009
+ delegatedPartyEmail: attributes.delegatedPartyEmail != null ? String(attributes.delegatedPartyEmail) : void 0,
1010
+ permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
1011
+ sourceType: attributes.sourceType != null ? String(attributes.sourceType) : void 0,
1012
+ sourceId: attributes.sourceId != null ? String(attributes.sourceId) : void 0,
1013
+ expiresAt: attributes.expiresAt != null ? String(attributes.expiresAt) : void 0,
1014
+ status: String(attributes.status),
1015
+ createdAt: String(attributes.createdAt),
1016
+ createdBy: attributes.createdBy != null ? String(attributes.createdBy) : void 0
1017
+ };
1018
+ }
1019
+ function unwrapDelegation(response) {
1020
+ if (!response?.data) {
1021
+ throw new NaturalError(
1022
+ 'Unexpected response format: missing "data" field in delegation response'
1023
+ );
1024
+ }
1025
+ return unwrapDelegationResource(response.data);
1026
+ }
1027
+ function unwrapDelegationList(response) {
1028
+ if (!response?.data || !Array.isArray(response.data)) {
1029
+ throw new NaturalError(
1030
+ 'Unexpected response format: missing "data" array in delegation list response'
1031
+ );
1032
+ }
1033
+ const delegations = response.data.map(unwrapDelegationResource);
1034
+ const pagination = response.meta?.pagination ?? {};
1035
+ return {
1036
+ delegations,
1037
+ hasMore: pagination.hasMore ?? false,
1038
+ nextCursor: pagination.nextCursor ?? null
1039
+ };
1040
+ }
944
1041
  var DelegationsResource = class extends BaseResource {
945
1042
  /**
946
1043
  * List delegations with optional filters.
@@ -949,7 +1046,7 @@ var DelegationsResource = class extends BaseResource {
949
1046
  * @returns DelegationListResponse with list of delegations
950
1047
  */
951
1048
  async list(params) {
952
- return this.http.get("/delegations", {
1049
+ const response = await this.http.get("/delegations", {
953
1050
  params: {
954
1051
  status: params?.status,
955
1052
  delegatingPartyId: params?.delegatingPartyId,
@@ -958,6 +1055,7 @@ var DelegationsResource = class extends BaseResource {
958
1055
  cursor: params?.cursor
959
1056
  }
960
1057
  });
1058
+ return unwrapDelegationList(response);
961
1059
  }
962
1060
  /**
963
1061
  * Get delegation by ID.
@@ -966,7 +1064,8 @@ var DelegationsResource = class extends BaseResource {
966
1064
  * @returns Delegation details
967
1065
  */
968
1066
  async get(delegationId) {
969
- return this.http.get(`/delegations/${delegationId}`);
1067
+ const response = await this.http.get(`/delegations/${delegationId}`);
1068
+ return unwrapDelegation(response);
970
1069
  }
971
1070
  /**
972
1071
  * Update an existing delegation.
@@ -976,11 +1075,15 @@ var DelegationsResource = class extends BaseResource {
976
1075
  * @returns Updated Delegation
977
1076
  */
978
1077
  async update(delegationId, params) {
979
- const body = {};
980
- if (params.status !== void 0) body["status"] = params.status;
981
- if (params.permissions !== void 0) body["permissions"] = params.permissions;
982
- if (params.expiresAt !== void 0) body["expiresAt"] = params.expiresAt;
983
- return this.http.put(`/delegations/${delegationId}`, { body });
1078
+ const attributes = {};
1079
+ if (params.status !== void 0) attributes["status"] = params.status;
1080
+ if (params.permissions !== void 0) attributes["permissions"] = params.permissions;
1081
+ if (params.expiresAt !== void 0) attributes["expiresAt"] = params.expiresAt;
1082
+ const body = { data: { attributes } };
1083
+ const response = await this.http.put(`/delegations/${delegationId}`, {
1084
+ body
1085
+ });
1086
+ return unwrapDelegation(response);
984
1087
  }
985
1088
  /**
986
1089
  * Revoke a delegation (soft delete by setting status to REVOKED).
@@ -994,6 +1097,41 @@ var DelegationsResource = class extends BaseResource {
994
1097
  };
995
1098
 
996
1099
  // src/resources/customers.ts
1100
+ function unwrapCustomerResource(resource) {
1101
+ if (resource.type !== "customer" || !resource.attributes) {
1102
+ throw new NaturalError(
1103
+ `Unexpected resource format: expected type "customer", got "${resource.type}"`
1104
+ );
1105
+ }
1106
+ const { id, attributes, relationships } = resource;
1107
+ return {
1108
+ party: {
1109
+ id,
1110
+ type: String(attributes.partyType),
1111
+ legalName: attributes.legalName != null ? String(attributes.legalName) : void 0,
1112
+ displayName: attributes.displayName != null ? String(attributes.displayName) : void 0,
1113
+ status: attributes.partyStatus != null ? String(attributes.partyStatus) : void 0
1114
+ },
1115
+ delegationId: relationships?.delegation?.data?.id ?? "",
1116
+ permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
1117
+ delegationStatus: String(attributes.delegationStatus),
1118
+ createdAt: String(attributes.createdAt)
1119
+ };
1120
+ }
1121
+ function unwrapCustomerList(response) {
1122
+ if (!response?.data || !Array.isArray(response.data)) {
1123
+ throw new NaturalError(
1124
+ 'Unexpected response format: missing "data" array in customer list response'
1125
+ );
1126
+ }
1127
+ const items = response.data.map(unwrapCustomerResource);
1128
+ const pagination = response.meta?.pagination ?? {};
1129
+ return {
1130
+ items,
1131
+ hasMore: pagination.hasMore ?? false,
1132
+ nextCursor: pagination.nextCursor ?? null
1133
+ };
1134
+ }
997
1135
  var CustomersResource = class extends BaseResource {
998
1136
  /**
999
1137
  * List customers onboarded by the partner via delegation.
@@ -1002,12 +1140,13 @@ var CustomersResource = class extends BaseResource {
1002
1140
  * @returns CustomerListResponse with items, hasMore, nextCursor
1003
1141
  */
1004
1142
  async list(params) {
1005
- return this.http.get("/customers", {
1143
+ const response = await this.http.get("/customers", {
1006
1144
  params: {
1007
1145
  limit: params?.limit,
1008
1146
  cursor: params?.cursor
1009
1147
  }
1010
1148
  });
1149
+ return unwrapCustomerList(response);
1011
1150
  }
1012
1151
  };
1013
1152