agentmall 0.1.11 → 0.1.12
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 +31 -5
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -393,8 +393,6 @@ function displayOrderSummary(body) {
|
|
|
393
393
|
console.log(` ${addr.address_line1}${addr.address_line2 ? `, ${addr.address_line2}` : ""}`);
|
|
394
394
|
console.log(` ${addr.city}, ${addr.state ?? ""} ${addr.postal_code} ${addr.country}`);
|
|
395
395
|
console.log();
|
|
396
|
-
console.log(` Max budget: \x1B[1m${formatCents(body.max_budget)}\x1B[0m + ${formatCents(SERVICE_FEE_CENTS)} fee`);
|
|
397
|
-
console.log();
|
|
398
396
|
}
|
|
399
397
|
function displayOrderResult(order) {
|
|
400
398
|
console.log();
|
|
@@ -713,6 +711,30 @@ function formatUsdAmount(cents) {
|
|
|
713
711
|
function sleep(ms) {
|
|
714
712
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
715
713
|
}
|
|
714
|
+
async function withSpinner(label, task) {
|
|
715
|
+
const frames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
716
|
+
let frame = 0;
|
|
717
|
+
const render = (prefix) => {
|
|
718
|
+
process.stdout.write(`\r ${prefix} ${label}`);
|
|
719
|
+
};
|
|
720
|
+
render(frames[frame]);
|
|
721
|
+
const interval = setInterval(() => {
|
|
722
|
+
frame = (frame + 1) % frames.length;
|
|
723
|
+
render(frames[frame]);
|
|
724
|
+
}, 80);
|
|
725
|
+
try {
|
|
726
|
+
const result = await task();
|
|
727
|
+
clearInterval(interval);
|
|
728
|
+
render("\x1B[32m\u2714\x1B[0m");
|
|
729
|
+
process.stdout.write("\n");
|
|
730
|
+
return result;
|
|
731
|
+
} catch (error) {
|
|
732
|
+
clearInterval(interval);
|
|
733
|
+
render("\x1B[31m\u2716\x1B[0m");
|
|
734
|
+
process.stdout.write("\n");
|
|
735
|
+
throw error;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
716
738
|
function getSelectedVariantUnitPriceCents(selectedVariants) {
|
|
717
739
|
const highestVariantPrice = selectedVariants?.reduce((highest, variant) => {
|
|
718
740
|
const variantPriceCents = typeof variant.price === "number" ? Math.round(variant.price * 100) : 0;
|
|
@@ -802,8 +824,10 @@ async function buy(urlArg) {
|
|
|
802
824
|
console.log();
|
|
803
825
|
const url = urlArg ?? await promptProductUrl();
|
|
804
826
|
const client = new AgentMall();
|
|
805
|
-
|
|
806
|
-
|
|
827
|
+
const product = await withSpinner(
|
|
828
|
+
"Looking up product...",
|
|
829
|
+
() => client.products.lookup(url)
|
|
830
|
+
);
|
|
807
831
|
displayProduct(product);
|
|
808
832
|
const quantity = await promptQuantity();
|
|
809
833
|
const selectedVariants = product.variants?.length ? await promptVariants(product.variants) : void 0;
|
|
@@ -845,7 +869,9 @@ async function buy(urlArg) {
|
|
|
845
869
|
buyer_email: buyerEmail
|
|
846
870
|
};
|
|
847
871
|
displayOrderSummary(body);
|
|
848
|
-
console.log(`
|
|
872
|
+
console.log(` Retailer budget cap: \x1B[1m${formatCents(maxBudget)}\x1B[0m`);
|
|
873
|
+
console.log(` AgentMall fee: ${formatCents(SERVICE_FEE_CENTS)}`);
|
|
874
|
+
console.log(` Total charged today: \x1B[1m${formatCents(maxBudget + SERVICE_FEE_CENTS)}\x1B[0m USDC on Tempo`);
|
|
849
875
|
console.log(" Any unused amount from your max budget is refunded automatically after checkout.");
|
|
850
876
|
console.log(" The buffer covers unforeseen tax, shipping, and retailer price changes at final checkout.");
|
|
851
877
|
console.log();
|