@itpay/cli 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/itp +18 -18
- package/package.json +1 -1
package/bin/itp
CHANGED
|
@@ -8,7 +8,7 @@ import { execFileSync } from "node:child_process";
|
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import QRCode from "qrcode";
|
|
10
10
|
|
|
11
|
-
const VERSION = "0.1.
|
|
11
|
+
const VERSION = "0.1.5";
|
|
12
12
|
const DEFAULT_API_BASE = process.env.ITPAY_API_BASE || process.env.ITPAY_CORE_API_BASE || process.env.ITPAY_CORE_BASE_URL || "https://dev.api.itpay.ai";
|
|
13
13
|
const CONFIG_DIR = path.join(os.homedir(), ".itp");
|
|
14
14
|
const CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
|
|
@@ -563,7 +563,7 @@ async function buyer(command, rest, flags) {
|
|
|
563
563
|
if (flags.currency) body.context.currency = String(flags.currency);
|
|
564
564
|
if (flags.page_size || flags.limit) body.pagination.limit = Number(flags.page_size || flags.limit);
|
|
565
565
|
if (flags.cursor) body.pagination.cursor = String(flags.cursor);
|
|
566
|
-
const catalog = await coreApi("/
|
|
566
|
+
const catalog = await coreApi("/v1/catalog/search", { method: "POST", body }, flags);
|
|
567
567
|
output(buyerRunOutput({
|
|
568
568
|
status: "catalog_search_results",
|
|
569
569
|
catalog,
|
|
@@ -647,20 +647,20 @@ async function buyer(command, rest, flags) {
|
|
|
647
647
|
}
|
|
648
648
|
if (command === "shelf") {
|
|
649
649
|
if (subcommand === "manifest") {
|
|
650
|
-
output(await coreApi("/v1/
|
|
650
|
+
output(await coreApi("/v1/catalog/manifests/current", { method: "GET" }, flags));
|
|
651
651
|
return;
|
|
652
652
|
}
|
|
653
653
|
if (subcommand === "snapshot") {
|
|
654
654
|
const version = flags.version || positional(rest, 1);
|
|
655
655
|
if (!version) throw new Error("snapshot version is required");
|
|
656
|
-
output(await coreApi(`/v1/
|
|
656
|
+
output(await coreApi(`/v1/catalog/snapshots/${encodeURIComponent(version)}`, { method: "GET" }, flags));
|
|
657
657
|
return;
|
|
658
658
|
}
|
|
659
659
|
if (subcommand === "delta") {
|
|
660
660
|
const since = flags.since || positional(rest, 1);
|
|
661
661
|
if (!since) throw new Error("delta --since version is required");
|
|
662
662
|
const params = new URLSearchParams({ since });
|
|
663
|
-
output(await coreApi(`/v1/
|
|
663
|
+
output(await coreApi(`/v1/catalog/delta?${params.toString()}`, { method: "GET" }, flags));
|
|
664
664
|
return;
|
|
665
665
|
}
|
|
666
666
|
}
|
|
@@ -1011,7 +1011,7 @@ async function getBuyerUCPProduct(selectionID, flags = {}) {
|
|
|
1011
1011
|
context: {}
|
|
1012
1012
|
};
|
|
1013
1013
|
if (flags.currency) body.context.currency = String(flags.currency);
|
|
1014
|
-
return await coreApi("/
|
|
1014
|
+
return await coreApi("/v1/catalog/selections/resolve", { method: "POST", body }, flags);
|
|
1015
1015
|
}
|
|
1016
1016
|
|
|
1017
1017
|
function selectionFromUCPProduct(detail, selectionID, flags = {}) {
|
|
@@ -1075,7 +1075,7 @@ async function createBuyerCartFromSelections(selections, flags = {}) {
|
|
|
1075
1075
|
client_reference_id: flags.cart_client_reference_id || flags.client_reference_id || `cli_cart_${Date.now()}`
|
|
1076
1076
|
};
|
|
1077
1077
|
if (currency) body.context.currency = String(currency);
|
|
1078
|
-
const cart = await coreApi("/
|
|
1078
|
+
const cart = await coreApi("/v1/carts", {
|
|
1079
1079
|
method: "POST",
|
|
1080
1080
|
idempotencyKey: flags.cart_idempotency_key || `idem_cli_cart_${cryptoRandom()}`,
|
|
1081
1081
|
body
|
|
@@ -1179,7 +1179,7 @@ function splitCSV(value) {
|
|
|
1179
1179
|
|
|
1180
1180
|
async function getBuyerCart(cartID, flags = {}) {
|
|
1181
1181
|
if (!cartID) throw new Error("cart_id is required");
|
|
1182
|
-
return await coreApi(`/
|
|
1182
|
+
return await coreApi(`/v1/carts/${encodeURIComponent(cartID)}`, { method: "GET" }, flags);
|
|
1183
1183
|
}
|
|
1184
1184
|
|
|
1185
1185
|
async function addBuyerCartLineItem(cartID, selection, flags = {}) {
|
|
@@ -1191,7 +1191,7 @@ async function addBuyerCartLineItem(cartID, selection, flags = {}) {
|
|
|
1191
1191
|
quantity,
|
|
1192
1192
|
input: buyerLineInputForSelection(selection, flags, 0)
|
|
1193
1193
|
};
|
|
1194
|
-
const cart = await coreApi(`/
|
|
1194
|
+
const cart = await coreApi(`/v1/carts/${encodeURIComponent(cartID)}/line-items`, {
|
|
1195
1195
|
method: "POST",
|
|
1196
1196
|
idempotencyKey: flags.cart_idempotency_key || `idem_cli_cart_add_${cryptoRandom()}`,
|
|
1197
1197
|
body
|
|
@@ -1203,7 +1203,7 @@ async function addBuyerCartLineItem(cartID, selection, flags = {}) {
|
|
|
1203
1203
|
async function removeBuyerCartLineItem(cartID, lineID, flags = {}) {
|
|
1204
1204
|
if (!cartID) throw new Error("cart_id is required");
|
|
1205
1205
|
if (!lineID) throw new Error("cart_line_item_id is required");
|
|
1206
|
-
const cart = await coreApi(`/
|
|
1206
|
+
const cart = await coreApi(`/v1/carts/${encodeURIComponent(cartID)}/line-items/${encodeURIComponent(lineID)}`, {
|
|
1207
1207
|
method: "DELETE"
|
|
1208
1208
|
}, flags);
|
|
1209
1209
|
writeState({ ...readState(), last_core_cart_id: cart.cart_id || cart.id });
|
|
@@ -1231,11 +1231,11 @@ async function createBuyerCheckoutFromCart(cart, selection = null, flags = {}) {
|
|
|
1231
1231
|
};
|
|
1232
1232
|
let checkout;
|
|
1233
1233
|
try {
|
|
1234
|
-
checkout = await coreApi("/
|
|
1234
|
+
checkout = await coreApi("/v1/checkouts", request, flags);
|
|
1235
1235
|
} catch (error) {
|
|
1236
1236
|
if (error?.status === 401 && readSessionToken(readCredentials()) && !flags.access_token) {
|
|
1237
1237
|
writeCredentials(deleteSessionCredential(readCredentials()));
|
|
1238
|
-
checkout = await coreApi("/
|
|
1238
|
+
checkout = await coreApi("/v1/checkouts", request, flags);
|
|
1239
1239
|
} else {
|
|
1240
1240
|
throw error;
|
|
1241
1241
|
}
|
|
@@ -1304,7 +1304,7 @@ async function maybeClaimBuyerSessionFromAuthAction(action, flags = {}) {
|
|
|
1304
1304
|
const parsed = parseBuyerAuthActionURL(action);
|
|
1305
1305
|
if (!parsed.authSessionID || !parsed.displayToken) return null;
|
|
1306
1306
|
try {
|
|
1307
|
-
const response = await coreApi(`/v1/
|
|
1307
|
+
const response = await coreApi(`/v1/session-exchanges/auth-sessions/${encodeURIComponent(parsed.authSessionID)}/agent-session?display_token=${encodeURIComponent(parsed.displayToken)}`, {
|
|
1308
1308
|
method: "POST"
|
|
1309
1309
|
}, flags);
|
|
1310
1310
|
const rawToken = response.raw_session_token || response.session_token || response.session?.raw_session_token;
|
|
@@ -1393,7 +1393,7 @@ function parseBuyerAuthActionURL(action) {
|
|
|
1393
1393
|
const parsed = new URL(rawURL);
|
|
1394
1394
|
const token = parsed.searchParams.get("display_token") || "";
|
|
1395
1395
|
if (token && !displayToken) displayToken = token;
|
|
1396
|
-
const match = parsed.pathname.match(/(?:^|\/)
|
|
1396
|
+
const match = parsed.pathname.match(/(?:^|\/)v1\/session-exchanges\/auth-sessions\/([^/?#]+)(?:\/|$)/);
|
|
1397
1397
|
if (match && !authSessionID) authSessionID = decodeURIComponent(match[1]);
|
|
1398
1398
|
if (!sourceURL && (match || token)) sourceURL = rawURL;
|
|
1399
1399
|
if (authSessionID && displayToken) break;
|
|
@@ -1685,7 +1685,7 @@ async function buyerAuthStatusOutput(flags = {}) {
|
|
|
1685
1685
|
const token = readSessionToken(credentials);
|
|
1686
1686
|
if (token && config.account_id) {
|
|
1687
1687
|
try {
|
|
1688
|
-
const status = await coreApi(
|
|
1688
|
+
const status = await coreApi("/v1/me/auth/status", { method: "GET" }, flags);
|
|
1689
1689
|
return buyerRunOutput({
|
|
1690
1690
|
status: "authenticated_buyer_session",
|
|
1691
1691
|
authenticated: true,
|
|
@@ -1735,12 +1735,12 @@ async function listBuyerAgentReadGrants(flags = {}) {
|
|
|
1735
1735
|
}
|
|
1736
1736
|
}
|
|
1737
1737
|
const query = params.toString();
|
|
1738
|
-
return await coreApi(`/v1/
|
|
1738
|
+
return await coreApi(`/v1/me/agent-grants${query ? `?${query}` : ""}`, { method: "GET" }, flags);
|
|
1739
1739
|
}
|
|
1740
1740
|
|
|
1741
1741
|
async function readBuyerAgentReadGrant(grantID, flags = {}) {
|
|
1742
1742
|
if (!grantID) throw new Error("agent_read_grant_id is required");
|
|
1743
|
-
return await coreApi(`/v1/
|
|
1743
|
+
return await coreApi(`/v1/me/agent-grants/${encodeURIComponent(grantID)}/view`, { method: "GET" }, flags);
|
|
1744
1744
|
}
|
|
1745
1745
|
|
|
1746
1746
|
async function readBuyerVaultArtifactGrant(flags = {}) {
|
|
@@ -2120,7 +2120,7 @@ async function accountLoginLink(flags) {
|
|
|
2120
2120
|
if (!readSessionToken()) {
|
|
2121
2121
|
throw new Error("buyer account session is required; complete first-purchase auth or run buyer checkout resume first");
|
|
2122
2122
|
}
|
|
2123
|
-
const link = await coreApi(
|
|
2123
|
+
const link = await coreApi("/v1/me/portal-login-links", { method: "POST" }, flags);
|
|
2124
2124
|
output(buyerRunOutput({
|
|
2125
2125
|
status: "account_portal_login_link_created",
|
|
2126
2126
|
account_id: accountID,
|