agentmall 0.1.15 → 0.1.17
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/cli.js +46 -21
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -283,7 +283,7 @@ var RULE_WIDTH = 48;
|
|
|
283
283
|
function banner() {
|
|
284
284
|
console.log();
|
|
285
285
|
console.log(
|
|
286
|
-
` ${c.bold}\u25CE
|
|
286
|
+
` ${c.bold}\u25CE AgentMall${c.reset} ${c.dim}\u2014 buy from the world's biggest retailers with a URL${c.reset}`
|
|
287
287
|
);
|
|
288
288
|
}
|
|
289
289
|
function section(title) {
|
|
@@ -456,14 +456,16 @@ function displayCheckoutEstimate(product, quantity = 1, variantSelections, varia
|
|
|
456
456
|
const linePrice = unitPriceCents * quantityClamped;
|
|
457
457
|
const listBaseUnitPrice = typeof product.listPrice === "number" ? Math.max(product.listPrice, variantUnitPriceCents ?? 0) : void 0;
|
|
458
458
|
const lineListPrice = typeof listBaseUnitPrice === "number" ? listBaseUnitPrice * quantityClamped : void 0;
|
|
459
|
+
const taxAndPriceBufferCents = Math.round(linePrice * 0.15);
|
|
460
|
+
const shippingBufferCents = 800;
|
|
459
461
|
section("Checkout Estimate");
|
|
460
462
|
if (lineListPrice && product.discountPercent) {
|
|
461
463
|
kv(
|
|
462
|
-
"
|
|
464
|
+
"Current price",
|
|
463
465
|
`${c.green}${formatCents(linePrice)}${c.reset} ${c.dim}${c.strike}${formatCents(lineListPrice)}${c.reset} ${c.yellow}-${product.discountPercent}%${c.reset}`
|
|
464
466
|
);
|
|
465
467
|
} else {
|
|
466
|
-
kv("
|
|
468
|
+
kv("Current price", formatCents(linePrice), { color: c.green });
|
|
467
469
|
}
|
|
468
470
|
kv("Quantity", `${quantityClamped}`);
|
|
469
471
|
if (quantityClamped > 1) {
|
|
@@ -474,17 +476,20 @@ function displayCheckoutEstimate(product, quantity = 1, variantSelections, varia
|
|
|
474
476
|
kv(variant.label, variant.value);
|
|
475
477
|
}
|
|
476
478
|
}
|
|
477
|
-
kv("
|
|
478
|
-
kv("
|
|
479
|
+
kv("Tax/price buffer", formatCents(taxAndPriceBufferCents), { dim: true });
|
|
480
|
+
kv("Shipping buffer", formatCents(shippingBufferCents), { dim: true });
|
|
481
|
+
kv(
|
|
482
|
+
"Budget cap",
|
|
483
|
+
`${c.bold}${formatCents(suggestedBudget)}${c.reset} ${c.dim}(suggested)${c.reset}`
|
|
484
|
+
);
|
|
485
|
+
kv("AgentMall fee", formatCents(SERVICE_FEE_CENTS), { dim: true });
|
|
479
486
|
kv(
|
|
480
|
-
"
|
|
487
|
+
"Charged today",
|
|
481
488
|
`${c.bold}${formatCents(suggestedBudget + SERVICE_FEE_CENTS)}${c.reset} USDC`
|
|
482
489
|
);
|
|
483
490
|
gap();
|
|
484
|
-
hint(
|
|
485
|
-
|
|
486
|
-
);
|
|
487
|
-
hint("Unused amount is refunded automatically after checkout.");
|
|
491
|
+
hint("You pay the budget cap plus the AgentMall fee upfront.");
|
|
492
|
+
hint("If the retailer's final total is lower, the difference is refunded automatically.");
|
|
488
493
|
if (product.cached) {
|
|
489
494
|
gap();
|
|
490
495
|
line(
|
|
@@ -1054,32 +1059,38 @@ async function buy(urlArg) {
|
|
|
1054
1059
|
throw error;
|
|
1055
1060
|
}
|
|
1056
1061
|
}
|
|
1057
|
-
async function status(purchaseId) {
|
|
1062
|
+
async function status(purchaseId, options) {
|
|
1058
1063
|
banner();
|
|
1059
1064
|
const apiSecret = process.env.AGENTMALL_API_SECRET;
|
|
1060
|
-
const buyerToken = apiSecret ? null : await getBuyerToken(purchaseId);
|
|
1065
|
+
const buyerToken = apiSecret ? null : options?.buyerToken?.trim() || await getBuyerToken(purchaseId);
|
|
1061
1066
|
const client = apiSecret ? new AgentMall({ apiSecret }) : new AgentMall();
|
|
1062
1067
|
if (!apiSecret && !buyerToken) {
|
|
1063
1068
|
throw new Error(
|
|
1064
|
-
"No saved buyer token found for this order on this machine."
|
|
1069
|
+
"No saved buyer token found for this order on this machine. Pass --buyer-token amtk_... to check it manually."
|
|
1065
1070
|
);
|
|
1066
1071
|
}
|
|
1072
|
+
if (!apiSecret && options?.buyerToken?.trim()) {
|
|
1073
|
+
await saveBuyerToken(purchaseId, options.buyerToken.trim());
|
|
1074
|
+
}
|
|
1067
1075
|
const result = await spin(
|
|
1068
1076
|
"Fetching order",
|
|
1069
1077
|
() => client.purchases.get(purchaseId, buyerToken ? { buyerToken } : void 0)
|
|
1070
1078
|
);
|
|
1071
1079
|
displayStatus(result);
|
|
1072
1080
|
}
|
|
1073
|
-
async function refund(purchaseId) {
|
|
1081
|
+
async function refund(purchaseId, options) {
|
|
1074
1082
|
banner();
|
|
1075
1083
|
const apiSecret = process.env.AGENTMALL_API_SECRET;
|
|
1076
|
-
const buyerToken = apiSecret ? null : await getBuyerToken(purchaseId);
|
|
1084
|
+
const buyerToken = apiSecret ? null : options?.buyerToken?.trim() || await getBuyerToken(purchaseId);
|
|
1077
1085
|
const client = apiSecret ? new AgentMall({ apiSecret }) : new AgentMall();
|
|
1078
1086
|
if (!apiSecret && !buyerToken) {
|
|
1079
1087
|
throw new Error(
|
|
1080
|
-
"No saved buyer token found for this order on this machine."
|
|
1088
|
+
"No saved buyer token found for this order on this machine. Pass --buyer-token amtk_... to check it manually."
|
|
1081
1089
|
);
|
|
1082
1090
|
}
|
|
1091
|
+
if (!apiSecret && options?.buyerToken?.trim()) {
|
|
1092
|
+
await saveBuyerToken(purchaseId, options.buyerToken.trim());
|
|
1093
|
+
}
|
|
1083
1094
|
const result = await spin(
|
|
1084
1095
|
"Fetching refund",
|
|
1085
1096
|
() => client.refunds.getByPurchase(
|
|
@@ -1130,6 +1141,17 @@ var c2 = {
|
|
|
1130
1141
|
};
|
|
1131
1142
|
var args = process.argv.slice(2);
|
|
1132
1143
|
var command = args[0];
|
|
1144
|
+
function readBuyerTokenFlag(values) {
|
|
1145
|
+
const inline = values.find((value) => value.startsWith("--buyer-token="));
|
|
1146
|
+
if (inline) {
|
|
1147
|
+
const token2 = inline.slice("--buyer-token=".length).trim();
|
|
1148
|
+
return token2 || void 0;
|
|
1149
|
+
}
|
|
1150
|
+
const index = values.indexOf("--buyer-token");
|
|
1151
|
+
if (index === -1) return void 0;
|
|
1152
|
+
const token = values[index + 1]?.trim();
|
|
1153
|
+
return token || void 0;
|
|
1154
|
+
}
|
|
1133
1155
|
async function main() {
|
|
1134
1156
|
try {
|
|
1135
1157
|
switch (command) {
|
|
@@ -1138,17 +1160,17 @@ async function main() {
|
|
|
1138
1160
|
break;
|
|
1139
1161
|
case "status":
|
|
1140
1162
|
if (!args[1]) {
|
|
1141
|
-
console.error("Usage: agentmall status <purchase_id>");
|
|
1163
|
+
console.error("Usage: agentmall status <purchase_id> [--buyer-token <token>]");
|
|
1142
1164
|
process.exit(1);
|
|
1143
1165
|
}
|
|
1144
|
-
await status(args[1]);
|
|
1166
|
+
await status(args[1], { buyerToken: readBuyerTokenFlag(args.slice(2)) });
|
|
1145
1167
|
break;
|
|
1146
1168
|
case "refund":
|
|
1147
1169
|
if (!args[1]) {
|
|
1148
|
-
console.error("Usage: agentmall refund <purchase_id>");
|
|
1170
|
+
console.error("Usage: agentmall refund <purchase_id> [--buyer-token <token>]");
|
|
1149
1171
|
process.exit(1);
|
|
1150
1172
|
}
|
|
1151
|
-
await refund(args[1]);
|
|
1173
|
+
await refund(args[1], { buyerToken: readBuyerTokenFlag(args.slice(2)) });
|
|
1152
1174
|
break;
|
|
1153
1175
|
case "onboard":
|
|
1154
1176
|
case "setup":
|
|
@@ -1182,7 +1204,7 @@ function printHelp() {
|
|
|
1182
1204
|
};
|
|
1183
1205
|
console.log();
|
|
1184
1206
|
console.log(
|
|
1185
|
-
` ${c2.bold}\u25CE
|
|
1207
|
+
` ${c2.bold}\u25CE AgentMall${c2.reset} ${c2.dim}\u2014 buy from the world's biggest retailers with a URL${c2.reset}`
|
|
1186
1208
|
);
|
|
1187
1209
|
console.log();
|
|
1188
1210
|
console.log(` ${rule("Commands")}`);
|
|
@@ -1210,6 +1232,9 @@ function printHelp() {
|
|
|
1210
1232
|
` ${c2.dim}$${c2.reset} npx agentmall https://amazon.com/dp/B0DWTMJHCG`
|
|
1211
1233
|
);
|
|
1212
1234
|
console.log(` ${c2.dim}$${c2.reset} npx agentmall status pur_abc123`);
|
|
1235
|
+
console.log(
|
|
1236
|
+
` ${c2.dim}$${c2.reset} npx agentmall status pur_abc123 --buyer-token amtk_...`
|
|
1237
|
+
);
|
|
1213
1238
|
console.log(` ${c2.dim}$${c2.reset} npx agentmall refund pur_abc123`);
|
|
1214
1239
|
console.log();
|
|
1215
1240
|
}
|