@naturalpay/sdk 0.1.4 → 0.2.0
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 +86 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -17
- package/dist/index.d.ts +67 -17
- package/dist/index.js +86 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -879,8 +879,9 @@ function unwrapTransactionResource(resource) {
|
|
|
879
879
|
amount: Number(attributes.amount),
|
|
880
880
|
currency: String(attributes.currency),
|
|
881
881
|
status: String(attributes.status),
|
|
882
|
+
escalationId: attributes.escalationId != null ? String(attributes.escalationId) : void 0,
|
|
883
|
+
disputeId: attributes.disputeId != null ? String(attributes.disputeId) : void 0,
|
|
882
884
|
description: attributes.description != null ? String(attributes.description) : void 0,
|
|
883
|
-
memo: attributes.memo != null ? String(attributes.memo) : void 0,
|
|
884
885
|
createdAt: String(attributes.createdAt),
|
|
885
886
|
updatedAt: attributes.updatedAt != null ? String(attributes.updatedAt) : void 0,
|
|
886
887
|
isDelegated: Boolean(attributes.isDelegated),
|
|
@@ -888,6 +889,8 @@ function unwrapTransactionResource(resource) {
|
|
|
888
889
|
customerAgentId: attributes.customerAgentId != null ? String(attributes.customerAgentId) : void 0,
|
|
889
890
|
senderName: attributes.senderName != null ? String(attributes.senderName) : void 0,
|
|
890
891
|
recipientName: attributes.recipientName != null ? String(attributes.recipientName) : void 0,
|
|
892
|
+
initiatorName: attributes.initiatorName != null ? String(attributes.initiatorName) : void 0,
|
|
893
|
+
initiatorIsAgent: attributes.initiatorIsAgent != null ? Boolean(attributes.initiatorIsAgent) : void 0,
|
|
891
894
|
transactionType: String(attributes.transactionType),
|
|
892
895
|
category: String(attributes.category),
|
|
893
896
|
direction: String(attributes.direction),
|
|
@@ -1002,8 +1005,6 @@ function unwrapPaymentResponse(response) {
|
|
|
1002
1005
|
transactionType: String(attributes.transactionType ?? "payment"),
|
|
1003
1006
|
category: String(attributes.category ?? "sent"),
|
|
1004
1007
|
direction: String(attributes.direction ?? "OUTBOUND"),
|
|
1005
|
-
// Mirror description into memo for payment convenience.
|
|
1006
|
-
memo: base.description,
|
|
1007
1008
|
// Payments use customerParty/counterparty relationship keys,
|
|
1008
1009
|
// falling back to the generic sourceParty/destinationParty.
|
|
1009
1010
|
sourcePartyId: relationships?.customerParty?.data?.id ?? base.sourcePartyId,
|
|
@@ -1027,9 +1028,9 @@ var PaymentsResource = class extends BaseResource {
|
|
|
1027
1028
|
amount: params.amount,
|
|
1028
1029
|
currency: params.currency ?? "USD",
|
|
1029
1030
|
counterparty: recipient,
|
|
1030
|
-
|
|
1031
|
+
description: params.description,
|
|
1032
|
+
...params.customerPartyId != null ? { customerPartyId: params.customerPartyId } : {}
|
|
1031
1033
|
};
|
|
1032
|
-
attributes["description"] = params.memo;
|
|
1033
1034
|
const body = { data: { attributes } };
|
|
1034
1035
|
const headers = {
|
|
1035
1036
|
"Idempotency-Key": params.idempotencyKey
|
|
@@ -1078,9 +1079,9 @@ function unwrapBalance(response) {
|
|
|
1078
1079
|
const breakdown = {
|
|
1079
1080
|
operatingFunded: toAmountInfo(rawBreakdown?.operatingFunded),
|
|
1080
1081
|
operatingAdvanced: toAmountInfo(rawBreakdown?.operatingAdvanced),
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1082
|
+
pendingIn: toAmountInfo(rawBreakdown?.pendingIn),
|
|
1083
|
+
pendingOut: toAmountInfo(rawBreakdown?.pendingOut),
|
|
1084
|
+
held: toAmountInfo(rawBreakdown?.held)
|
|
1084
1085
|
};
|
|
1085
1086
|
return {
|
|
1086
1087
|
walletId: id,
|
|
@@ -1458,18 +1459,14 @@ var DelegationsResource = class extends BaseResource {
|
|
|
1458
1459
|
};
|
|
1459
1460
|
|
|
1460
1461
|
// src/resources/customers.ts
|
|
1461
|
-
var VALID_CUSTOMER_TYPES = /* @__PURE__ */ new Set(["party", "delegationInvitation"]);
|
|
1462
1462
|
var VALID_WALLET_ACCESS = /* @__PURE__ */ new Set(["granted", "denied", "noWallet"]);
|
|
1463
|
-
function isCustomerType(value) {
|
|
1464
|
-
return VALID_CUSTOMER_TYPES.has(value);
|
|
1465
|
-
}
|
|
1466
1463
|
function isWalletAccess(value) {
|
|
1467
1464
|
return typeof value === "string" && VALID_WALLET_ACCESS.has(value);
|
|
1468
1465
|
}
|
|
1469
1466
|
function unwrapCustomerResource(resource) {
|
|
1470
|
-
if (
|
|
1467
|
+
if (resource.type !== "party" || !resource.attributes) {
|
|
1471
1468
|
throw new NaturalError(
|
|
1472
|
-
`Unexpected resource format: expected type "party"
|
|
1469
|
+
`Unexpected resource format: expected type "party", got "${resource.type}"`
|
|
1473
1470
|
);
|
|
1474
1471
|
}
|
|
1475
1472
|
const { id, attributes } = resource;
|
|
@@ -1480,9 +1477,8 @@ function unwrapCustomerResource(resource) {
|
|
|
1480
1477
|
} : void 0;
|
|
1481
1478
|
return {
|
|
1482
1479
|
id,
|
|
1483
|
-
type:
|
|
1480
|
+
type: "party",
|
|
1484
1481
|
party,
|
|
1485
|
-
email: typeof attributes.email === "string" ? attributes.email : void 0,
|
|
1486
1482
|
status: typeof attributes.status === "string" ? attributes.status : "",
|
|
1487
1483
|
permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
|
|
1488
1484
|
createdAt: typeof attributes.createdAt === "string" ? attributes.createdAt : "",
|
|
@@ -1491,6 +1487,22 @@ function unwrapCustomerResource(resource) {
|
|
|
1491
1487
|
walletAccess: isWalletAccess(attributes.walletAccess) ? attributes.walletAccess : "denied"
|
|
1492
1488
|
};
|
|
1493
1489
|
}
|
|
1490
|
+
function unwrapPendingInvitationResource(resource) {
|
|
1491
|
+
if (resource.type !== "delegationInvitation" || !resource.attributes) {
|
|
1492
|
+
throw new NaturalError(
|
|
1493
|
+
`Unexpected resource format: expected type "delegationInvitation", got "${resource.type}"`
|
|
1494
|
+
);
|
|
1495
|
+
}
|
|
1496
|
+
const { id, attributes } = resource;
|
|
1497
|
+
return {
|
|
1498
|
+
id,
|
|
1499
|
+
type: "delegationInvitation",
|
|
1500
|
+
email: typeof attributes.email === "string" ? attributes.email : void 0,
|
|
1501
|
+
status: typeof attributes.status === "string" ? attributes.status : "",
|
|
1502
|
+
permissions: Array.isArray(attributes.permissions) ? attributes.permissions : [],
|
|
1503
|
+
createdAt: typeof attributes.createdAt === "string" ? attributes.createdAt : ""
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1494
1506
|
function unwrapCustomerList(response) {
|
|
1495
1507
|
if (!response?.data || !Array.isArray(response.data)) {
|
|
1496
1508
|
throw new NaturalError(
|
|
@@ -1504,34 +1516,59 @@ function unwrapCustomerList(response) {
|
|
|
1504
1516
|
nextCursor: pagination.nextCursor ?? null
|
|
1505
1517
|
};
|
|
1506
1518
|
}
|
|
1519
|
+
function unwrapPendingInvitationList(response) {
|
|
1520
|
+
if (!response?.data || !Array.isArray(response.data)) {
|
|
1521
|
+
throw new NaturalError(
|
|
1522
|
+
'Unexpected response format: missing "data" array in pending invitation list response'
|
|
1523
|
+
);
|
|
1524
|
+
}
|
|
1525
|
+
const pagination = response.meta?.pagination ?? {};
|
|
1526
|
+
return {
|
|
1527
|
+
items: response.data.map(unwrapPendingInvitationResource),
|
|
1528
|
+
hasMore: pagination.hasMore ?? false,
|
|
1529
|
+
nextCursor: pagination.nextCursor ?? null
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
function buildRequest(params) {
|
|
1533
|
+
const headers = {};
|
|
1534
|
+
if (params?.agentId) {
|
|
1535
|
+
headers["X-Agent-ID"] = params.agentId;
|
|
1536
|
+
}
|
|
1537
|
+
if (params?.instanceId) {
|
|
1538
|
+
headers["X-Instance-ID"] = params.instanceId;
|
|
1539
|
+
}
|
|
1540
|
+
if (params?.traceId) {
|
|
1541
|
+
headers["X-Trace-ID"] = sanitizeHeaderValue(params.traceId);
|
|
1542
|
+
}
|
|
1543
|
+
const queryParams = {
|
|
1544
|
+
limit: params?.limit,
|
|
1545
|
+
cursor: params?.cursor
|
|
1546
|
+
};
|
|
1547
|
+
return {
|
|
1548
|
+
params: queryParams,
|
|
1549
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1507
1552
|
var CustomersResource = class extends BaseResource {
|
|
1508
1553
|
/**
|
|
1509
|
-
* List customers who have delegated access to the partner.
|
|
1554
|
+
* List active customers who have delegated access to the partner.
|
|
1510
1555
|
*
|
|
1511
|
-
* @
|
|
1512
|
-
*
|
|
1556
|
+
* Returns only accepted delegations. Use {@link listInvitations} for pending
|
|
1557
|
+
* invitations that have not yet been accepted.
|
|
1513
1558
|
*/
|
|
1514
1559
|
async list(params) {
|
|
1515
|
-
const
|
|
1516
|
-
|
|
1517
|
-
headers["X-Agent-ID"] = params.agentId;
|
|
1518
|
-
}
|
|
1519
|
-
if (params?.instanceId) {
|
|
1520
|
-
headers["X-Instance-ID"] = params.instanceId;
|
|
1521
|
-
}
|
|
1522
|
-
if (params?.traceId) {
|
|
1523
|
-
headers["X-Trace-ID"] = sanitizeHeaderValue(params.traceId);
|
|
1524
|
-
}
|
|
1525
|
-
const queryParams = {
|
|
1526
|
-
limit: params?.limit,
|
|
1527
|
-
cursor: params?.cursor
|
|
1528
|
-
};
|
|
1529
|
-
const response = await this.http.get("/customers", {
|
|
1530
|
-
params: queryParams,
|
|
1531
|
-
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
1532
|
-
});
|
|
1560
|
+
const request = buildRequest(params);
|
|
1561
|
+
const response = await this.http.get("/customers", request);
|
|
1533
1562
|
return unwrapCustomerList(response);
|
|
1534
1563
|
}
|
|
1564
|
+
/**
|
|
1565
|
+
* List pending customer invitations you've sent that have not yet been accepted.
|
|
1566
|
+
*/
|
|
1567
|
+
async listInvitations(params) {
|
|
1568
|
+
const request = buildRequest(params);
|
|
1569
|
+
const response = await this.http.get("/customers/invitations", request);
|
|
1570
|
+
return unwrapPendingInvitationList(response);
|
|
1571
|
+
}
|
|
1535
1572
|
};
|
|
1536
1573
|
|
|
1537
1574
|
// src/client.ts
|
|
@@ -1567,6 +1604,17 @@ var NaturalClient = class {
|
|
|
1567
1604
|
this.customers = new CustomersResource(this.http);
|
|
1568
1605
|
}
|
|
1569
1606
|
};
|
|
1607
|
+
|
|
1608
|
+
// src/tool-names.ts
|
|
1609
|
+
var NATURAL_TOOL_NAMES = {
|
|
1610
|
+
CREATE_PAYMENT: "create_payment",
|
|
1611
|
+
GET_PAYMENT_STATUS: "get_payment_status",
|
|
1612
|
+
GET_ACCOUNT_BALANCE: "get_account_balance",
|
|
1613
|
+
LIST_TRANSACTIONS: "list_transactions",
|
|
1614
|
+
LIST_AGENTS: "list_agents",
|
|
1615
|
+
LIST_CUSTOMERS: "list_customers",
|
|
1616
|
+
LIST_CUSTOMER_INVITATIONS: "list_customer_invitations"
|
|
1617
|
+
};
|
|
1570
1618
|
var WHSEC_PREFIX = "whsec_";
|
|
1571
1619
|
var DEFAULT_TOLERANCE_SECONDS = 300;
|
|
1572
1620
|
function getHeader(headers, name) {
|
|
@@ -1657,6 +1705,7 @@ var TransactionTypeFilter = /* @__PURE__ */ ((TransactionTypeFilter2) => {
|
|
|
1657
1705
|
exports.AuthenticationError = AuthenticationError;
|
|
1658
1706
|
exports.InsufficientFundsError = InsufficientFundsError;
|
|
1659
1707
|
exports.InvalidRequestError = InvalidRequestError;
|
|
1708
|
+
exports.NATURAL_TOOL_NAMES = NATURAL_TOOL_NAMES;
|
|
1660
1709
|
exports.NaturalClient = NaturalClient;
|
|
1661
1710
|
exports.NaturalError = NaturalError;
|
|
1662
1711
|
exports.PaymentError = PaymentError;
|