@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.
- 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/index.cjs
CHANGED
|
@@ -585,6 +585,32 @@ var BaseResource = class {
|
|
|
585
585
|
|
|
586
586
|
// src/resources/payments.ts
|
|
587
587
|
var IDEMPOTENCY_WINDOW_SECONDS = 300;
|
|
588
|
+
function unwrapPayment(response) {
|
|
589
|
+
if (!response?.data) {
|
|
590
|
+
throw new NaturalError('Unexpected response format: missing "data" field in payment response');
|
|
591
|
+
}
|
|
592
|
+
const { data } = response;
|
|
593
|
+
if (data.type !== "payment" || !data.attributes) {
|
|
594
|
+
throw new NaturalError(
|
|
595
|
+
`Unexpected resource format: expected type "payment", got "${data.type}"`
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
const { id, attributes, relationships } = data;
|
|
599
|
+
const description = attributes.description != null ? String(attributes.description) : void 0;
|
|
600
|
+
return {
|
|
601
|
+
transferId: id,
|
|
602
|
+
status: String(attributes.status),
|
|
603
|
+
amount: String(attributes.amount),
|
|
604
|
+
currency: String(attributes.currency),
|
|
605
|
+
description,
|
|
606
|
+
memo: description,
|
|
607
|
+
createdAt: attributes.createdAt != null ? String(attributes.createdAt) : void 0,
|
|
608
|
+
updatedAt: attributes.updatedAt != null ? String(attributes.updatedAt) : void 0,
|
|
609
|
+
claimLink: attributes.claimLink != null ? String(attributes.claimLink) : void 0,
|
|
610
|
+
counterpartyPartyId: relationships?.counterparty?.data?.id,
|
|
611
|
+
customerPartyId: relationships?.customerParty?.data?.id
|
|
612
|
+
};
|
|
613
|
+
}
|
|
588
614
|
var PaymentsResource = class extends BaseResource {
|
|
589
615
|
/**
|
|
590
616
|
* Generate idempotency key based on payment details + time window.
|
|
@@ -615,20 +641,19 @@ var PaymentsResource = class extends BaseResource {
|
|
|
615
641
|
}
|
|
616
642
|
const recipient = params.recipientEmail ?? params.recipientPhone ?? params.recipientPartyId;
|
|
617
643
|
const idempotencyKey = params.idempotencyKey ?? this.generateIdempotencyKey(recipient, params.amount, params.memo);
|
|
618
|
-
const
|
|
619
|
-
amount: params.amount
|
|
644
|
+
const attributes = {
|
|
645
|
+
amount: String(params.amount),
|
|
646
|
+
currency: "USD",
|
|
647
|
+
counterparty: recipient,
|
|
648
|
+
customerPartyId: params.customerPartyId
|
|
620
649
|
};
|
|
621
|
-
if (params.
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
if (params.memo) body["memo"] = params.memo;
|
|
625
|
-
if (params.agentId) body["agentId"] = params.agentId;
|
|
626
|
-
if (params.customerPartyId) body["customerPartyId"] = params.customerPartyId;
|
|
627
|
-
if (params.instanceId) body["instanceId"] = params.instanceId;
|
|
628
|
-
return this.http.post("/payments/initiate", {
|
|
650
|
+
if (params.memo) attributes["description"] = params.memo;
|
|
651
|
+
const body = { data: { attributes } };
|
|
652
|
+
const response = await this.http.post("/payments", {
|
|
629
653
|
body,
|
|
630
654
|
headers: { "Idempotency-Key": idempotencyKey }
|
|
631
655
|
});
|
|
656
|
+
return unwrapPayment(response);
|
|
632
657
|
}
|
|
633
658
|
/**
|
|
634
659
|
* Get payment status by transfer ID.
|
|
@@ -637,20 +662,83 @@ var PaymentsResource = class extends BaseResource {
|
|
|
637
662
|
* @returns Payment object with current status
|
|
638
663
|
*/
|
|
639
664
|
async retrieve(transferId) {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
/**
|
|
643
|
-
* Cancel a pending payment.
|
|
644
|
-
*
|
|
645
|
-
* @param transferId - The transfer ID to cancel
|
|
646
|
-
* @returns Cancellation result with status and message
|
|
647
|
-
*/
|
|
648
|
-
async cancel(transferId) {
|
|
649
|
-
return this.http.post(`/payments/${transferId}/cancel`);
|
|
665
|
+
const response = await this.http.get(`/payments/${transferId}`);
|
|
666
|
+
return unwrapPayment(response);
|
|
650
667
|
}
|
|
651
668
|
};
|
|
652
669
|
|
|
653
670
|
// src/resources/wallet.ts
|
|
671
|
+
function unwrapBalance(response) {
|
|
672
|
+
if (!response?.data) {
|
|
673
|
+
throw new NaturalError(
|
|
674
|
+
'Unexpected response format: missing "data" field in wallet balance response'
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
const { data } = response;
|
|
678
|
+
if (data.type !== "wallet_balance" || !data.attributes) {
|
|
679
|
+
throw new NaturalError(
|
|
680
|
+
`Unexpected resource format: expected type "wallet_balance", got "${data.type}"`
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
const { id, attributes } = data;
|
|
684
|
+
return {
|
|
685
|
+
walletId: id,
|
|
686
|
+
balances: attributes.balances,
|
|
687
|
+
pendingClaimAmountMinor: attributes.pendingClaimAmountMinor != null ? Number(attributes.pendingClaimAmountMinor) : void 0,
|
|
688
|
+
pendingClaimCount: attributes.pendingClaimCount != null ? Number(attributes.pendingClaimCount) : void 0
|
|
689
|
+
};
|
|
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
|
+
}
|
|
654
742
|
var WalletResource = class extends BaseResource {
|
|
655
743
|
/**
|
|
656
744
|
* Get current wallet balance.
|
|
@@ -658,7 +746,8 @@ var WalletResource = class extends BaseResource {
|
|
|
658
746
|
* @returns AccountBalance with available, current, pending amounts
|
|
659
747
|
*/
|
|
660
748
|
async balance() {
|
|
661
|
-
|
|
749
|
+
const response = await this.http.get("/wallet/balance");
|
|
750
|
+
return unwrapBalance(response);
|
|
662
751
|
}
|
|
663
752
|
/**
|
|
664
753
|
* Initiate a deposit from a linked bank account.
|
|
@@ -667,18 +756,20 @@ var WalletResource = class extends BaseResource {
|
|
|
667
756
|
* @returns DepositResponse with transfer status
|
|
668
757
|
*/
|
|
669
758
|
async deposit(params) {
|
|
670
|
-
const
|
|
759
|
+
const attributes = {
|
|
671
760
|
amount: params.amount,
|
|
672
761
|
currency: params.currency ?? "USD",
|
|
673
762
|
paymentInstrumentId: params.paymentInstrumentId
|
|
674
763
|
};
|
|
675
764
|
if (params.description) {
|
|
676
|
-
|
|
765
|
+
attributes["description"] = params.description;
|
|
677
766
|
}
|
|
678
|
-
|
|
767
|
+
const body = { data: { attributes } };
|
|
768
|
+
const response = await this.http.post("/wallet/deposit", {
|
|
679
769
|
body,
|
|
680
770
|
headers: { "Idempotency-Key": params.idempotencyKey }
|
|
681
771
|
});
|
|
772
|
+
return unwrapDeposit(response);
|
|
682
773
|
}
|
|
683
774
|
/**
|
|
684
775
|
* Initiate a withdrawal to a linked bank account.
|
|
@@ -687,28 +778,59 @@ var WalletResource = class extends BaseResource {
|
|
|
687
778
|
* @returns WithdrawResponse with transfer status (may require KYC/MFA)
|
|
688
779
|
*/
|
|
689
780
|
async withdraw(params) {
|
|
690
|
-
const
|
|
781
|
+
const attributes = {
|
|
691
782
|
amount: params.amount,
|
|
692
783
|
currency: params.currency ?? "USD",
|
|
693
784
|
paymentInstrumentId: params.paymentInstrumentId
|
|
694
785
|
};
|
|
695
|
-
if (params.description)
|
|
696
|
-
|
|
697
|
-
}
|
|
698
|
-
|
|
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", {
|
|
699
790
|
body,
|
|
700
791
|
headers: { "Idempotency-Key": params.idempotencyKey }
|
|
701
792
|
});
|
|
793
|
+
return unwrapWithdrawal(response);
|
|
702
794
|
}
|
|
703
795
|
};
|
|
704
796
|
|
|
705
797
|
// src/resources/transactions.ts
|
|
798
|
+
function unwrapTransactionResource(resource) {
|
|
799
|
+
if (resource.type !== "transaction" || !resource.attributes) {
|
|
800
|
+
throw new NaturalError(
|
|
801
|
+
`Unexpected resource format: expected type "transaction", got "${resource.type}"`
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
const { id, attributes, relationships } = resource;
|
|
805
|
+
return {
|
|
806
|
+
transactionId: id,
|
|
807
|
+
amount: String(attributes.amount),
|
|
808
|
+
currency: String(attributes.currency),
|
|
809
|
+
status: String(attributes.status),
|
|
810
|
+
description: attributes.description != null ? String(attributes.description) : void 0,
|
|
811
|
+
memo: attributes.memo != null ? String(attributes.memo) : void 0,
|
|
812
|
+
createdAt: String(attributes.createdAt),
|
|
813
|
+
updatedAt: attributes.updatedAt != null ? String(attributes.updatedAt) : void 0,
|
|
814
|
+
isDelegated: Boolean(attributes.isDelegated),
|
|
815
|
+
customerName: attributes.customerName != null ? String(attributes.customerName) : void 0,
|
|
816
|
+
customerAgentId: attributes.customerAgentId != null ? String(attributes.customerAgentId) : void 0,
|
|
817
|
+
senderName: attributes.senderName != null ? String(attributes.senderName) : void 0,
|
|
818
|
+
recipientName: attributes.recipientName != null ? String(attributes.recipientName) : void 0,
|
|
819
|
+
transactionType: String(attributes.transactionType),
|
|
820
|
+
category: String(attributes.category),
|
|
821
|
+
direction: String(attributes.direction),
|
|
822
|
+
sourcePartyId: relationships?.sourceParty?.data?.id,
|
|
823
|
+
destinationPartyId: relationships?.destinationParty?.data?.id,
|
|
824
|
+
sourceWalletId: relationships?.sourceWallet?.data?.id,
|
|
825
|
+
destinationWalletId: relationships?.destinationWallet?.data?.id
|
|
826
|
+
};
|
|
827
|
+
}
|
|
706
828
|
var TransactionsResource = class extends BaseResource {
|
|
707
829
|
/**
|
|
708
830
|
* List recent transactions.
|
|
709
831
|
*
|
|
710
832
|
* @param params - List parameters including agent context
|
|
711
|
-
* @returns
|
|
833
|
+
* @returns TransactionListResponse with transactions and pagination info
|
|
712
834
|
*/
|
|
713
835
|
async list(params) {
|
|
714
836
|
const headers = {};
|
|
@@ -718,20 +840,69 @@ var TransactionsResource = class extends BaseResource {
|
|
|
718
840
|
if (params?.customerPartyId) {
|
|
719
841
|
headers["X-On-Behalf-Of"] = params.customerPartyId;
|
|
720
842
|
}
|
|
721
|
-
const
|
|
843
|
+
const response = await this.http.get("/transactions", {
|
|
722
844
|
params: {
|
|
723
|
-
limit: params?.limit ??
|
|
724
|
-
|
|
725
|
-
customerFilter: params?.customerFilter,
|
|
845
|
+
limit: params?.limit ?? 50,
|
|
846
|
+
cursor: params?.cursor,
|
|
726
847
|
type: params?.type
|
|
727
848
|
},
|
|
728
849
|
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
729
850
|
});
|
|
730
|
-
|
|
851
|
+
if (!response?.data || !Array.isArray(response.data)) {
|
|
852
|
+
throw new NaturalError(
|
|
853
|
+
'Unexpected response format: missing "data" array in transaction list response'
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
const transactions = response.data.map(unwrapTransactionResource);
|
|
857
|
+
const pagination = response.meta?.pagination ?? {};
|
|
858
|
+
return {
|
|
859
|
+
transactions,
|
|
860
|
+
hasMore: pagination.hasMore ?? false,
|
|
861
|
+
nextCursor: pagination.nextCursor ?? null
|
|
862
|
+
};
|
|
731
863
|
}
|
|
732
864
|
};
|
|
733
865
|
|
|
734
866
|
// src/resources/agents.ts
|
|
867
|
+
function unwrapAgentResource(resource) {
|
|
868
|
+
if (resource.type !== "agent" || !resource.attributes) {
|
|
869
|
+
throw new NaturalError(
|
|
870
|
+
`Unexpected resource format: expected type "agent", got "${resource.type}"`
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
const { id, attributes, relationships } = resource;
|
|
874
|
+
return {
|
|
875
|
+
id,
|
|
876
|
+
name: String(attributes.name),
|
|
877
|
+
description: attributes.description != null ? String(attributes.description) : void 0,
|
|
878
|
+
status: String(attributes.status),
|
|
879
|
+
partyId: relationships?.party?.data?.id ?? "",
|
|
880
|
+
createdAt: attributes.createdAt != null ? String(attributes.createdAt) : void 0,
|
|
881
|
+
createdBy: attributes.createdBy != null ? String(attributes.createdBy) : void 0,
|
|
882
|
+
updatedAt: attributes.updatedAt != null ? String(attributes.updatedAt) : void 0,
|
|
883
|
+
updatedBy: attributes.updatedBy != null ? String(attributes.updatedBy) : void 0
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
function unwrapAgent(response) {
|
|
887
|
+
if (!response?.data) {
|
|
888
|
+
throw new NaturalError('Unexpected response format: missing "data" field in agent response');
|
|
889
|
+
}
|
|
890
|
+
return unwrapAgentResource(response.data);
|
|
891
|
+
}
|
|
892
|
+
function unwrapAgentList(response) {
|
|
893
|
+
if (!response?.data || !Array.isArray(response.data)) {
|
|
894
|
+
throw new NaturalError(
|
|
895
|
+
'Unexpected response format: missing "data" array in agent list response'
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
const agents = response.data.map(unwrapAgentResource);
|
|
899
|
+
const pagination = response.meta?.pagination ?? {};
|
|
900
|
+
return {
|
|
901
|
+
agents,
|
|
902
|
+
hasMore: pagination.hasMore ?? false,
|
|
903
|
+
nextCursor: pagination.nextCursor ?? null
|
|
904
|
+
};
|
|
905
|
+
}
|
|
735
906
|
var AgentsResource = class extends BaseResource {
|
|
736
907
|
/**
|
|
737
908
|
* List agents for the partner.
|
|
@@ -740,14 +911,15 @@ var AgentsResource = class extends BaseResource {
|
|
|
740
911
|
* @returns AgentListResponse with list of agents
|
|
741
912
|
*/
|
|
742
913
|
async list(params) {
|
|
743
|
-
|
|
914
|
+
const response = await this.http.get("/agents", {
|
|
744
915
|
params: {
|
|
745
916
|
status: params?.status,
|
|
746
917
|
partyId: params?.partyId,
|
|
747
918
|
limit: params?.limit ?? 50,
|
|
748
|
-
|
|
919
|
+
cursor: params?.cursor
|
|
749
920
|
}
|
|
750
921
|
});
|
|
922
|
+
return unwrapAgentList(response);
|
|
751
923
|
}
|
|
752
924
|
/**
|
|
753
925
|
* Get agent by ID.
|
|
@@ -756,7 +928,8 @@ var AgentsResource = class extends BaseResource {
|
|
|
756
928
|
* @returns Agent details
|
|
757
929
|
*/
|
|
758
930
|
async get(agentId) {
|
|
759
|
-
|
|
931
|
+
const response = await this.http.get(`/agents/${agentId}`);
|
|
932
|
+
return unwrapAgent(response);
|
|
760
933
|
}
|
|
761
934
|
/**
|
|
762
935
|
* Create a new agent.
|
|
@@ -765,21 +938,25 @@ var AgentsResource = class extends BaseResource {
|
|
|
765
938
|
* @returns AgentCreateResponse with created agent details
|
|
766
939
|
*/
|
|
767
940
|
async create(params) {
|
|
768
|
-
const
|
|
769
|
-
name: params.name
|
|
770
|
-
partyId: params.partyId
|
|
941
|
+
const attributes = {
|
|
942
|
+
name: params.name
|
|
771
943
|
};
|
|
772
944
|
if (params.description) {
|
|
773
|
-
|
|
945
|
+
attributes["description"] = params.description;
|
|
946
|
+
}
|
|
947
|
+
if (params.limits) {
|
|
948
|
+
attributes["limits"] = params.limits;
|
|
774
949
|
}
|
|
950
|
+
const body = { data: { attributes } };
|
|
775
951
|
const headers = {};
|
|
776
952
|
if (params.idempotencyKey) {
|
|
777
953
|
headers["Idempotency-Key"] = params.idempotencyKey;
|
|
778
954
|
}
|
|
779
|
-
|
|
955
|
+
const response = await this.http.post("/agents", {
|
|
780
956
|
body,
|
|
781
957
|
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
782
958
|
});
|
|
959
|
+
return unwrapAgent(response);
|
|
783
960
|
}
|
|
784
961
|
/**
|
|
785
962
|
* Update an existing agent.
|
|
@@ -789,18 +966,20 @@ var AgentsResource = class extends BaseResource {
|
|
|
789
966
|
* @returns AgentUpdateResponse with updated agent details
|
|
790
967
|
*/
|
|
791
968
|
async update(agentId, params) {
|
|
792
|
-
const
|
|
793
|
-
if (params.name !== void 0)
|
|
794
|
-
if (params.description !== void 0)
|
|
795
|
-
if (params.status !== void 0)
|
|
969
|
+
const attributes = {};
|
|
970
|
+
if (params.name !== void 0) attributes["name"] = params.name;
|
|
971
|
+
if (params.description !== void 0) attributes["description"] = params.description;
|
|
972
|
+
if (params.status !== void 0) attributes["status"] = params.status;
|
|
973
|
+
const body = { data: { attributes } };
|
|
796
974
|
const headers = {};
|
|
797
975
|
if (params.idempotencyKey) {
|
|
798
976
|
headers["Idempotency-Key"] = params.idempotencyKey;
|
|
799
977
|
}
|
|
800
|
-
|
|
978
|
+
const response = await this.http.put(`/agents/${agentId}`, {
|
|
801
979
|
body,
|
|
802
980
|
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
803
981
|
});
|
|
982
|
+
return unwrapAgent(response);
|
|
804
983
|
}
|
|
805
984
|
/**
|
|
806
985
|
* Delete an agent.
|
|
@@ -813,6 +992,52 @@ var AgentsResource = class extends BaseResource {
|
|
|
813
992
|
};
|
|
814
993
|
|
|
815
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
|
+
}
|
|
816
1041
|
var DelegationsResource = class extends BaseResource {
|
|
817
1042
|
/**
|
|
818
1043
|
* List delegations with optional filters.
|
|
@@ -821,13 +1046,16 @@ var DelegationsResource = class extends BaseResource {
|
|
|
821
1046
|
* @returns DelegationListResponse with list of delegations
|
|
822
1047
|
*/
|
|
823
1048
|
async list(params) {
|
|
824
|
-
|
|
1049
|
+
const response = await this.http.get("/delegations", {
|
|
825
1050
|
params: {
|
|
826
1051
|
status: params?.status,
|
|
827
1052
|
delegatingPartyId: params?.delegatingPartyId,
|
|
828
|
-
delegatedPartyId: params?.delegatedPartyId
|
|
1053
|
+
delegatedPartyId: params?.delegatedPartyId,
|
|
1054
|
+
limit: params?.limit ?? 50,
|
|
1055
|
+
cursor: params?.cursor
|
|
829
1056
|
}
|
|
830
1057
|
});
|
|
1058
|
+
return unwrapDelegationList(response);
|
|
831
1059
|
}
|
|
832
1060
|
/**
|
|
833
1061
|
* Get delegation by ID.
|
|
@@ -836,31 +1064,8 @@ var DelegationsResource = class extends BaseResource {
|
|
|
836
1064
|
* @returns Delegation details
|
|
837
1065
|
*/
|
|
838
1066
|
async get(delegationId) {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
/**
|
|
842
|
-
* Create a new delegation (party-to-party trust relationship).
|
|
843
|
-
*
|
|
844
|
-
* @param params - Delegation creation parameters
|
|
845
|
-
* @returns Created Delegation
|
|
846
|
-
*/
|
|
847
|
-
async create(params) {
|
|
848
|
-
const body = {
|
|
849
|
-
delegatingPartyId: params.delegatingPartyId,
|
|
850
|
-
delegatedPartyId: params.delegatedPartyId,
|
|
851
|
-
permissions: params.permissions
|
|
852
|
-
};
|
|
853
|
-
if (params.expiresAt) {
|
|
854
|
-
body["expiresAt"] = params.expiresAt;
|
|
855
|
-
}
|
|
856
|
-
const headers = {};
|
|
857
|
-
if (params.idempotencyKey) {
|
|
858
|
-
headers["Idempotency-Key"] = params.idempotencyKey;
|
|
859
|
-
}
|
|
860
|
-
return this.http.post("/delegations", {
|
|
861
|
-
body,
|
|
862
|
-
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
863
|
-
});
|
|
1067
|
+
const response = await this.http.get(`/delegations/${delegationId}`);
|
|
1068
|
+
return unwrapDelegation(response);
|
|
864
1069
|
}
|
|
865
1070
|
/**
|
|
866
1071
|
* Update an existing delegation.
|
|
@@ -870,11 +1075,15 @@ var DelegationsResource = class extends BaseResource {
|
|
|
870
1075
|
* @returns Updated Delegation
|
|
871
1076
|
*/
|
|
872
1077
|
async update(delegationId, params) {
|
|
873
|
-
const
|
|
874
|
-
if (params.status !== void 0)
|
|
875
|
-
if (params.permissions !== void 0)
|
|
876
|
-
if (params.expiresAt !== void 0)
|
|
877
|
-
|
|
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);
|
|
878
1087
|
}
|
|
879
1088
|
/**
|
|
880
1089
|
* Revoke a delegation (soft delete by setting status to REVOKED).
|
|
@@ -883,19 +1092,61 @@ var DelegationsResource = class extends BaseResource {
|
|
|
883
1092
|
* @returns Revoked Delegation
|
|
884
1093
|
*/
|
|
885
1094
|
async revoke(delegationId) {
|
|
886
|
-
return this.
|
|
1095
|
+
return this.update(delegationId, { status: "REVOKED" });
|
|
887
1096
|
}
|
|
888
1097
|
};
|
|
889
1098
|
|
|
890
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
|
+
}
|
|
891
1135
|
var CustomersResource = class extends BaseResource {
|
|
892
1136
|
/**
|
|
893
1137
|
* List customers onboarded by the partner via delegation.
|
|
894
1138
|
*
|
|
895
|
-
* @
|
|
1139
|
+
* @param params - Pagination parameters
|
|
1140
|
+
* @returns CustomerListResponse with items, hasMore, nextCursor
|
|
896
1141
|
*/
|
|
897
|
-
async list() {
|
|
898
|
-
|
|
1142
|
+
async list(params) {
|
|
1143
|
+
const response = await this.http.get("/customers", {
|
|
1144
|
+
params: {
|
|
1145
|
+
limit: params?.limit,
|
|
1146
|
+
cursor: params?.cursor
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
return unwrapCustomerList(response);
|
|
899
1150
|
}
|
|
900
1151
|
};
|
|
901
1152
|
|