@naturalpay/sdk 0.0.3 → 0.0.5
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/README.md +1 -1
- package/dist/index.cjs +205 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +205 -27
- package/dist/index.js.map +1 -1
- package/dist/mcp/cli.cjs +252 -50
- package/dist/mcp/cli.cjs.map +1 -1
- package/dist/mcp/cli.js +252 -50
- package/dist/mcp/cli.js.map +1 -1
- package/dist/mcp/index.cjs +251 -49
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.cts +7 -3
- package/dist/mcp/index.d.ts +7 -3
- package/dist/mcp/index.js +251 -49
- package/dist/mcp/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -210,7 +210,7 @@ npx naturalpay mcp serve --transport http --port 8080
|
|
|
210
210
|
```typescript
|
|
211
211
|
import { createServer } from 'naturalpay/mcp';
|
|
212
212
|
|
|
213
|
-
const server = createServer('pk_sandbox_xxx');
|
|
213
|
+
const server = createServer({ apiKey: 'pk_sandbox_xxx' });
|
|
214
214
|
|
|
215
215
|
// Start with stdio
|
|
216
216
|
server.start({ transportType: 'stdio' });
|
package/dist/index.cjs
CHANGED
|
@@ -298,6 +298,12 @@ function logToolCall(logger2, toolName, options) {
|
|
|
298
298
|
logger2.info(`Tool call: ${toolName}`, extra);
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
|
+
var toolCallStorage = new async_hooks.AsyncLocalStorage();
|
|
302
|
+
function getToolCallHeader() {
|
|
303
|
+
const data = toolCallStorage.getStore();
|
|
304
|
+
if (!data) return void 0;
|
|
305
|
+
return btoa(JSON.stringify(data));
|
|
306
|
+
}
|
|
301
307
|
|
|
302
308
|
// src/http.ts
|
|
303
309
|
var logger = getLogger("http");
|
|
@@ -531,9 +537,15 @@ var HTTPClient = class {
|
|
|
531
537
|
const headers = {
|
|
532
538
|
Authorization: `Bearer ${jwt}`,
|
|
533
539
|
"Content-Type": "application/json",
|
|
534
|
-
"User-Agent": `naturalpay-ts/${SDK_VERSION2}
|
|
535
|
-
...options?.headers
|
|
540
|
+
"User-Agent": `naturalpay-ts/${SDK_VERSION2}`
|
|
536
541
|
};
|
|
542
|
+
const toolCallHeader = getToolCallHeader();
|
|
543
|
+
if (toolCallHeader) {
|
|
544
|
+
headers["X-Tool-Call"] = toolCallHeader;
|
|
545
|
+
}
|
|
546
|
+
if (options?.headers) {
|
|
547
|
+
Object.assign(headers, options.headers);
|
|
548
|
+
}
|
|
537
549
|
const response = await fetch(url, {
|
|
538
550
|
method,
|
|
539
551
|
headers,
|
|
@@ -649,9 +661,16 @@ var PaymentsResource = class extends BaseResource {
|
|
|
649
661
|
};
|
|
650
662
|
if (params.memo) attributes["description"] = params.memo;
|
|
651
663
|
const body = { data: { attributes } };
|
|
664
|
+
const headers = { "Idempotency-Key": idempotencyKey };
|
|
665
|
+
if (params.agentId) {
|
|
666
|
+
headers["X-Agent-ID"] = params.agentId;
|
|
667
|
+
}
|
|
668
|
+
if (params.instanceId) {
|
|
669
|
+
headers["X-Instance-ID"] = params.instanceId;
|
|
670
|
+
}
|
|
652
671
|
const response = await this.http.post("/payments", {
|
|
653
672
|
body,
|
|
654
|
-
headers
|
|
673
|
+
headers
|
|
655
674
|
});
|
|
656
675
|
return unwrapPayment(response);
|
|
657
676
|
}
|
|
@@ -661,8 +680,14 @@ var PaymentsResource = class extends BaseResource {
|
|
|
661
680
|
* @param transferId - The transfer ID to look up
|
|
662
681
|
* @returns Payment object with current status
|
|
663
682
|
*/
|
|
664
|
-
async retrieve(transferId) {
|
|
665
|
-
const
|
|
683
|
+
async retrieve(transferId, options) {
|
|
684
|
+
const headers = {};
|
|
685
|
+
if (options?.instanceId) {
|
|
686
|
+
headers["X-Instance-ID"] = options.instanceId;
|
|
687
|
+
}
|
|
688
|
+
const response = await this.http.get(`/payments/${transferId}`, {
|
|
689
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
690
|
+
});
|
|
666
691
|
return unwrapPayment(response);
|
|
667
692
|
}
|
|
668
693
|
};
|
|
@@ -688,14 +713,71 @@ function unwrapBalance(response) {
|
|
|
688
713
|
pendingClaimCount: attributes.pendingClaimCount != null ? Number(attributes.pendingClaimCount) : void 0
|
|
689
714
|
};
|
|
690
715
|
}
|
|
716
|
+
function unwrapDeposit(response) {
|
|
717
|
+
if (!response?.data) {
|
|
718
|
+
throw new NaturalError('Unexpected response format: missing "data" field in deposit response');
|
|
719
|
+
}
|
|
720
|
+
const { data } = response;
|
|
721
|
+
if (data.type !== "deposit" || !data.attributes) {
|
|
722
|
+
throw new NaturalError(
|
|
723
|
+
`Unexpected resource format: expected type "deposit", got "${data.type}"`
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
const { id, attributes } = data;
|
|
727
|
+
return {
|
|
728
|
+
transferId: id ?? void 0,
|
|
729
|
+
status: String(attributes.status),
|
|
730
|
+
amount: attributes.amount != null ? String(attributes.amount) : "",
|
|
731
|
+
currency: String(attributes.currency),
|
|
732
|
+
estimatedSettlement: attributes.estimatedSettlement != null ? String(attributes.estimatedSettlement) : void 0,
|
|
733
|
+
error: attributes.error != null ? String(attributes.error) : void 0,
|
|
734
|
+
errorDetails: attributes.errorDetails != null ? String(attributes.errorDetails) : void 0
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
function unwrapWithdrawal(response) {
|
|
738
|
+
if (!response?.data) {
|
|
739
|
+
throw new NaturalError(
|
|
740
|
+
'Unexpected response format: missing "data" field in withdrawal response'
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
const { data } = response;
|
|
744
|
+
if (data.type !== "withdrawal" || !data.attributes) {
|
|
745
|
+
throw new NaturalError(
|
|
746
|
+
`Unexpected resource format: expected type "withdrawal", got "${data.type}"`
|
|
747
|
+
);
|
|
748
|
+
}
|
|
749
|
+
const { id, attributes } = data;
|
|
750
|
+
return {
|
|
751
|
+
transferId: id ?? void 0,
|
|
752
|
+
instructionId: attributes.instructionId != null ? String(attributes.instructionId) : void 0,
|
|
753
|
+
status: String(attributes.status),
|
|
754
|
+
amount: attributes.amount != null ? String(attributes.amount) : "",
|
|
755
|
+
currency: String(attributes.currency),
|
|
756
|
+
estimatedSettlement: attributes.estimatedSettlement != null ? String(attributes.estimatedSettlement) : void 0,
|
|
757
|
+
kycRequired: Boolean(attributes.kycRequired),
|
|
758
|
+
kycStatus: attributes.kycStatus != null ? String(attributes.kycStatus) : void 0,
|
|
759
|
+
kycSessionUrl: attributes.kycSessionUrl != null ? String(attributes.kycSessionUrl) : void 0,
|
|
760
|
+
mfaRequired: Boolean(attributes.mfaRequired),
|
|
761
|
+
mfaChallengeId: attributes.mfaChallengeId != null ? String(attributes.mfaChallengeId) : void 0,
|
|
762
|
+
mfaExpiresAt: attributes.mfaExpiresAt != null ? String(attributes.mfaExpiresAt) : void 0,
|
|
763
|
+
error: attributes.error != null ? String(attributes.error) : void 0,
|
|
764
|
+
errorDetails: attributes.errorDetails != null ? String(attributes.errorDetails) : void 0
|
|
765
|
+
};
|
|
766
|
+
}
|
|
691
767
|
var WalletResource = class extends BaseResource {
|
|
692
768
|
/**
|
|
693
769
|
* Get current wallet balance.
|
|
694
770
|
*
|
|
695
771
|
* @returns AccountBalance with available, current, pending amounts
|
|
696
772
|
*/
|
|
697
|
-
async balance() {
|
|
698
|
-
const
|
|
773
|
+
async balance(options) {
|
|
774
|
+
const headers = {};
|
|
775
|
+
if (options?.instanceId) {
|
|
776
|
+
headers["X-Instance-ID"] = options.instanceId;
|
|
777
|
+
}
|
|
778
|
+
const response = await this.http.get("/wallet/balance", {
|
|
779
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
780
|
+
});
|
|
699
781
|
return unwrapBalance(response);
|
|
700
782
|
}
|
|
701
783
|
/**
|
|
@@ -705,18 +787,20 @@ var WalletResource = class extends BaseResource {
|
|
|
705
787
|
* @returns DepositResponse with transfer status
|
|
706
788
|
*/
|
|
707
789
|
async deposit(params) {
|
|
708
|
-
const
|
|
790
|
+
const attributes = {
|
|
709
791
|
amount: params.amount,
|
|
710
792
|
currency: params.currency ?? "USD",
|
|
711
793
|
paymentInstrumentId: params.paymentInstrumentId
|
|
712
794
|
};
|
|
713
795
|
if (params.description) {
|
|
714
|
-
|
|
796
|
+
attributes["description"] = params.description;
|
|
715
797
|
}
|
|
716
|
-
|
|
798
|
+
const body = { data: { attributes } };
|
|
799
|
+
const response = await this.http.post("/wallet/deposit", {
|
|
717
800
|
body,
|
|
718
801
|
headers: { "Idempotency-Key": params.idempotencyKey }
|
|
719
802
|
});
|
|
803
|
+
return unwrapDeposit(response);
|
|
720
804
|
}
|
|
721
805
|
/**
|
|
722
806
|
* Initiate a withdrawal to a linked bank account.
|
|
@@ -725,21 +809,19 @@ var WalletResource = class extends BaseResource {
|
|
|
725
809
|
* @returns WithdrawResponse with transfer status (may require KYC/MFA)
|
|
726
810
|
*/
|
|
727
811
|
async withdraw(params) {
|
|
728
|
-
const
|
|
812
|
+
const attributes = {
|
|
729
813
|
amount: params.amount,
|
|
730
814
|
currency: params.currency ?? "USD",
|
|
731
815
|
paymentInstrumentId: params.paymentInstrumentId
|
|
732
816
|
};
|
|
733
|
-
if (params.description)
|
|
734
|
-
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
body["walletId"] = params.walletId;
|
|
738
|
-
}
|
|
739
|
-
return this.http.post("/wallet/withdraw", {
|
|
817
|
+
if (params.description) attributes["description"] = params.description;
|
|
818
|
+
if (params.walletId) attributes["walletId"] = params.walletId;
|
|
819
|
+
const body = { data: { attributes } };
|
|
820
|
+
const response = await this.http.post("/wallet/withdraw", {
|
|
740
821
|
body,
|
|
741
822
|
headers: { "Idempotency-Key": params.idempotencyKey }
|
|
742
823
|
});
|
|
824
|
+
return unwrapWithdrawal(response);
|
|
743
825
|
}
|
|
744
826
|
};
|
|
745
827
|
|
|
@@ -789,6 +871,9 @@ var TransactionsResource = class extends BaseResource {
|
|
|
789
871
|
if (params?.customerPartyId) {
|
|
790
872
|
headers["X-On-Behalf-Of"] = params.customerPartyId;
|
|
791
873
|
}
|
|
874
|
+
if (params?.instanceId) {
|
|
875
|
+
headers["X-Instance-ID"] = params.instanceId;
|
|
876
|
+
}
|
|
792
877
|
const response = await this.http.get("/transactions", {
|
|
793
878
|
params: {
|
|
794
879
|
limit: params?.limit ?? 50,
|
|
@@ -860,13 +945,18 @@ var AgentsResource = class extends BaseResource {
|
|
|
860
945
|
* @returns AgentListResponse with list of agents
|
|
861
946
|
*/
|
|
862
947
|
async list(params) {
|
|
948
|
+
const headers = {};
|
|
949
|
+
if (params?.instanceId) {
|
|
950
|
+
headers["X-Instance-ID"] = params.instanceId;
|
|
951
|
+
}
|
|
863
952
|
const response = await this.http.get("/agents", {
|
|
864
953
|
params: {
|
|
865
954
|
status: params?.status,
|
|
866
955
|
partyId: params?.partyId,
|
|
867
956
|
limit: params?.limit ?? 50,
|
|
868
957
|
cursor: params?.cursor
|
|
869
|
-
}
|
|
958
|
+
},
|
|
959
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
870
960
|
});
|
|
871
961
|
return unwrapAgentList(response);
|
|
872
962
|
}
|
|
@@ -941,6 +1031,52 @@ var AgentsResource = class extends BaseResource {
|
|
|
941
1031
|
};
|
|
942
1032
|
|
|
943
1033
|
// src/resources/delegations.ts
|
|
1034
|
+
function unwrapDelegationResource(resource) {
|
|
1035
|
+
if (resource.type !== "delegation" || !resource.attributes) {
|
|
1036
|
+
throw new NaturalError(
|
|
1037
|
+
`Unexpected resource format: expected type "delegation", got "${resource.type}"`
|
|
1038
|
+
);
|
|
1039
|
+
}
|
|
1040
|
+
const { id, attributes, relationships } = resource;
|
|
1041
|
+
return {
|
|
1042
|
+
id,
|
|
1043
|
+
delegatingPartyId: relationships?.delegatingParty?.data?.id ?? "",
|
|
1044
|
+
delegatedPartyId: relationships?.delegatedParty?.data?.id ?? "",
|
|
1045
|
+
delegatingPartyName: attributes.delegatingPartyName != null ? String(attributes.delegatingPartyName) : void 0,
|
|
1046
|
+
delegatedPartyName: attributes.delegatedPartyName != null ? String(attributes.delegatedPartyName) : void 0,
|
|
1047
|
+
delegatingPartyEmail: attributes.delegatingPartyEmail != null ? String(attributes.delegatingPartyEmail) : void 0,
|
|
1048
|
+
delegatedPartyEmail: attributes.delegatedPartyEmail != null ? String(attributes.delegatedPartyEmail) : void 0,
|
|
1049
|
+
permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
|
|
1050
|
+
sourceType: attributes.sourceType != null ? String(attributes.sourceType) : void 0,
|
|
1051
|
+
sourceId: attributes.sourceId != null ? String(attributes.sourceId) : void 0,
|
|
1052
|
+
expiresAt: attributes.expiresAt != null ? String(attributes.expiresAt) : void 0,
|
|
1053
|
+
status: String(attributes.status),
|
|
1054
|
+
createdAt: String(attributes.createdAt),
|
|
1055
|
+
createdBy: attributes.createdBy != null ? String(attributes.createdBy) : void 0
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
function unwrapDelegation(response) {
|
|
1059
|
+
if (!response?.data) {
|
|
1060
|
+
throw new NaturalError(
|
|
1061
|
+
'Unexpected response format: missing "data" field in delegation response'
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
return unwrapDelegationResource(response.data);
|
|
1065
|
+
}
|
|
1066
|
+
function unwrapDelegationList(response) {
|
|
1067
|
+
if (!response?.data || !Array.isArray(response.data)) {
|
|
1068
|
+
throw new NaturalError(
|
|
1069
|
+
'Unexpected response format: missing "data" array in delegation list response'
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
const delegations = response.data.map(unwrapDelegationResource);
|
|
1073
|
+
const pagination = response.meta?.pagination ?? {};
|
|
1074
|
+
return {
|
|
1075
|
+
delegations,
|
|
1076
|
+
hasMore: pagination.hasMore ?? false,
|
|
1077
|
+
nextCursor: pagination.nextCursor ?? null
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
944
1080
|
var DelegationsResource = class extends BaseResource {
|
|
945
1081
|
/**
|
|
946
1082
|
* List delegations with optional filters.
|
|
@@ -949,7 +1085,7 @@ var DelegationsResource = class extends BaseResource {
|
|
|
949
1085
|
* @returns DelegationListResponse with list of delegations
|
|
950
1086
|
*/
|
|
951
1087
|
async list(params) {
|
|
952
|
-
|
|
1088
|
+
const response = await this.http.get("/delegations", {
|
|
953
1089
|
params: {
|
|
954
1090
|
status: params?.status,
|
|
955
1091
|
delegatingPartyId: params?.delegatingPartyId,
|
|
@@ -958,6 +1094,7 @@ var DelegationsResource = class extends BaseResource {
|
|
|
958
1094
|
cursor: params?.cursor
|
|
959
1095
|
}
|
|
960
1096
|
});
|
|
1097
|
+
return unwrapDelegationList(response);
|
|
961
1098
|
}
|
|
962
1099
|
/**
|
|
963
1100
|
* Get delegation by ID.
|
|
@@ -966,7 +1103,8 @@ var DelegationsResource = class extends BaseResource {
|
|
|
966
1103
|
* @returns Delegation details
|
|
967
1104
|
*/
|
|
968
1105
|
async get(delegationId) {
|
|
969
|
-
|
|
1106
|
+
const response = await this.http.get(`/delegations/${delegationId}`);
|
|
1107
|
+
return unwrapDelegation(response);
|
|
970
1108
|
}
|
|
971
1109
|
/**
|
|
972
1110
|
* Update an existing delegation.
|
|
@@ -976,11 +1114,15 @@ var DelegationsResource = class extends BaseResource {
|
|
|
976
1114
|
* @returns Updated Delegation
|
|
977
1115
|
*/
|
|
978
1116
|
async update(delegationId, params) {
|
|
979
|
-
const
|
|
980
|
-
if (params.status !== void 0)
|
|
981
|
-
if (params.permissions !== void 0)
|
|
982
|
-
if (params.expiresAt !== void 0)
|
|
983
|
-
|
|
1117
|
+
const attributes = {};
|
|
1118
|
+
if (params.status !== void 0) attributes["status"] = params.status;
|
|
1119
|
+
if (params.permissions !== void 0) attributes["permissions"] = params.permissions;
|
|
1120
|
+
if (params.expiresAt !== void 0) attributes["expiresAt"] = params.expiresAt;
|
|
1121
|
+
const body = { data: { attributes } };
|
|
1122
|
+
const response = await this.http.put(`/delegations/${delegationId}`, {
|
|
1123
|
+
body
|
|
1124
|
+
});
|
|
1125
|
+
return unwrapDelegation(response);
|
|
984
1126
|
}
|
|
985
1127
|
/**
|
|
986
1128
|
* Revoke a delegation (soft delete by setting status to REVOKED).
|
|
@@ -994,6 +1136,41 @@ var DelegationsResource = class extends BaseResource {
|
|
|
994
1136
|
};
|
|
995
1137
|
|
|
996
1138
|
// src/resources/customers.ts
|
|
1139
|
+
function unwrapCustomerResource(resource) {
|
|
1140
|
+
if (resource.type !== "customer" || !resource.attributes) {
|
|
1141
|
+
throw new NaturalError(
|
|
1142
|
+
`Unexpected resource format: expected type "customer", got "${resource.type}"`
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
const { id, attributes, relationships } = resource;
|
|
1146
|
+
return {
|
|
1147
|
+
party: {
|
|
1148
|
+
id,
|
|
1149
|
+
type: String(attributes.partyType),
|
|
1150
|
+
legalName: attributes.legalName != null ? String(attributes.legalName) : void 0,
|
|
1151
|
+
displayName: attributes.displayName != null ? String(attributes.displayName) : void 0,
|
|
1152
|
+
status: attributes.partyStatus != null ? String(attributes.partyStatus) : void 0
|
|
1153
|
+
},
|
|
1154
|
+
delegationId: relationships?.delegation?.data?.id ?? "",
|
|
1155
|
+
permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
|
|
1156
|
+
delegationStatus: String(attributes.delegationStatus),
|
|
1157
|
+
createdAt: String(attributes.createdAt)
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
function unwrapCustomerList(response) {
|
|
1161
|
+
if (!response?.data || !Array.isArray(response.data)) {
|
|
1162
|
+
throw new NaturalError(
|
|
1163
|
+
'Unexpected response format: missing "data" array in customer list response'
|
|
1164
|
+
);
|
|
1165
|
+
}
|
|
1166
|
+
const items = response.data.map(unwrapCustomerResource);
|
|
1167
|
+
const pagination = response.meta?.pagination ?? {};
|
|
1168
|
+
return {
|
|
1169
|
+
items,
|
|
1170
|
+
hasMore: pagination.hasMore ?? false,
|
|
1171
|
+
nextCursor: pagination.nextCursor ?? null
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
997
1174
|
var CustomersResource = class extends BaseResource {
|
|
998
1175
|
/**
|
|
999
1176
|
* List customers onboarded by the partner via delegation.
|
|
@@ -1002,12 +1179,13 @@ var CustomersResource = class extends BaseResource {
|
|
|
1002
1179
|
* @returns CustomerListResponse with items, hasMore, nextCursor
|
|
1003
1180
|
*/
|
|
1004
1181
|
async list(params) {
|
|
1005
|
-
|
|
1182
|
+
const response = await this.http.get("/customers", {
|
|
1006
1183
|
params: {
|
|
1007
1184
|
limit: params?.limit,
|
|
1008
1185
|
cursor: params?.cursor
|
|
1009
1186
|
}
|
|
1010
1187
|
});
|
|
1188
|
+
return unwrapCustomerList(response);
|
|
1011
1189
|
}
|
|
1012
1190
|
};
|
|
1013
1191
|
|