agentmall 0.1.16 → 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.
Files changed (2) hide show
  1. package/dist/cli.js +32 -12
  2. 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 agentmall${c.reset} ${c.dim}\u2014 buy anything with a URL${c.reset}`
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) {
@@ -1059,32 +1059,38 @@ async function buy(urlArg) {
1059
1059
  throw error;
1060
1060
  }
1061
1061
  }
1062
- async function status(purchaseId) {
1062
+ async function status(purchaseId, options) {
1063
1063
  banner();
1064
1064
  const apiSecret = process.env.AGENTMALL_API_SECRET;
1065
- const buyerToken = apiSecret ? null : await getBuyerToken(purchaseId);
1065
+ const buyerToken = apiSecret ? null : options?.buyerToken?.trim() || await getBuyerToken(purchaseId);
1066
1066
  const client = apiSecret ? new AgentMall({ apiSecret }) : new AgentMall();
1067
1067
  if (!apiSecret && !buyerToken) {
1068
1068
  throw new Error(
1069
- "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."
1070
1070
  );
1071
1071
  }
1072
+ if (!apiSecret && options?.buyerToken?.trim()) {
1073
+ await saveBuyerToken(purchaseId, options.buyerToken.trim());
1074
+ }
1072
1075
  const result = await spin(
1073
1076
  "Fetching order",
1074
1077
  () => client.purchases.get(purchaseId, buyerToken ? { buyerToken } : void 0)
1075
1078
  );
1076
1079
  displayStatus(result);
1077
1080
  }
1078
- async function refund(purchaseId) {
1081
+ async function refund(purchaseId, options) {
1079
1082
  banner();
1080
1083
  const apiSecret = process.env.AGENTMALL_API_SECRET;
1081
- const buyerToken = apiSecret ? null : await getBuyerToken(purchaseId);
1084
+ const buyerToken = apiSecret ? null : options?.buyerToken?.trim() || await getBuyerToken(purchaseId);
1082
1085
  const client = apiSecret ? new AgentMall({ apiSecret }) : new AgentMall();
1083
1086
  if (!apiSecret && !buyerToken) {
1084
1087
  throw new Error(
1085
- "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."
1086
1089
  );
1087
1090
  }
1091
+ if (!apiSecret && options?.buyerToken?.trim()) {
1092
+ await saveBuyerToken(purchaseId, options.buyerToken.trim());
1093
+ }
1088
1094
  const result = await spin(
1089
1095
  "Fetching refund",
1090
1096
  () => client.refunds.getByPurchase(
@@ -1135,6 +1141,17 @@ var c2 = {
1135
1141
  };
1136
1142
  var args = process.argv.slice(2);
1137
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
+ }
1138
1155
  async function main() {
1139
1156
  try {
1140
1157
  switch (command) {
@@ -1143,17 +1160,17 @@ async function main() {
1143
1160
  break;
1144
1161
  case "status":
1145
1162
  if (!args[1]) {
1146
- console.error("Usage: agentmall status <purchase_id>");
1163
+ console.error("Usage: agentmall status <purchase_id> [--buyer-token <token>]");
1147
1164
  process.exit(1);
1148
1165
  }
1149
- await status(args[1]);
1166
+ await status(args[1], { buyerToken: readBuyerTokenFlag(args.slice(2)) });
1150
1167
  break;
1151
1168
  case "refund":
1152
1169
  if (!args[1]) {
1153
- console.error("Usage: agentmall refund <purchase_id>");
1170
+ console.error("Usage: agentmall refund <purchase_id> [--buyer-token <token>]");
1154
1171
  process.exit(1);
1155
1172
  }
1156
- await refund(args[1]);
1173
+ await refund(args[1], { buyerToken: readBuyerTokenFlag(args.slice(2)) });
1157
1174
  break;
1158
1175
  case "onboard":
1159
1176
  case "setup":
@@ -1187,7 +1204,7 @@ function printHelp() {
1187
1204
  };
1188
1205
  console.log();
1189
1206
  console.log(
1190
- ` ${c2.bold}\u25CE agentmall${c2.reset} ${c2.dim}\u2014 buy anything with a URL${c2.reset}`
1207
+ ` ${c2.bold}\u25CE AgentMall${c2.reset} ${c2.dim}\u2014 buy from the world's biggest retailers with a URL${c2.reset}`
1191
1208
  );
1192
1209
  console.log();
1193
1210
  console.log(` ${rule("Commands")}`);
@@ -1215,6 +1232,9 @@ function printHelp() {
1215
1232
  ` ${c2.dim}$${c2.reset} npx agentmall https://amazon.com/dp/B0DWTMJHCG`
1216
1233
  );
1217
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
+ );
1218
1238
  console.log(` ${c2.dim}$${c2.reset} npx agentmall refund pur_abc123`);
1219
1239
  console.log();
1220
1240
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentmall",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
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",