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