agentmall 0.1.10 → 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.
Files changed (2) hide show
  1. package/dist/cli.js +34 -8
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -295,8 +295,8 @@ function calculateSuggestedBudget(product, quantity = 1, variantUnitPriceCents)
295
295
  variantUnitPriceCents ?? 0
296
296
  );
297
297
  const basePriceCents = baseUnitPriceCents * quantityClamped;
298
- const variableBufferCents = Math.round(basePriceCents * 0.15);
299
- return basePriceCents + Math.max(variableBufferCents, 800);
298
+ const taxAndPriceBufferCents = Math.round(basePriceCents * 0.15);
299
+ return basePriceCents + taxAndPriceBufferCents + 800;
300
300
  }
301
301
  function calculateMinimumBudget(product, quantity = 1, variantUnitPriceCents) {
302
302
  const unitPriceCents = Math.max(product.price, variantUnitPriceCents ?? 0);
@@ -354,7 +354,7 @@ function displayCheckoutEstimate(product, quantity = 1, variantSelections, varia
354
354
  }
355
355
  }
356
356
  console.log(
357
- ` Suggested budget: \x1B[1m${formatCents(suggestedBudget)}\x1B[0m (includes 15% buffer for tax and an $8 minimum shipping buffer)`
357
+ ` Suggested budget: \x1B[1m${formatCents(suggestedBudget)}\x1B[0m (includes a 15% tax/price buffer plus an $8 minimum shipping buffer)`
358
358
  );
359
359
  console.log(
360
360
  ` Service fee: ${formatCents(SERVICE_FEE_CENTS)}`
@@ -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
- console.log(" Looking up product...");
806
- const product = await client.products.lookup(url);
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(` Total charge: \x1B[1m${formatCents(maxBudget + SERVICE_FEE_CENTS)}\x1B[0m USDC on Tempo`);
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentmall",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "SDK and CLI for the AgentMall API — let AI agents buy physical products from US retailers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",