@newpeak/barista-cli 0.1.7 → 0.1.8
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/commands/liberica/calendar/index.d.ts +3 -0
- package/dist/commands/liberica/calendar/index.d.ts.map +1 -0
- package/dist/commands/liberica/calendar/index.js +11 -0
- package/dist/commands/liberica/calendar/index.js.map +1 -0
- package/dist/commands/liberica/calendar/list.d.ts +3 -0
- package/dist/commands/liberica/calendar/list.d.ts.map +1 -0
- package/dist/commands/liberica/calendar/list.js +181 -0
- package/dist/commands/liberica/calendar/list.js.map +1 -0
- package/dist/commands/liberica/calendar/set.d.ts +3 -0
- package/dist/commands/liberica/calendar/set.d.ts.map +1 -0
- package/dist/commands/liberica/calendar/set.js +120 -0
- package/dist/commands/liberica/calendar/set.js.map +1 -0
- package/dist/commands/liberica/client-contacts/create.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/create.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/create.js +132 -0
- package/dist/commands/liberica/client-contacts/create.js.map +1 -0
- package/dist/commands/liberica/client-contacts/delete.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/delete.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/delete.js +139 -0
- package/dist/commands/liberica/client-contacts/delete.js.map +1 -0
- package/dist/commands/liberica/client-contacts/get.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/get.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/get.js +92 -0
- package/dist/commands/liberica/client-contacts/get.js.map +1 -0
- package/dist/commands/liberica/client-contacts/index.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/index.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/index.js +17 -0
- package/dist/commands/liberica/client-contacts/index.js.map +1 -0
- package/dist/commands/liberica/client-contacts/list.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/list.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/list.js +92 -0
- package/dist/commands/liberica/client-contacts/list.js.map +1 -0
- package/dist/commands/liberica/client-contacts/update.d.ts +3 -0
- package/dist/commands/liberica/client-contacts/update.d.ts.map +1 -0
- package/dist/commands/liberica/client-contacts/update.js +156 -0
- package/dist/commands/liberica/client-contacts/update.js.map +1 -0
- package/dist/commands/liberica/dict-types/get.d.ts +3 -0
- package/dist/commands/liberica/dict-types/get.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/get.js +62 -0
- package/dist/commands/liberica/dict-types/get.js.map +1 -0
- package/dist/commands/liberica/dict-types/index.d.ts +3 -0
- package/dist/commands/liberica/dict-types/index.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/index.js +13 -0
- package/dist/commands/liberica/dict-types/index.js.map +1 -0
- package/dist/commands/liberica/dict-types/list.d.ts +3 -0
- package/dist/commands/liberica/dict-types/list.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/list.js +91 -0
- package/dist/commands/liberica/dict-types/list.js.map +1 -0
- package/dist/commands/liberica/dict-types/update.d.ts +3 -0
- package/dist/commands/liberica/dict-types/update.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/update.js +127 -0
- package/dist/commands/liberica/dict-types/update.js.map +1 -0
- package/dist/commands/liberica/dicts/create.d.ts +3 -0
- package/dist/commands/liberica/dicts/create.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/create.js +157 -0
- package/dist/commands/liberica/dicts/create.js.map +1 -0
- package/dist/commands/liberica/dicts/delete.d.ts +3 -0
- package/dist/commands/liberica/dicts/delete.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/delete.js +106 -0
- package/dist/commands/liberica/dicts/delete.js.map +1 -0
- package/dist/commands/liberica/dicts/get.d.ts +3 -0
- package/dist/commands/liberica/dicts/get.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/get.js +69 -0
- package/dist/commands/liberica/dicts/get.js.map +1 -0
- package/dist/commands/liberica/dicts/index.d.ts +3 -0
- package/dist/commands/liberica/dicts/index.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/index.js +17 -0
- package/dist/commands/liberica/dicts/index.js.map +1 -0
- package/dist/commands/liberica/dicts/list.d.ts +3 -0
- package/dist/commands/liberica/dicts/list.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/list.js +88 -0
- package/dist/commands/liberica/dicts/list.js.map +1 -0
- package/dist/commands/liberica/dicts/update.d.ts +3 -0
- package/dist/commands/liberica/dicts/update.d.ts.map +1 -0
- package/dist/commands/liberica/dicts/update.js +112 -0
- package/dist/commands/liberica/dicts/update.js.map +1 -0
- package/dist/commands/liberica/index.d.ts.map +1 -1
- package/dist/commands/liberica/index.js +18 -0
- package/dist/commands/liberica/index.js.map +1 -1
- package/dist/commands/liberica/operations/active.d.ts +3 -0
- package/dist/commands/liberica/operations/active.d.ts.map +1 -0
- package/dist/commands/liberica/operations/active.js +152 -0
- package/dist/commands/liberica/operations/active.js.map +1 -0
- package/dist/commands/liberica/operations/batch-delete.d.ts +3 -0
- package/dist/commands/liberica/operations/batch-delete.d.ts.map +1 -0
- package/dist/commands/liberica/operations/batch-delete.js +130 -0
- package/dist/commands/liberica/operations/batch-delete.js.map +1 -0
- package/dist/commands/liberica/operations/copy.d.ts +3 -0
- package/dist/commands/liberica/operations/copy.d.ts.map +1 -0
- package/dist/commands/liberica/operations/copy.js +137 -0
- package/dist/commands/liberica/operations/copy.js.map +1 -0
- package/dist/commands/liberica/operations/create.d.ts +3 -0
- package/dist/commands/liberica/operations/create.d.ts.map +1 -0
- package/dist/commands/liberica/operations/create.js +212 -0
- package/dist/commands/liberica/operations/create.js.map +1 -0
- package/dist/commands/liberica/operations/deactive.d.ts +3 -0
- package/dist/commands/liberica/operations/deactive.d.ts.map +1 -0
- package/dist/commands/liberica/operations/deactive.js +152 -0
- package/dist/commands/liberica/operations/deactive.js.map +1 -0
- package/dist/commands/liberica/operations/delete.d.ts +3 -0
- package/dist/commands/liberica/operations/delete.d.ts.map +1 -0
- package/dist/commands/liberica/operations/delete.js +128 -0
- package/dist/commands/liberica/operations/delete.js.map +1 -0
- package/dist/commands/liberica/operations/get.d.ts +3 -0
- package/dist/commands/liberica/operations/get.d.ts.map +1 -0
- package/dist/commands/liberica/operations/get.js +93 -0
- package/dist/commands/liberica/operations/get.js.map +1 -0
- package/dist/commands/liberica/operations/index.d.ts +3 -0
- package/dist/commands/liberica/operations/index.d.ts.map +1 -0
- package/dist/commands/liberica/operations/index.js +25 -0
- package/dist/commands/liberica/operations/index.js.map +1 -0
- package/dist/commands/liberica/operations/list.d.ts +3 -0
- package/dist/commands/liberica/operations/list.d.ts.map +1 -0
- package/dist/commands/liberica/operations/list.js +141 -0
- package/dist/commands/liberica/operations/list.js.map +1 -0
- package/dist/commands/liberica/operations/update.d.ts +3 -0
- package/dist/commands/liberica/operations/update.d.ts.map +1 -0
- package/dist/commands/liberica/operations/update.js +208 -0
- package/dist/commands/liberica/operations/update.js.map +1 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.d.ts +2 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.d.ts.map +1 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.js +41 -0
- package/dist/commands/liberica/stock/__tests__/ledger.test.js.map +1 -0
- package/dist/commands/liberica/stock/__tests__/list.test.d.ts +2 -0
- package/dist/commands/liberica/stock/__tests__/list.test.d.ts.map +1 -0
- package/dist/commands/liberica/stock/__tests__/list.test.js +39 -0
- package/dist/commands/liberica/stock/__tests__/list.test.js.map +1 -0
- package/dist/commands/liberica/stock/index.d.ts +3 -0
- package/dist/commands/liberica/stock/index.d.ts.map +1 -0
- package/dist/commands/liberica/stock/index.js +11 -0
- package/dist/commands/liberica/stock/index.js.map +1 -0
- package/dist/commands/liberica/stock/ledger.d.ts +3 -0
- package/dist/commands/liberica/stock/ledger.d.ts.map +1 -0
- package/dist/commands/liberica/stock/ledger.js +154 -0
- package/dist/commands/liberica/stock/ledger.js.map +1 -0
- package/dist/commands/liberica/stock/list.d.ts +3 -0
- package/dist/commands/liberica/stock/list.d.ts.map +1 -0
- package/dist/commands/liberica/stock/list.js +127 -0
- package/dist/commands/liberica/stock/list.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/create.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/create.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/create.js +129 -0
- package/dist/commands/liberica/supplier-contacts/create.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/delete.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/delete.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/delete.js +88 -0
- package/dist/commands/liberica/supplier-contacts/delete.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/get.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/get.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/get.js +84 -0
- package/dist/commands/liberica/supplier-contacts/get.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/index.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/index.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/index.js +17 -0
- package/dist/commands/liberica/supplier-contacts/index.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/list.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/list.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/list.js +98 -0
- package/dist/commands/liberica/supplier-contacts/list.js.map +1 -0
- package/dist/commands/liberica/supplier-contacts/update.d.ts +3 -0
- package/dist/commands/liberica/supplier-contacts/update.d.ts.map +1 -0
- package/dist/commands/liberica/supplier-contacts/update.js +136 -0
- package/dist/commands/liberica/supplier-contacts/update.js.map +1 -0
- package/dist/core/api/client.d.ts +46 -0
- package/dist/core/api/client.d.ts.map +1 -1
- package/dist/core/api/client.js +865 -52
- package/dist/core/api/client.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/calendar.d.ts +28 -0
- package/dist/types/calendar.d.ts.map +1 -0
- package/dist/types/calendar.js +2 -0
- package/dist/types/calendar.js.map +1 -0
- package/dist/types/client-contact.d.ts +65 -0
- package/dist/types/client-contact.d.ts.map +1 -0
- package/dist/types/client-contact.js +4 -0
- package/dist/types/client-contact.js.map +1 -0
- package/dist/types/dict.d.ts +97 -0
- package/dist/types/dict.d.ts.map +1 -0
- package/dist/types/dict.js +2 -0
- package/dist/types/dict.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/operation.d.ts +66 -0
- package/dist/types/operation.d.ts.map +1 -0
- package/dist/types/operation.js +2 -0
- package/dist/types/operation.js.map +1 -0
- package/dist/types/stock.d.ts +133 -0
- package/dist/types/stock.d.ts.map +1 -0
- package/dist/types/stock.js +3 -0
- package/dist/types/stock.js.map +1 -0
- package/dist/types/supplier-contact.d.ts +65 -0
- package/dist/types/supplier-contact.d.ts.map +1 -0
- package/dist/types/supplier-contact.js +4 -0
- package/dist/types/supplier-contact.js.map +1 -0
- package/docs/commands/REFERENCE.md +24 -4
- package/docs/commands/liberica/calendar/DESIGN.md +333 -0
- package/docs/commands/liberica/client-contacts/create.md +152 -0
- package/docs/commands/liberica/client-contacts/delete.md +123 -0
- package/docs/commands/liberica/client-contacts/get.md +133 -0
- package/docs/commands/liberica/client-contacts/list.md +143 -0
- package/docs/commands/liberica/client-contacts/update.md +158 -0
- package/docs/commands/liberica/stock/ledger.md +209 -0
- package/docs/commands/liberica/stock/list.md +165 -0
- package/docs/commands/liberica/supplier-contacts/create.md +152 -0
- package/docs/commands/liberica/supplier-contacts/delete.md +123 -0
- package/docs/commands/liberica/supplier-contacts/get.md +133 -0
- package/docs/commands/liberica/supplier-contacts/list.md +143 -0
- package/docs/commands/liberica/supplier-contacts/update.md +158 -0
- package/package.json +1 -1
- package/src/commands/liberica/calendar/index.ts +13 -0
- package/src/commands/liberica/calendar/list.ts +214 -0
- package/src/commands/liberica/calendar/set.ts +130 -0
- package/src/commands/liberica/client-contacts/create.ts +115 -0
- package/src/commands/liberica/client-contacts/delete.ts +140 -0
- package/src/commands/liberica/client-contacts/get.ts +103 -0
- package/src/commands/liberica/client-contacts/index.ts +19 -0
- package/src/commands/liberica/client-contacts/list.ts +118 -0
- package/src/commands/liberica/client-contacts/update.ts +137 -0
- package/src/commands/liberica/dict-types/get.ts +74 -0
- package/src/commands/liberica/dict-types/index.ts +15 -0
- package/src/commands/liberica/dict-types/list.ts +118 -0
- package/src/commands/liberica/dict-types/update.ts +134 -0
- package/src/commands/liberica/dicts/create.ts +175 -0
- package/src/commands/liberica/dicts/delete.ts +107 -0
- package/src/commands/liberica/dicts/get.ts +80 -0
- package/src/commands/liberica/dicts/index.ts +19 -0
- package/src/commands/liberica/dicts/list.ts +114 -0
- package/src/commands/liberica/dicts/update.ts +116 -0
- package/src/commands/liberica/index.ts +18 -0
- package/src/commands/liberica/operations/active.ts +153 -0
- package/src/commands/liberica/operations/batch-delete.ts +131 -0
- package/src/commands/liberica/operations/copy.ts +138 -0
- package/src/commands/liberica/operations/create.ts +223 -0
- package/src/commands/liberica/operations/deactive.ts +152 -0
- package/src/commands/liberica/operations/delete.ts +128 -0
- package/src/commands/liberica/operations/design.md +587 -0
- package/src/commands/liberica/operations/get.ts +112 -0
- package/src/commands/liberica/operations/index.ts +27 -0
- package/src/commands/liberica/operations/list.ts +180 -0
- package/src/commands/liberica/operations/update.ts +218 -0
- package/src/commands/liberica/stock/index.ts +13 -0
- package/src/commands/liberica/stock/ledger.ts +159 -0
- package/src/commands/liberica/stock/list.ts +128 -0
- package/src/commands/liberica/supplier-contacts/create.ts +120 -0
- package/src/commands/liberica/supplier-contacts/delete.ts +88 -0
- package/src/commands/liberica/supplier-contacts/get.ts +94 -0
- package/src/commands/liberica/supplier-contacts/index.ts +19 -0
- package/src/commands/liberica/supplier-contacts/list.ts +130 -0
- package/src/commands/liberica/supplier-contacts/update.ts +127 -0
- package/src/core/api/client.ts +1093 -74
- package/src/index.ts +1 -1
- package/src/types/calendar.ts +36 -0
- package/src/types/client-contact.ts +78 -0
- package/src/types/dict.ts +121 -0
- package/src/types/index.ts +5 -0
- package/src/types/operation.ts +72 -0
- package/src/types/stock.ts +161 -0
- package/src/types/supplier-contact.ts +78 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { Environment } from '../../../types/index.js';
|
|
6
|
+
import { DictItem } from '../../../types/dict.js';
|
|
7
|
+
|
|
8
|
+
export function createDictGetCommand(): Command {
|
|
9
|
+
const getCommand = new Command('get');
|
|
10
|
+
getCommand.description('Get dictionary item details by ID');
|
|
11
|
+
getCommand.arguments('<dictId>');
|
|
12
|
+
getCommand.option('--json', 'Output as JSON');
|
|
13
|
+
|
|
14
|
+
getCommand.action(async (dictId: string, options: Record<string, unknown>) => {
|
|
15
|
+
const context = configManager.getCurrentContext();
|
|
16
|
+
const environment = (options.env as Environment) || context.environment;
|
|
17
|
+
const tenant = (options.tenant as string) || context.tenant;
|
|
18
|
+
|
|
19
|
+
if (!dictId) {
|
|
20
|
+
console.error(chalk.red('\n✗ Dict ID is required\n'));
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!dictId || dictId.trim() === '') {
|
|
25
|
+
console.error(chalk.red('\n✗ Invalid dict ID.\n'));
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const response = await apiClient.getDictItem(environment, tenant, dictId);
|
|
31
|
+
|
|
32
|
+
if (!response.success) {
|
|
33
|
+
const errorCode = response.error?.code || 'UNKNOWN_ERROR';
|
|
34
|
+
const errorMessage = response.error?.message || 'Unknown error';
|
|
35
|
+
|
|
36
|
+
// Handle "dict item not found" case
|
|
37
|
+
if (errorCode === '01001150001' || errorMessage.includes('不存在')) {
|
|
38
|
+
console.error(chalk.red(`\n✗ Dictionary item not found: ${dictId}\n`));
|
|
39
|
+
} else {
|
|
40
|
+
console.error(chalk.red(`\n✗ Error: ${errorMessage} (${errorCode})\n`));
|
|
41
|
+
}
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const dictItem = response.data as DictItem | null;
|
|
46
|
+
|
|
47
|
+
if (!dictItem) {
|
|
48
|
+
console.error(chalk.red('\n✗ Dictionary item not found\n'));
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (options.json) {
|
|
53
|
+
console.log(JSON.stringify({
|
|
54
|
+
success: true,
|
|
55
|
+
data: dictItem,
|
|
56
|
+
}, null, 2));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Table output
|
|
61
|
+
console.log(chalk.bold('\n📖 Dictionary Item Details\n'));
|
|
62
|
+
console.log(` ${chalk.gray('ID:')} ${dictItem.dictId}`);
|
|
63
|
+
console.log(` ${chalk.gray('Type ID:')} ${dictItem.dictTypeId}`);
|
|
64
|
+
console.log(` ${chalk.gray('Code:')} ${dictItem.dictCode}`);
|
|
65
|
+
console.log(` ${chalk.gray('Name:')} ${dictItem.dictName}`);
|
|
66
|
+
console.log(` ${chalk.gray('Value:')} ${dictItem.dictValue}`);
|
|
67
|
+
console.log(` ${chalk.gray('Sort Order:')} ${dictItem.sortOrder}`);
|
|
68
|
+
console.log(` ${chalk.gray('Status:')} ${dictItem.statusFlag === 1 ? 'Enable' : 'Disable'}`);
|
|
69
|
+
if (dictItem.remark) {
|
|
70
|
+
console.log(` ${chalk.gray('Remark:')} ${dictItem.remark}`);
|
|
71
|
+
}
|
|
72
|
+
console.log();
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error(chalk.red(`\n✗ Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return getCommand;
|
|
80
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { createDictListCommand } from './list.js';
|
|
3
|
+
import { createDictGetCommand } from './get.js';
|
|
4
|
+
import { createDictDeleteCommand } from './delete.js';
|
|
5
|
+
import { createDictCreateCommand } from './create.js';
|
|
6
|
+
import { createDictUpdateCommand } from './update.js';
|
|
7
|
+
|
|
8
|
+
export function createDictsCommand(): Command {
|
|
9
|
+
const dictsCommand = new Command('dicts');
|
|
10
|
+
dictsCommand.description('Manage dictionary items');
|
|
11
|
+
|
|
12
|
+
dictsCommand.addCommand(createDictListCommand());
|
|
13
|
+
dictsCommand.addCommand(createDictGetCommand());
|
|
14
|
+
dictsCommand.addCommand(createDictDeleteCommand());
|
|
15
|
+
dictsCommand.addCommand(createDictCreateCommand());
|
|
16
|
+
dictsCommand.addCommand(createDictUpdateCommand());
|
|
17
|
+
|
|
18
|
+
return dictsCommand;
|
|
19
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import Table from 'cli-table3';
|
|
4
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
5
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
6
|
+
import { DictItem, DictStatusFlag } from '../../../types/dict.js';
|
|
7
|
+
import { Environment } from '../../../types/index.js';
|
|
8
|
+
|
|
9
|
+
export function createDictListCommand(): Command {
|
|
10
|
+
const listCommand = new Command('list');
|
|
11
|
+
listCommand.description('List dictionary items by type');
|
|
12
|
+
|
|
13
|
+
listCommand
|
|
14
|
+
.requiredOption('-t, --type-code <string>', 'Dict type code (e.g., ID_TYPE, sex)')
|
|
15
|
+
.option('-p, --page <number>', 'Page number', '1')
|
|
16
|
+
.option('-s, --size <number>', 'Page size', '20')
|
|
17
|
+
.option('--status <string>', 'Status filter (enable/disable)')
|
|
18
|
+
.option('--json', 'Output as JSON')
|
|
19
|
+
.action(async (options) => {
|
|
20
|
+
const outputJson = options.json === true || process.argv.includes('--json');
|
|
21
|
+
|
|
22
|
+
const context = configManager.getCurrentContext();
|
|
23
|
+
const environment = (options.env as Environment) || context.environment;
|
|
24
|
+
const tenant = options.tenant || context.tenant;
|
|
25
|
+
|
|
26
|
+
const typeCode = options.typeCode as string;
|
|
27
|
+
const page = parseInt(options.page as string, 10) - 1;
|
|
28
|
+
const size = parseInt(options.size as string, 10);
|
|
29
|
+
|
|
30
|
+
const params: {
|
|
31
|
+
dictTypeCode: string;
|
|
32
|
+
pageNo: number;
|
|
33
|
+
pageSize: number;
|
|
34
|
+
status?: DictStatusFlag;
|
|
35
|
+
} = { dictTypeCode: typeCode, pageNo: page, pageSize: size };
|
|
36
|
+
|
|
37
|
+
if (options.status !== undefined) {
|
|
38
|
+
const statusVal = (options.status as string).toLowerCase();
|
|
39
|
+
if (statusVal === 'enable' || statusVal === '1') {
|
|
40
|
+
params.status = 1;
|
|
41
|
+
} else if (statusVal === 'disable' || statusVal === '2') {
|
|
42
|
+
params.status = 2;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const response = await apiClient.listDictItems(environment, tenant, params);
|
|
47
|
+
|
|
48
|
+
if (!response.success) {
|
|
49
|
+
console.error(chalk.red(`\n✗ Failed to list dict items: ${response.error?.message || 'Unknown error'}`));
|
|
50
|
+
if (response.error?.code) {
|
|
51
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
52
|
+
}
|
|
53
|
+
console.error();
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const records = (response.data as unknown as DictItem[]) || [];
|
|
58
|
+
|
|
59
|
+
if (!records || records.length === 0) {
|
|
60
|
+
if (outputJson) {
|
|
61
|
+
console.log(JSON.stringify({ success: true, data: { items: [] } }, null, 2));
|
|
62
|
+
} else {
|
|
63
|
+
console.log(chalk.bold('\n📖 Dict Items\n'));
|
|
64
|
+
console.log(chalk.gray(' No dict items found\n'));
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (outputJson) {
|
|
70
|
+
console.log(
|
|
71
|
+
JSON.stringify(
|
|
72
|
+
{
|
|
73
|
+
success: true,
|
|
74
|
+
data: {
|
|
75
|
+
items: records,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
null,
|
|
79
|
+
2
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log(chalk.bold('\n📖 Dict Items\n'));
|
|
86
|
+
|
|
87
|
+
const table = new Table({
|
|
88
|
+
head: [chalk.bold('ID'), chalk.bold('Code'), chalk.bold('Name'), chalk.bold('Sort'), chalk.bold('Status')],
|
|
89
|
+
colWidths: [14, 20, 30, 10, 10],
|
|
90
|
+
style: {
|
|
91
|
+
head: [],
|
|
92
|
+
border: [],
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
for (const item of records) {
|
|
97
|
+
const statusText = item.statusFlag === 1 ? chalk.green('Enable') : chalk.red('Disable');
|
|
98
|
+
table.push([
|
|
99
|
+
item.dictId,
|
|
100
|
+
item.dictCode || '-',
|
|
101
|
+
item.dictName || '-',
|
|
102
|
+
item.sortOrder?.toString() || '-',
|
|
103
|
+
statusText,
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log(table.toString());
|
|
108
|
+
console.log();
|
|
109
|
+
console.log(chalk.gray(` Total: ${records.length}`));
|
|
110
|
+
console.log();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return listCommand;
|
|
114
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { Environment } from '../../../types/index.js';
|
|
6
|
+
import { DictItem, UpdateDictItemRequest } from '../../../types/dict.js';
|
|
7
|
+
|
|
8
|
+
export function createDictUpdateCommand(): Command {
|
|
9
|
+
const updateCommand = new Command('update');
|
|
10
|
+
updateCommand
|
|
11
|
+
.description('Update dictionary item')
|
|
12
|
+
.argument('<dictId>', 'Dictionary item ID')
|
|
13
|
+
.option('--code <code>', 'Dictionary code')
|
|
14
|
+
.option('--name <name>', 'Dictionary name')
|
|
15
|
+
.option('--parent <id>', 'Parent dict type ID')
|
|
16
|
+
.option('--status <status>', 'Status (1=enable, 2=disable)', (val) => {
|
|
17
|
+
const num = parseInt(val, 10);
|
|
18
|
+
if (num !== 1 && num !== 2) {
|
|
19
|
+
throw new Error('Status must be 1 or 2');
|
|
20
|
+
}
|
|
21
|
+
return num;
|
|
22
|
+
})
|
|
23
|
+
.option('--sort <sort>', 'Sort order', (val) => parseInt(val, 10))
|
|
24
|
+
.option('--json', 'Output as JSON')
|
|
25
|
+
.action(async (dictId: string, options: Record<string, unknown>) => {
|
|
26
|
+
const context = configManager.getCurrentContext();
|
|
27
|
+
const environment = context.environment as Environment;
|
|
28
|
+
const tenant = context.tenant;
|
|
29
|
+
|
|
30
|
+
const fields: Partial<UpdateDictItemRequest> = {};
|
|
31
|
+
if (options.code) fields.dictCode = options.code as string;
|
|
32
|
+
if (options.name) fields.dictName = options.name as string;
|
|
33
|
+
if (options.parent) fields.dictTypeId = options.parent as string;
|
|
34
|
+
if (options.status) fields.statusFlag = options.status as 1 | 2;
|
|
35
|
+
if (options.sort) fields.sortOrder = options.sort as number;
|
|
36
|
+
|
|
37
|
+
const providedFields = Object.keys(fields).filter(
|
|
38
|
+
(k) => fields[k as keyof UpdateDictItemRequest] !== undefined
|
|
39
|
+
);
|
|
40
|
+
if (providedFields.length === 0) {
|
|
41
|
+
console.error(
|
|
42
|
+
chalk.red('\n✗ No fields to update. Provide at least one of: --code, --name, --parent, --status, --sort\n')
|
|
43
|
+
);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let currentItem: DictItem | undefined;
|
|
48
|
+
try {
|
|
49
|
+
const itemResponse = await apiClient.getDictItem(environment, tenant, dictId);
|
|
50
|
+
if (!itemResponse.success || !itemResponse.data) {
|
|
51
|
+
console.error(chalk.red(`\n✗ Dictionary item not found: ${dictId}`));
|
|
52
|
+
if (itemResponse.error?.message) {
|
|
53
|
+
console.error(chalk.gray(` ${itemResponse.error.message}`));
|
|
54
|
+
}
|
|
55
|
+
if (itemResponse.error?.code) {
|
|
56
|
+
console.error(chalk.gray(` Error code: ${itemResponse.error.code}`));
|
|
57
|
+
}
|
|
58
|
+
console.error();
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
currentItem = itemResponse.data as DictItem;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error(chalk.red(`\n✗ Failed to fetch dictionary item: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(chalk.bold(`\n📖 Update Dictionary Item (${environment})\n`));
|
|
68
|
+
console.log(chalk.gray(` Dict ID: ${dictId}`));
|
|
69
|
+
console.log(chalk.gray(` Current Name: ${currentItem.dictName}`));
|
|
70
|
+
console.log(chalk.gray('\n Changes:'));
|
|
71
|
+
for (const field of providedFields) {
|
|
72
|
+
const label = field.replace(/([A-Z])/g, (m) => ` ${m.toLowerCase()}`).trim();
|
|
73
|
+
const currentVal = (currentItem as unknown as Record<string, unknown>)[field] ?? '(not set)';
|
|
74
|
+
const newVal = fields[field as keyof UpdateDictItemRequest];
|
|
75
|
+
console.log(chalk.cyan(` ${label}: "${currentVal}" -> "${newVal}"`));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const updateData: UpdateDictItemRequest = { dictId, dictTypeId: currentItem.dictTypeId, ...fields };
|
|
79
|
+
try {
|
|
80
|
+
const response = await apiClient.updateDictItem(environment, tenant, updateData);
|
|
81
|
+
|
|
82
|
+
if (response.success) {
|
|
83
|
+
if (options.json) {
|
|
84
|
+
console.log(JSON.stringify({ success: true, data: response.data }, null, 2));
|
|
85
|
+
} else {
|
|
86
|
+
console.log(chalk.green(`\n✓ Dictionary item updated successfully\n`));
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
if (options.json) {
|
|
90
|
+
console.log(JSON.stringify({ success: false, error: response.error }, null, 2));
|
|
91
|
+
} else {
|
|
92
|
+
console.error(chalk.red(`\n✗ Update failed: ${response.error?.message || 'Unknown error'}`));
|
|
93
|
+
if (response.error?.code) {
|
|
94
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
95
|
+
}
|
|
96
|
+
console.error();
|
|
97
|
+
}
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (options.json) {
|
|
102
|
+
console.log(
|
|
103
|
+
JSON.stringify({
|
|
104
|
+
success: false,
|
|
105
|
+
error: { message: error instanceof Error ? error.message : 'Unknown error' },
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
} else {
|
|
109
|
+
console.error(chalk.red(`\n✗ Error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
110
|
+
}
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return updateCommand;
|
|
116
|
+
}
|
|
@@ -13,6 +13,13 @@ import { createMaterialsCommand } from './materials/index.js';
|
|
|
13
13
|
import { createUomsCommand } from './uoms/index.js';
|
|
14
14
|
import { createCurrencyCommand } from './currency/index.js';
|
|
15
15
|
import { createWarehousesCommand } from './warehouses/index.js';
|
|
16
|
+
import { createDictTypesCommand } from './dict-types/index.js';
|
|
17
|
+
import { createDictsCommand } from './dicts/index.js';
|
|
18
|
+
import { createOperationsCommand } from './operations/index.js';
|
|
19
|
+
import { createStockCommand } from './stock/index.js';
|
|
20
|
+
import { createCalendarCommand } from './calendar/index.js';
|
|
21
|
+
import { createClientContactsCommand } from './client-contacts/index.js';
|
|
22
|
+
import { createSupplierContactsCommand } from './supplier-contacts/index.js';
|
|
16
23
|
|
|
17
24
|
export function createLibericaCommand(): Command {
|
|
18
25
|
const libericaCommand = new Command('liberica');
|
|
@@ -31,6 +38,13 @@ export function createLibericaCommand(): Command {
|
|
|
31
38
|
libericaCommand.addCommand(createUomsCommand());
|
|
32
39
|
libericaCommand.addCommand(createCurrencyCommand());
|
|
33
40
|
libericaCommand.addCommand(createWarehousesCommand());
|
|
41
|
+
libericaCommand.addCommand(createDictTypesCommand());
|
|
42
|
+
libericaCommand.addCommand(createDictsCommand());
|
|
43
|
+
libericaCommand.addCommand(createOperationsCommand());
|
|
44
|
+
libericaCommand.addCommand(createStockCommand());
|
|
45
|
+
libericaCommand.addCommand(createCalendarCommand());
|
|
46
|
+
libericaCommand.addCommand(createClientContactsCommand());
|
|
47
|
+
libericaCommand.addCommand(createSupplierContactsCommand());
|
|
34
48
|
|
|
35
49
|
libericaCommand.action(() => {
|
|
36
50
|
console.log(chalk.bold('\n☕ Liberica Commands\n'));
|
|
@@ -47,6 +61,10 @@ export function createLibericaCommand(): Command {
|
|
|
47
61
|
console.log(' Use "barista liberica currencies <command>" for currency management');
|
|
48
62
|
console.log(' Use "barista liberica warehouses <command>" for warehouse management');
|
|
49
63
|
console.log(' Use "barista liberica warehouses locations <command>" for warehouse location management');
|
|
64
|
+
console.log(' Use "barista liberica dict-types <command>" for dictionary type management');
|
|
65
|
+
console.log(' Use "barista liberica dicts <command>" for dictionary item management');
|
|
66
|
+
console.log(' Use "barista liberica operations <command>" for operation management');
|
|
67
|
+
console.log(' Use "barista liberica stock <command>" for stock management');
|
|
50
68
|
console.log('\n Run "barista liberica <command> --help" for more details\n');
|
|
51
69
|
});
|
|
52
70
|
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { Environment } from '../../../types/index.js';
|
|
6
|
+
import { Operation } from '../../../types/operation.js';
|
|
7
|
+
|
|
8
|
+
export function createOperationActiveCommand(): Command {
|
|
9
|
+
const activeCommand = new Command('active');
|
|
10
|
+
activeCommand
|
|
11
|
+
.description('Enable (activate) operation(s)')
|
|
12
|
+
.argument('[operation-id]', 'Operation ID (mutually exclusive with --ids)')
|
|
13
|
+
.option('--ids <ids>', 'Comma-separated operation IDs for batch operations')
|
|
14
|
+
.option('--force', 'Execute the operation (skip dry-run preview)')
|
|
15
|
+
.option('--dry-run', 'Preview the operation without executing (default)')
|
|
16
|
+
.option('--json', 'Output as JSON')
|
|
17
|
+
.action(async (operationId: string | undefined, options: Record<string, unknown>) => {
|
|
18
|
+
const context = configManager.getCurrentContext();
|
|
19
|
+
const environment = context.environment as Environment;
|
|
20
|
+
const tenant = context.tenant;
|
|
21
|
+
const force = options.force === true;
|
|
22
|
+
const dryRun = !force;
|
|
23
|
+
|
|
24
|
+
const batchIds = options.ids
|
|
25
|
+
? (options.ids as string).split(',').map((id) => id.trim()).filter((id) => id !== '')
|
|
26
|
+
: [];
|
|
27
|
+
|
|
28
|
+
const jsonOutput = options.json === true;
|
|
29
|
+
|
|
30
|
+
if (!operationId && batchIds.length === 0) {
|
|
31
|
+
const errMsg = 'Invalid operation ID. Provide <operation-id> or use --ids for batch operations.';
|
|
32
|
+
if (jsonOutput) {
|
|
33
|
+
console.log(JSON.stringify({ success: false, error: { code: 'INVALID_ID', message: errMsg } }));
|
|
34
|
+
} else {
|
|
35
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
36
|
+
}
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const allIds = operationId ? [operationId] : batchIds;
|
|
41
|
+
|
|
42
|
+
if (!jsonOutput) {
|
|
43
|
+
console.log(chalk.bold(`\n↑ Enable Operation(s) (${environment})\n`));
|
|
44
|
+
if (batchIds.length > 0) {
|
|
45
|
+
console.log(chalk.gray(` Operation IDs: ${batchIds.join(', ')}`));
|
|
46
|
+
} else {
|
|
47
|
+
console.log(chalk.gray(` Operation ID: ${operationId}`));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (dryRun) {
|
|
52
|
+
if (jsonOutput) {
|
|
53
|
+
console.log(JSON.stringify({
|
|
54
|
+
success: true,
|
|
55
|
+
dryRun: true,
|
|
56
|
+
operationIds: allIds,
|
|
57
|
+
message: 'No actual API call will be made',
|
|
58
|
+
}));
|
|
59
|
+
} else {
|
|
60
|
+
console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual API call will be made\n'));
|
|
61
|
+
console.log(chalk.gray(` This operation will enable ${allIds.length} operation(s).`));
|
|
62
|
+
console.log(chalk.gray('\n To execute, add --force flag.\n'));
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const operations: Operation[] = [];
|
|
68
|
+
for (const id of allIds) {
|
|
69
|
+
try {
|
|
70
|
+
const response = await apiClient.getOperationDetail(environment, tenant, id);
|
|
71
|
+
if (!response.success || !response.data || !('operationId' in response.data)) {
|
|
72
|
+
const errMsg = `Operation not found: ${id}`;
|
|
73
|
+
if (jsonOutput) {
|
|
74
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
75
|
+
} else {
|
|
76
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
77
|
+
}
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
operations.push(response.data as Operation);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
83
|
+
const jsonErr = { success: false, error: { code: 'FETCH_ERROR', message: 'Failed to fetch operation: ' + errMsg } };
|
|
84
|
+
if (jsonOutput) {
|
|
85
|
+
console.log(JSON.stringify(jsonErr));
|
|
86
|
+
} else {
|
|
87
|
+
console.error(chalk.red(`\n✗ Failed to fetch operation: ${errMsg}\n`));
|
|
88
|
+
}
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const allAlreadyEnabled = operations.every((op) => op.statusFlag === 1);
|
|
94
|
+
if (allAlreadyEnabled) {
|
|
95
|
+
const names = operations.map((op) => `"${op.operationName}"`).join(', ');
|
|
96
|
+
const errMsg = `Operation(s) ${names} ${operations.length === 1 ? 'is' : 'are'} already enabled`;
|
|
97
|
+
if (jsonOutput) {
|
|
98
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ALREADY_ENABLED', message: errMsg } }));
|
|
99
|
+
} else {
|
|
100
|
+
console.error(chalk.yellow(`\n⚠ ${errMsg}\n`));
|
|
101
|
+
}
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!jsonOutput) {
|
|
106
|
+
if (operations.length === 1) {
|
|
107
|
+
console.log(chalk.gray(` Name: ${operations[0].operationName}`));
|
|
108
|
+
console.log(chalk.gray(` Code: ${operations[0].operationCode}`));
|
|
109
|
+
} else {
|
|
110
|
+
operations.forEach((op, i) => {
|
|
111
|
+
console.log(chalk.gray(` [${i + 1}] ${op.operationName} (${op.operationCode})`));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
console.log();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const response = await apiClient.batchActiveOperations(environment, tenant, allIds);
|
|
119
|
+
|
|
120
|
+
if (response.success) {
|
|
121
|
+
if (jsonOutput) {
|
|
122
|
+
console.log(JSON.stringify({ success: true, operationIds: allIds }));
|
|
123
|
+
} else {
|
|
124
|
+
const names = operations.map((op) => op.operationName).join(', ');
|
|
125
|
+
console.log(chalk.green(`\n✓ Operation(s) ${names || allIds.join(', ')} enabled\n`));
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
129
|
+
const errorCode = response.error?.code || 'ACTIVE_ERROR';
|
|
130
|
+
if (jsonOutput) {
|
|
131
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
132
|
+
} else {
|
|
133
|
+
console.error(chalk.red(`\n✗ Failed to enable operation(s): ${errorMsg}`));
|
|
134
|
+
if (response.error?.code) {
|
|
135
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
136
|
+
}
|
|
137
|
+
console.error();
|
|
138
|
+
}
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
143
|
+
if (jsonOutput) {
|
|
144
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
145
|
+
} else {
|
|
146
|
+
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
147
|
+
}
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return activeCommand;
|
|
153
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { Environment } from '../../../types/index.js';
|
|
6
|
+
import { Operation } from '../../../types/operation.js';
|
|
7
|
+
|
|
8
|
+
export function createBatchDeleteCommand(): Command {
|
|
9
|
+
const batchDeleteCommand = new Command('batch-delete');
|
|
10
|
+
batchDeleteCommand
|
|
11
|
+
.description('Batch delete operations')
|
|
12
|
+
.requiredOption('--ids <ids>', 'Comma-separated operation IDs')
|
|
13
|
+
.option('--force', 'Skip confirmation and delete directly')
|
|
14
|
+
.option('--dry-run', 'Preview without API call (default)')
|
|
15
|
+
.option('--json', 'Output as JSON')
|
|
16
|
+
.action(async (options: Record<string, unknown>) => {
|
|
17
|
+
const context = configManager.getCurrentContext();
|
|
18
|
+
const environment = context.environment as Environment;
|
|
19
|
+
const tenant = context.tenant;
|
|
20
|
+
const force = options.force === true;
|
|
21
|
+
const dryRun = options.dryRun === true || !force;
|
|
22
|
+
const jsonOutput = options.json === true;
|
|
23
|
+
const idsParam = options.ids as string;
|
|
24
|
+
|
|
25
|
+
if (!idsParam) {
|
|
26
|
+
const errMsg = 'Missing required option: --ids';
|
|
27
|
+
if (jsonOutput) {
|
|
28
|
+
console.log(JSON.stringify({ success: false, error: { code: 'MISSING_IDS', message: errMsg } }));
|
|
29
|
+
} else {
|
|
30
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
31
|
+
}
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ids = idsParam.split(',').map((id) => id.trim()).filter((id) => id !== '');
|
|
36
|
+
|
|
37
|
+
if (ids.length === 0) {
|
|
38
|
+
const errMsg = 'No valid operation IDs provided';
|
|
39
|
+
if (jsonOutput) {
|
|
40
|
+
console.log(JSON.stringify({ success: false, error: { code: 'INVALID_IDS', message: errMsg } }));
|
|
41
|
+
} else {
|
|
42
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
43
|
+
}
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!jsonOutput) {
|
|
48
|
+
console.log(chalk.bold(`\n🗑️ Batch Delete Operations (${environment})\n`));
|
|
49
|
+
console.log(chalk.gray(` Operation IDs: ${ids.join(', ')}`));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (dryRun) {
|
|
53
|
+
const operations: Operation[] = [];
|
|
54
|
+
for (const id of ids) {
|
|
55
|
+
try {
|
|
56
|
+
const response = await apiClient.getOperationDetail(environment, tenant, id);
|
|
57
|
+
if (response.success && response.data && 'operationId' in response.data) {
|
|
58
|
+
operations.push(response.data as Operation);
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
// skip fetch errors
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (jsonOutput) {
|
|
66
|
+
console.log(JSON.stringify({
|
|
67
|
+
success: true,
|
|
68
|
+
dryRun: true,
|
|
69
|
+
operationIds: ids,
|
|
70
|
+
operations: operations.map((op) => ({
|
|
71
|
+
operationId: op.operationId,
|
|
72
|
+
operationCode: op.operationCode,
|
|
73
|
+
operationName: op.operationName,
|
|
74
|
+
operationType: op.operationType,
|
|
75
|
+
})),
|
|
76
|
+
message: 'Dry-run mode: no actual deletion will be performed',
|
|
77
|
+
}));
|
|
78
|
+
} else {
|
|
79
|
+
console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual deletion will be performed\n'));
|
|
80
|
+
if (operations.length > 0) {
|
|
81
|
+
console.log(chalk.gray(' Operations to be deleted:'));
|
|
82
|
+
operations.forEach((op) => {
|
|
83
|
+
console.log(chalk.gray(` - ${op.operationName} (${op.operationCode}) [${op.operationId}]`));
|
|
84
|
+
});
|
|
85
|
+
} else {
|
|
86
|
+
console.log(chalk.gray(` ${ids.length} operation(s) will be deleted.`));
|
|
87
|
+
}
|
|
88
|
+
console.log();
|
|
89
|
+
console.log(chalk.yellow(' To delete, run with --force flag'));
|
|
90
|
+
console.log();
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Actual deletion with --force
|
|
96
|
+
try {
|
|
97
|
+
const response = await apiClient.batchDeleteOperations(environment, tenant, ids);
|
|
98
|
+
|
|
99
|
+
if (response.success) {
|
|
100
|
+
if (jsonOutput) {
|
|
101
|
+
console.log(JSON.stringify({ success: true, operationIds: ids }));
|
|
102
|
+
} else {
|
|
103
|
+
console.log(chalk.green(`\n✓ Deleted ${ids.length} operation(s)\n`));
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
107
|
+
const errorCode = response.error?.code || 'DELETE_ERROR';
|
|
108
|
+
if (jsonOutput) {
|
|
109
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
110
|
+
} else {
|
|
111
|
+
console.error(chalk.red(`\n✗ Failed to delete operations: ${errorMsg}`));
|
|
112
|
+
if (response.error?.code) {
|
|
113
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
114
|
+
}
|
|
115
|
+
console.error();
|
|
116
|
+
}
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
121
|
+
if (jsonOutput) {
|
|
122
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
123
|
+
} else {
|
|
124
|
+
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
125
|
+
}
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return batchDeleteCommand;
|
|
131
|
+
}
|