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