@marteye/studio-cli
Version:
CLI for MartEye Studio API
225 lines (221 loc) • 9.76 kB
JavaScript
;
var commander = require('commander');
var studio = require('../utils/studio.js');
var output = require('../utils/output.js');
var fs = require('fs');
function lotsCommand() {
const lots = new commander.Command('lots')
.description('Lot operations');
lots
.command('list <market-id> <sale-id>')
.description('List lots in a sale')
.option('--group <group>', 'Filter by group')
.option('--product-code <code>', 'Filter by product code')
.option('--status <status>', 'Filter by sale status')
.option('--seller-id <id>', 'Filter by seller customer ID')
.option('--buyer-id <id>', 'Filter by buyer customer ID')
.action(async (marketId, saleId, options, command) => {
const globalOptions = command.optsWithGlobals ? command.optsWithGlobals() : command.parent?.parent?.opts() || {};
try {
const studio$1 = studio.createStudioInstance(globalOptions);
const filters = {};
if (options.group)
filters.group = options.group;
if (options.productCode)
filters.productCode = options.productCode;
if (options.status)
filters.saleStatus = options.status;
if (options.sellerId)
filters.sellerCustomerId = options.sellerId;
if (options.buyerId)
filters.buyerCustomerId = options.buyerId;
const result = await studio$1.lots.list(marketId, saleId, filters);
output.output(result, globalOptions);
}
catch (err) {
output.error(err.message, err.response?.data);
process.exit(1);
}
});
lots
.command('get <market-id> <sale-id> <lot-id>')
.description('Get specific lot details')
.action(async (marketId, saleId, lotId, _options, command) => {
const globalOptions = command.optsWithGlobals ? command.optsWithGlobals() : command.parent?.parent?.opts() || {};
try {
const studio$1 = studio.createStudioInstance(globalOptions);
const result = await studio$1.lots.get(marketId, saleId, lotId);
output.output(result, globalOptions);
}
catch (err) {
output.error(err.message, err.response?.data);
process.exit(1);
}
});
lots
.command('create <market-id> <sale-id>')
.description('Create a new lot')
.option('--lot-number <number>', 'Lot number')
.option('--group <group>', 'Group')
.option('--product-code <code>', 'Product code')
.option('--seller-id <id>', 'Seller customer ID')
.option('--buyer-id <id>', 'Buyer customer ID')
.option('--price <cents>', 'Unit price in cents', parseInt)
.option('--reserve <cents>', 'Reserve price in cents', parseInt)
.option('--starting <cents>', 'Starting price in cents', parseInt)
.option('--attributes <json>', 'Attributes as JSON string')
.option('--metadata <json>', 'Metadata as JSON string')
.action(async (marketId, saleId, options, command) => {
const globalOptions = command.optsWithGlobals ? command.optsWithGlobals() : command.parent?.parent?.opts() || {};
try {
const studio$1 = studio.createStudioInstance(globalOptions);
const lotData = {};
if (options.lotNumber)
lotData.lotNumber = options.lotNumber;
if (options.group)
lotData.group = options.group;
if (options.productCode)
lotData.productCode = options.productCode;
if (options.sellerId)
lotData.sellerCustomerId = options.sellerId;
if (options.buyerId)
lotData.buyerCustomerId = options.buyerId;
if (options.price)
lotData.unitPriceInCents = options.price;
if (options.reserve)
lotData.reservePriceInCents = options.reserve;
if (options.starting)
lotData.startingPriceInCents = options.starting;
if (options.attributes) {
try {
lotData.attributes = JSON.parse(options.attributes);
}
catch (e) {
throw new Error('Invalid JSON for attributes');
}
}
if (options.metadata) {
try {
lotData.metadata = JSON.parse(options.metadata);
}
catch (e) {
throw new Error('Invalid JSON for metadata');
}
}
const result = await studio$1.lots.create(marketId, saleId, lotData);
output.success(`Lot ID: ${result.id}`);
output.output(result, globalOptions);
}
catch (err) {
output.error(err.message, err.response?.data);
process.exit(1);
}
});
lots
.command('update <market-id> <sale-id> <lot-id>')
.description('Update lot information')
.option('--product-code <code>', 'Product code')
.option('--lot-number <number>', 'Lot number')
.option('--seller-id <id>', 'Seller customer ID')
.option('--buyer-id <id>', 'Buyer customer ID')
.option('--price <cents>', 'Unit price in cents', parseInt)
.option('--reserve <cents>', 'Reserve price in cents', parseInt)
.option('--status <status>', 'Sale status')
.option('--attributes <json>', 'Attributes as JSON string')
.option('--metadata <json>', 'Metadata as JSON string')
.action(async (marketId, saleId, lotId, _options, command) => {
const globalOptions = command.optsWithGlobals ? command.optsWithGlobals() : command.parent?.parent?.opts() || {};
try {
const studio$1 = studio.createStudioInstance(globalOptions);
const updateData = {};
if (_options.productCode)
updateData.productCode = _options.productCode;
if (_options.lotNumber)
updateData.lotNumber = _options.lotNumber;
if (_options.sellerId)
updateData.sellerCustomerId = _options.sellerId;
if (_options.buyerId)
updateData.buyerCustomerId = _options.buyerId;
if (_options.price)
updateData.unitPriceInCents = _options.price;
if (_options.reserve)
updateData.reservePriceInCents = _options.reserve;
if (_options.status)
updateData.saleStatus = _options.status;
if (_options.attributes) {
try {
updateData.attributes = JSON.parse(_options.attributes);
}
catch (e) {
throw new Error('Invalid JSON for attributes');
}
}
if (_options.metadata) {
try {
updateData.metadata = JSON.parse(_options.metadata);
}
catch (e) {
throw new Error('Invalid JSON for metadata');
}
}
const result = await studio$1.lots.update(marketId, saleId, lotId, updateData);
output.output(result, globalOptions);
}
catch (err) {
output.error(err.message, err.response?.data);
process.exit(1);
}
});
lots
.command('delete <market-id> <sale-id> <lot-id>')
.description('Delete a lot')
.option('--confirm', 'Skip confirmation prompt')
.action(async (marketId, saleId, lotId, _options, command) => {
const globalOptions = command.optsWithGlobals ? command.optsWithGlobals() : command.parent?.parent?.opts() || {};
if (!_options.confirm) {
output.warning('This action cannot be undone. Use --confirm to proceed.');
process.exit(0);
}
try {
const studio$1 = studio.createStudioInstance(globalOptions);
await studio$1.lots.delete(marketId, saleId, lotId);
}
catch (err) {
output.error(err.message, err.response?.data);
process.exit(1);
}
});
lots
.command('export <market-id> <sale-id>')
.description('Export lots to file')
.option('--format <format>', 'Export format: json, csv', 'json')
.option('--output <file>', 'Output file path')
.action(async (marketId, saleId, options, command) => {
const globalOptions = command.optsWithGlobals ? command.optsWithGlobals() : command.parent?.parent?.opts() || {};
try {
const studio$1 = studio.createStudioInstance(globalOptions);
const result = await studio$1.lots.list(marketId, saleId);
const exportOptions = { ...globalOptions, format: options.format };
if (options.output) {
// Save to file instead of stdout
const originalLog = console.log;
const content = [];
console.log = (...args) => content.push(args.join(' '));
output.output(result, exportOptions);
console.log = originalLog;
fs.writeFileSync(options.output, content.join('\n'));
output.success(`Exported to ${options.output}`);
}
else {
output.output(result, exportOptions);
}
}
catch (err) {
output.error(err.message, err.response?.data);
process.exit(1);
}
});
return lots;
}
exports.lotsCommand = lotsCommand;
//# sourceMappingURL=lots.js.map