terminalmarket 0.11.0 → 0.11.2
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/tm.js +31 -15
- package/package.json +1 -1
package/bin/tm.js
CHANGED
|
@@ -107,9 +107,15 @@ program
|
|
|
107
107
|
.name("tm")
|
|
108
108
|
.description("TerminalMarket CLI — marketplace for developers")
|
|
109
109
|
.version(VERSION)
|
|
110
|
-
.helpOption(
|
|
110
|
+
.helpOption('-h, --help', 'Show help')
|
|
111
111
|
.addHelpCommand(false);
|
|
112
112
|
|
|
113
|
+
// Override --help to show our custom help instead of Commander's default
|
|
114
|
+
program.helpInformation = () => '';
|
|
115
|
+
program.on('--help', () => {
|
|
116
|
+
showHelp(null, 'basic');
|
|
117
|
+
});
|
|
118
|
+
|
|
113
119
|
// -----------------
|
|
114
120
|
// config
|
|
115
121
|
// -----------------
|
|
@@ -459,14 +465,19 @@ cart
|
|
|
459
465
|
try {
|
|
460
466
|
const cartData = await apiGet("/cart");
|
|
461
467
|
|
|
468
|
+
// Normalize: API returns item.product.price, flatten for display
|
|
469
|
+
const items = (cartData.items || []).map((item) => ({
|
|
470
|
+
...item,
|
|
471
|
+
name: item.name || item.product?.name || `Product #${item.productId}`,
|
|
472
|
+
price: item.price ?? item.product?.price ?? 0,
|
|
473
|
+
}));
|
|
474
|
+
|
|
462
475
|
let total = 0;
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
});
|
|
467
|
-
}
|
|
476
|
+
items.forEach((item) => {
|
|
477
|
+
total += (parseFloat(item.price) || 0) * (item.quantity || 1);
|
|
478
|
+
});
|
|
468
479
|
|
|
469
|
-
printCart(
|
|
480
|
+
printCart(items, total);
|
|
470
481
|
} catch (e) {
|
|
471
482
|
printError(e?.message || String(e));
|
|
472
483
|
process.exitCode = 1;
|
|
@@ -480,7 +491,8 @@ cart
|
|
|
480
491
|
.action(async (productId, opts) => {
|
|
481
492
|
try {
|
|
482
493
|
const quantity = parseInt(opts.quantity) || 1;
|
|
483
|
-
|
|
494
|
+
const pid = /^\d+$/.test(productId) ? parseInt(productId) : productId;
|
|
495
|
+
await apiPost("/cart/add", { productId: pid, quantity });
|
|
484
496
|
printSuccess(`Added to cart (qty: ${quantity})`);
|
|
485
497
|
} catch (e) {
|
|
486
498
|
printError(e?.message || String(e));
|
|
@@ -493,7 +505,8 @@ cart
|
|
|
493
505
|
.description("Remove product from cart")
|
|
494
506
|
.action(async (productId) => {
|
|
495
507
|
try {
|
|
496
|
-
|
|
508
|
+
const pid = /^\d+$/.test(productId) ? parseInt(productId) : productId;
|
|
509
|
+
await apiPost("/cart/remove", { productId: pid });
|
|
497
510
|
printSuccess("Removed from cart");
|
|
498
511
|
} catch (e) {
|
|
499
512
|
printError(e?.message || String(e));
|
|
@@ -522,7 +535,8 @@ program
|
|
|
522
535
|
.action(async (productId, opts) => {
|
|
523
536
|
try {
|
|
524
537
|
const quantity = parseInt(opts.quantity) || 1;
|
|
525
|
-
|
|
538
|
+
const pid = /^\d+$/.test(productId) ? parseInt(productId) : productId;
|
|
539
|
+
await apiPost("/cart/add", { productId: pid, quantity });
|
|
526
540
|
console.log(chalk.green(`Added to cart (qty: ${quantity})`));
|
|
527
541
|
} catch (e) {
|
|
528
542
|
console.error(chalk.red(e?.message || String(e)));
|
|
@@ -551,9 +565,11 @@ program
|
|
|
551
565
|
|
|
552
566
|
let total = 0;
|
|
553
567
|
cartData.items.forEach((item, i) => {
|
|
554
|
-
const
|
|
568
|
+
const name = item.name || item.product?.name || `Product #${item.productId}`;
|
|
569
|
+
const price = parseFloat(item.price ?? item.product?.price ?? 0);
|
|
570
|
+
const subtotal = price * (item.quantity || 1);
|
|
555
571
|
total += subtotal;
|
|
556
|
-
console.log(` ${i + 1}. ${
|
|
572
|
+
console.log(` ${i + 1}. ${name} x${item.quantity} = $${subtotal.toFixed(2)}`);
|
|
557
573
|
});
|
|
558
574
|
|
|
559
575
|
console.log("");
|
|
@@ -1189,7 +1205,7 @@ reward
|
|
|
1189
1205
|
.action(async (productId, pushCount) => {
|
|
1190
1206
|
try {
|
|
1191
1207
|
await apiPost("/rewards", {
|
|
1192
|
-
productId: parseInt(productId),
|
|
1208
|
+
productId: /^\d+$/.test(productId) ? parseInt(productId) : productId,
|
|
1193
1209
|
pushCount: parseInt(pushCount)
|
|
1194
1210
|
});
|
|
1195
1211
|
console.log(chalk.green(`Reward rule created! Product #${productId} every ${pushCount} pushes.`));
|
|
@@ -1306,7 +1322,7 @@ subscribe
|
|
|
1306
1322
|
}
|
|
1307
1323
|
|
|
1308
1324
|
const payload = {
|
|
1309
|
-
productId: parseInt(productId),
|
|
1325
|
+
productId: /^\d+$/.test(productId) ? parseInt(productId) : productId,
|
|
1310
1326
|
frequency,
|
|
1311
1327
|
timeOfDay: options.time,
|
|
1312
1328
|
name: options.name,
|
|
@@ -1458,7 +1474,7 @@ wishlist
|
|
|
1458
1474
|
.action(async (productId, options) => {
|
|
1459
1475
|
try {
|
|
1460
1476
|
const item = await apiPost("/wishlist", {
|
|
1461
|
-
productId: parseInt(productId),
|
|
1477
|
+
productId: /^\d+$/.test(productId) ? parseInt(productId) : productId,
|
|
1462
1478
|
note: options.note,
|
|
1463
1479
|
});
|
|
1464
1480
|
console.log(chalk.green(`✓ Added to wishlist: ${item.product?.name || productId}`));
|