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