@newpeak/barista-cli 0.1.5 → 0.1.6

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 (79) hide show
  1. package/dist/commands/liberica/currency/create.d.ts +3 -0
  2. package/dist/commands/liberica/currency/create.d.ts.map +1 -0
  3. package/dist/commands/liberica/currency/create.js +168 -0
  4. package/dist/commands/liberica/currency/create.js.map +1 -0
  5. package/dist/commands/liberica/currency/delete.d.ts +3 -0
  6. package/dist/commands/liberica/currency/delete.d.ts.map +1 -0
  7. package/dist/commands/liberica/currency/delete.js +122 -0
  8. package/dist/commands/liberica/currency/delete.js.map +1 -0
  9. package/dist/commands/liberica/currency/disable.d.ts +3 -0
  10. package/dist/commands/liberica/currency/disable.d.ts.map +1 -0
  11. package/dist/commands/liberica/currency/disable.js +145 -0
  12. package/dist/commands/liberica/currency/disable.js.map +1 -0
  13. package/dist/commands/liberica/currency/enable.d.ts +3 -0
  14. package/dist/commands/liberica/currency/enable.d.ts.map +1 -0
  15. package/dist/commands/liberica/currency/enable.js +125 -0
  16. package/dist/commands/liberica/currency/enable.js.map +1 -0
  17. package/dist/commands/liberica/currency/get.d.ts +3 -0
  18. package/dist/commands/liberica/currency/get.d.ts.map +1 -0
  19. package/dist/commands/liberica/currency/get.js +80 -0
  20. package/dist/commands/liberica/currency/get.js.map +1 -0
  21. package/dist/commands/liberica/currency/index.d.ts +3 -0
  22. package/dist/commands/liberica/currency/index.d.ts.map +1 -0
  23. package/dist/commands/liberica/currency/index.js +21 -0
  24. package/dist/commands/liberica/currency/index.js.map +1 -0
  25. package/dist/commands/liberica/currency/list.d.ts +3 -0
  26. package/dist/commands/liberica/currency/list.d.ts.map +1 -0
  27. package/dist/commands/liberica/currency/list.js +106 -0
  28. package/dist/commands/liberica/currency/list.js.map +1 -0
  29. package/dist/commands/liberica/currency/update.d.ts +3 -0
  30. package/dist/commands/liberica/currency/update.d.ts.map +1 -0
  31. package/dist/commands/liberica/currency/update.js +123 -0
  32. package/dist/commands/liberica/currency/update.js.map +1 -0
  33. package/dist/commands/liberica/index.d.ts.map +1 -1
  34. package/dist/commands/liberica/index.js +3 -0
  35. package/dist/commands/liberica/index.js.map +1 -1
  36. package/dist/core/api/client.d.ts +10 -0
  37. package/dist/core/api/client.d.ts.map +1 -1
  38. package/dist/core/api/client.js +185 -0
  39. package/dist/core/api/client.js.map +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/types/currency.d.ts +74 -0
  42. package/dist/types/currency.d.ts.map +1 -0
  43. package/dist/types/currency.js +2 -0
  44. package/dist/types/currency.js.map +1 -0
  45. package/docs/COMMAND_DESIGN_SPEC.md +42 -13
  46. package/docs/commands/liberica/currency/create.md +145 -0
  47. package/docs/commands/liberica/currency/delete.md +121 -0
  48. package/docs/commands/liberica/currency/disable.md +119 -0
  49. package/docs/commands/liberica/currency/enable.md +115 -0
  50. package/docs/commands/liberica/currency/get.md +118 -0
  51. package/docs/commands/liberica/currency/list.md +149 -0
  52. package/docs/commands/liberica/currency/update.md +141 -0
  53. package/package.json +1 -1
  54. package/src/commands/liberica/currency/create.ts +183 -0
  55. package/src/commands/liberica/currency/delete.ts +124 -0
  56. package/src/commands/liberica/currency/disable.ts +147 -0
  57. package/src/commands/liberica/currency/enable.ts +128 -0
  58. package/src/commands/liberica/currency/get.ts +91 -0
  59. package/src/commands/liberica/currency/index.ts +23 -0
  60. package/src/commands/liberica/currency/list.ts +140 -0
  61. package/src/commands/liberica/currency/update.ts +129 -0
  62. package/src/commands/liberica/index.ts +3 -0
  63. package/src/core/api/client.ts +236 -0
  64. package/src/index.ts +1 -1
  65. package/src/types/currency.ts +90 -0
  66. /package/docs/commands/liberica/{materials-create.md → materials/create.md} +0 -0
  67. /package/docs/commands/liberica/{materials-delete.md → materials/delete.md} +0 -0
  68. /package/docs/commands/liberica/{materials-disable.md → materials/disable.md} +0 -0
  69. /package/docs/commands/liberica/{materials-enable.md → materials/enable.md} +0 -0
  70. /package/docs/commands/liberica/{materials-get.md → materials/get.md} +0 -0
  71. /package/docs/commands/liberica/{materials-list.md → materials/list.md} +0 -0
  72. /package/docs/commands/liberica/{materials-update.md → materials/update.md} +0 -0
  73. /package/docs/commands/liberica/{uoms-create.md → uoms/create.md} +0 -0
  74. /package/docs/commands/liberica/{uoms-delete.md → uoms/delete.md} +0 -0
  75. /package/docs/commands/liberica/{uoms-disable.md → uoms/disable.md} +0 -0
  76. /package/docs/commands/liberica/{uoms-enable.md → uoms/enable.md} +0 -0
  77. /package/docs/commands/liberica/{uoms-get.md → uoms/get.md} +0 -0
  78. /package/docs/commands/liberica/{uoms-list.md → uoms/list.md} +0 -0
  79. /package/docs/commands/liberica/{uoms-update.md → uoms/update.md} +0 -0
@@ -0,0 +1,147 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import inquirer from 'inquirer';
4
+ import { configManager } from '../../../core/config/manager.js';
5
+ import { apiClient } from '../../../core/api/client.js';
6
+ import { Environment } from '../../../types/index.js';
7
+ import { Currency } from '../../../types/currency.js';
8
+
9
+ export function createCurrencyDisableCommand(): Command {
10
+ const disableCommand = new Command('disable');
11
+ disableCommand
12
+ .description('Disable (deactivate) a currency')
13
+ .argument('<currencyId>', 'Currency ID')
14
+ .option('--force', 'Skip confirmation prompt')
15
+ .option('--dry-run', 'Preview the operation without executing')
16
+ .option('--json', 'Output as JSON')
17
+ .action(async (currencyId: string, 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 = options.dryRun === true;
23
+
24
+ (options as Record<string, unknown>).json = process.argv.includes('--json');
25
+ const jsonOutput = options.json === true;
26
+
27
+ if (!currencyId || currencyId.trim() === '') {
28
+ const errMsg = 'Invalid currency ID';
29
+ if (jsonOutput) {
30
+ console.log(JSON.stringify({ success: false, error: { code: 'INVALID_ID', message: errMsg } }));
31
+ } else {
32
+ console.error(chalk.red(`\n✗ ${errMsg}\n`));
33
+ }
34
+ process.exit(1);
35
+ }
36
+
37
+ if (!jsonOutput) {
38
+ console.log(chalk.bold(`\n⬇ Disable Currency (${environment})\n`));
39
+ console.log(chalk.gray(` Currency ID: ${currencyId}`));
40
+ }
41
+
42
+ if (dryRun) {
43
+ if (jsonOutput) {
44
+ console.log(JSON.stringify({ success: true, dryRun: true, message: 'No actual API call will be made' }));
45
+ } else {
46
+ console.log(chalk.cyan('\n🔍 Dry-Run Mode: No actual API call will be made\n'));
47
+ console.log(chalk.gray(' This operation will disable the currency.'));
48
+ console.log();
49
+ }
50
+ return;
51
+ }
52
+
53
+ let currency: Currency | undefined;
54
+ try {
55
+ const currencyResponse = await apiClient.getCurrency(environment, tenant, currencyId);
56
+ if (!currencyResponse.success || !currencyResponse.data || !('currencyId' in currencyResponse.data)) {
57
+ const errMsg = `Currency not found: ${currencyId}`;
58
+ if (jsonOutput) {
59
+ console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
60
+ } else {
61
+ console.error(chalk.red(`\n✗ ${errMsg}\n`));
62
+ }
63
+ process.exit(1);
64
+ }
65
+ currency = currencyResponse.data as Currency;
66
+ } catch (error) {
67
+ const errMsg = error instanceof Error ? error.message : 'Unknown error';
68
+ const jsonErr = { success: false, error: { code: 'FETCH_ERROR', message: 'Failed to fetch currency: ' + errMsg } };
69
+ if (jsonOutput) {
70
+ console.log(JSON.stringify(jsonErr));
71
+ } else {
72
+ console.error(chalk.red(`\n✗ Failed to fetch currency: ${errMsg}\n`));
73
+ }
74
+ process.exit(1);
75
+ }
76
+
77
+ if (currency.statusFlag === 2) {
78
+ const errMsg = `Currency "${currency.currencyName}" is already disabled`;
79
+ if (jsonOutput) {
80
+ console.log(JSON.stringify({ success: false, error: { code: 'ALREADY_DISABLED', message: errMsg } }));
81
+ } else {
82
+ console.error(chalk.yellow(`\n⚠ ${errMsg}\n`));
83
+ }
84
+ process.exit(1);
85
+ }
86
+
87
+ if (!force) {
88
+ if (!jsonOutput) {
89
+ console.log(chalk.gray(` Name: ${currency.currencyName}`));
90
+ console.log(chalk.gray(` Code: ${currency.currencyCode}`));
91
+ }
92
+
93
+ const { confirm } = await inquirer.prompt([
94
+ {
95
+ type: 'confirm',
96
+ name: 'confirm',
97
+ message: `Disable currency "${currency.currencyName}"?`,
98
+ default: false,
99
+ },
100
+ ]);
101
+
102
+ if (!confirm) {
103
+ if (jsonOutput) {
104
+ console.log(JSON.stringify({ success: false, error: { code: 'CANCELLED', message: 'Operation cancelled' } }));
105
+ } else {
106
+ console.log(chalk.gray('\n Operation cancelled.\n'));
107
+ }
108
+ process.exit(0);
109
+ }
110
+ }
111
+
112
+ try {
113
+ const response = await apiClient.disableCurrencies(environment, tenant, [currencyId]);
114
+
115
+ if (response.success) {
116
+ if (jsonOutput) {
117
+ console.log(JSON.stringify({ success: true, currencyId, name: currency?.currencyName }));
118
+ } else {
119
+ console.log(chalk.green(`\n✓ Currency ${currency?.currencyName || currencyId} disabled\n`));
120
+ }
121
+ } else {
122
+ const errorMsg = response.error?.message || 'Unknown error';
123
+ const errorCode = response.error?.code || 'DISABLE_ERROR';
124
+ if (jsonOutput) {
125
+ console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
126
+ } else {
127
+ console.error(chalk.red(`\n✗ Failed to disable currency: ${errorMsg}`));
128
+ if (response.error?.code) {
129
+ console.error(chalk.gray(` Error code: ${response.error.code}`));
130
+ }
131
+ console.error();
132
+ }
133
+ process.exit(1);
134
+ }
135
+ } catch (error) {
136
+ const errMsg = error instanceof Error ? error.message : 'Unknown error';
137
+ if (jsonOutput) {
138
+ console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
139
+ } else {
140
+ console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
141
+ }
142
+ process.exit(1);
143
+ }
144
+ });
145
+
146
+ return disableCommand;
147
+ }
@@ -0,0 +1,128 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import inquirer from 'inquirer';
4
+ import { configManager } from '../../../core/config/manager.js';
5
+ import { apiClient } from '../../../core/api/client.js';
6
+ import { Environment } from '../../../types/index.js';
7
+ import { Currency } from '../../../types/currency.js';
8
+
9
+ export function createCurrencyEnableCommand(): Command {
10
+ const enableCommand = new Command('enable');
11
+ enableCommand
12
+ .description('Enable (activate) a currency')
13
+ .argument('<currencyId>', 'Currency ID')
14
+ .option('--json', 'Output as JSON')
15
+ .action(async (currencyId: string, options: Record<string, unknown>) => {
16
+ const context = configManager.getCurrentContext();
17
+ const environment = context.environment as Environment;
18
+ const tenant = context.tenant;
19
+
20
+ (options as Record<string, unknown>).json = process.argv.includes('--json');
21
+ const jsonOutput = options.json === true;
22
+
23
+ if (!currencyId || currencyId.trim() === '') {
24
+ const errMsg = 'Invalid currency ID';
25
+ if (jsonOutput) {
26
+ console.log(JSON.stringify({ success: false, error: { code: 'INVALID_ID', message: errMsg } }));
27
+ } else {
28
+ console.error(chalk.red(`\n✗ ${errMsg}\n`));
29
+ }
30
+ process.exit(1);
31
+ }
32
+
33
+ if (!jsonOutput) {
34
+ console.log(chalk.bold(`\n✓ Enable Currency (${environment})\n`));
35
+ console.log(chalk.gray(` Currency ID: ${currencyId}`));
36
+ }
37
+
38
+ // Get currency details for confirmation
39
+ let currency: Currency | undefined;
40
+ try {
41
+ const currencyResponse = await apiClient.getCurrency(environment, tenant, currencyId);
42
+ if (!currencyResponse.success || !currencyResponse.data || !('currencyId' in currencyResponse.data)) {
43
+ const errMsg = `Currency not found: ${currencyId}`;
44
+ if (jsonOutput) {
45
+ console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
46
+ } else {
47
+ console.error(chalk.red(`\n✗ ${errMsg}\n`));
48
+ }
49
+ process.exit(1);
50
+ }
51
+ currency = currencyResponse.data as Currency;
52
+ } catch (error) {
53
+ const errMsg = error instanceof Error ? error.message : 'Unknown error';
54
+ if (jsonOutput) {
55
+ console.log(JSON.stringify({ success: false, error: { code: 'FETCH_ERROR', message: `Failed to fetch currency: ${errMsg}` } }));
56
+ } else {
57
+ console.error(chalk.red(`\n✗ Failed to fetch currency: ${errMsg}\n`));
58
+ }
59
+ process.exit(1);
60
+ }
61
+
62
+ // Check if already enabled
63
+ if (currency.statusFlag === 1) {
64
+ const errMsg = `Currency "${currency.currencyName}" is already enabled`;
65
+ if (jsonOutput) {
66
+ console.log(JSON.stringify({ success: false, error: { code: 'ALREADY_ENABLED', message: errMsg } }));
67
+ } else {
68
+ console.error(chalk.yellow(`\n⚠ ${errMsg}\n`));
69
+ }
70
+ process.exit(1);
71
+ }
72
+
73
+ if (!jsonOutput) {
74
+ console.log(chalk.gray(` Name: ${currency.currencyName}`));
75
+ console.log(chalk.gray(` Code: ${currency.currencyCode}`));
76
+
77
+ const { confirm } = await inquirer.prompt([
78
+ {
79
+ type: 'confirm',
80
+ name: 'confirm',
81
+ message: `Enable currency "${currency.currencyName}"?`,
82
+ default: false,
83
+ },
84
+ ]);
85
+
86
+ if (!confirm) {
87
+ console.log(chalk.gray('\n Operation cancelled.\n'));
88
+ process.exit(0);
89
+ }
90
+ }
91
+
92
+ // Execute enable via batch endpoint (single-element array)
93
+ try {
94
+ const response = await apiClient.enableCurrencies(environment, tenant, [currencyId]);
95
+
96
+ if (response.success) {
97
+ if (jsonOutput) {
98
+ console.log(JSON.stringify({ success: true, currencyId, name: currency?.currencyName }));
99
+ } else {
100
+ console.log(chalk.green(`\n✓ Currency ${currency?.currencyName || currencyId} enabled\n`));
101
+ }
102
+ } else {
103
+ const errorMsg = response.error?.message || 'Unknown error';
104
+ const errorCode = response.error?.code || 'ENABLE_ERROR';
105
+ if (jsonOutput) {
106
+ console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
107
+ } else {
108
+ console.error(chalk.red(`\n✗ Failed to enable currency: ${errorMsg}`));
109
+ if (response.error?.code) {
110
+ console.error(chalk.gray(` Error code: ${response.error.code}`));
111
+ }
112
+ console.error();
113
+ }
114
+ process.exit(1);
115
+ }
116
+ } catch (error) {
117
+ const errMsg = error instanceof Error ? error.message : 'Unknown error';
118
+ if (jsonOutput) {
119
+ console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
120
+ } else {
121
+ console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
122
+ }
123
+ process.exit(1);
124
+ }
125
+ });
126
+
127
+ return enableCommand;
128
+ }
@@ -0,0 +1,91 @@
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 { Currency } from '../../../types/currency.js';
7
+
8
+ export function createCurrencyGetCommand(): Command {
9
+ const getCommand = new Command('get');
10
+ getCommand.description('Get currency details by ID');
11
+ getCommand.arguments('<currencyId>');
12
+ getCommand.option('--json', 'Output as JSON');
13
+
14
+ getCommand.action(async (currencyId: 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 (!currencyId || currencyId.trim() === '') {
20
+ console.error(chalk.red('\n✗ Currency ID is required\n'));
21
+ process.exit(1);
22
+ }
23
+
24
+ try {
25
+ const response = await apiClient.getCurrency(environment, tenant, currencyId);
26
+
27
+ if (!response.success) {
28
+ const errorCode = response.error?.code || 'UNKNOWN_ERROR';
29
+ const errorMessage = response.error?.message || 'Unknown error';
30
+
31
+ if (errorCode === '01001150001' || errorMessage.includes('不存在')) {
32
+ console.error(chalk.red(`\n✗ Currency not found: ${currencyId}\n`));
33
+ } else {
34
+ console.error(chalk.red(`\n✗ Error: ${errorMessage} (${errorCode})\n`));
35
+ }
36
+ process.exit(1);
37
+ }
38
+
39
+ const currency = response.data as Currency | null;
40
+
41
+ // Workaround: Commander.js doesn't propagate --json to nested subcommands properly
42
+ (options as Record<string, unknown>).json = process.argv.includes('--json');
43
+ const outputJson = (options as Record<string, unknown>).json === true;
44
+
45
+ if (!currency) {
46
+ console.error(chalk.red('\n✗ Currency not found\n'));
47
+ process.exit(1);
48
+ }
49
+
50
+ if (outputJson) {
51
+ console.log(JSON.stringify({
52
+ success: true,
53
+ data: currency,
54
+ }, null, 2));
55
+ return;
56
+ }
57
+
58
+ // Table output
59
+ console.log(chalk.bold('\n💱 Currency Details\n'));
60
+ console.log(` ${chalk.gray('ID:')} ${currency.currencyId}`);
61
+ console.log(` ${chalk.gray('Code:')} ${currency.currencyCode}`);
62
+ console.log(` ${chalk.gray('Name:')} ${currency.currencyName}`);
63
+ console.log(` ${chalk.gray('Sign:')} ${currency.currencySign}`);
64
+ if (currency.currencyRateType) {
65
+ console.log(` ${chalk.gray('Rate Type:')} ${currency.currencyRateType}`);
66
+ }
67
+ if (currency.currencyExchangeMethod) {
68
+ console.log(` ${chalk.gray('Exchange Method:')} ${currency.currencyExchangeMethod}`);
69
+ }
70
+ if (currency.unitPriceFractionPlaces !== undefined) {
71
+ console.log(` ${chalk.gray('Unit Price Fraction Places:')} ${currency.unitPriceFractionPlaces}`);
72
+ }
73
+ if (currency.amountFractionPlaces !== undefined) {
74
+ console.log(` ${chalk.gray('Amount Fraction Places:')} ${currency.amountFractionPlaces}`);
75
+ }
76
+ console.log(` ${chalk.gray('Status:')} ${currency.statusFlag === 1 ? 'Enable' : 'Disable'}`);
77
+ if (currency.currencyRate) {
78
+ console.log(` ${chalk.gray('Rate:')} ${currency.currencyRate}`);
79
+ }
80
+ if (currency.remark) {
81
+ console.log(` ${chalk.gray('Remark:')} ${currency.remark}`);
82
+ }
83
+ console.log();
84
+ } catch (error) {
85
+ console.error(chalk.red(`\n✗ Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
86
+ process.exit(1);
87
+ }
88
+ });
89
+
90
+ return getCommand;
91
+ }
@@ -0,0 +1,23 @@
1
+ import { Command } from 'commander';
2
+ import { createCurrencyListCommand } from './list.js';
3
+ import { createCurrencyGetCommand } from './get.js';
4
+ import { createCurrencyCreateCommand } from './create.js';
5
+ import { createCurrencyUpdateCommand } from './update.js';
6
+ import { createCurrencyDeleteCommand } from './delete.js';
7
+ import { createCurrencyEnableCommand } from './enable.js';
8
+ import { createCurrencyDisableCommand } from './disable.js';
9
+
10
+ export function createCurrencyCommand(): Command {
11
+ const currencyCommand = new Command('currency');
12
+ currencyCommand.description('Manage currencies');
13
+
14
+ currencyCommand.addCommand(createCurrencyListCommand());
15
+ currencyCommand.addCommand(createCurrencyGetCommand());
16
+ currencyCommand.addCommand(createCurrencyCreateCommand());
17
+ currencyCommand.addCommand(createCurrencyUpdateCommand());
18
+ currencyCommand.addCommand(createCurrencyDeleteCommand());
19
+ currencyCommand.addCommand(createCurrencyEnableCommand());
20
+ currencyCommand.addCommand(createCurrencyDisableCommand());
21
+
22
+ return currencyCommand;
23
+ }
@@ -0,0 +1,140 @@
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 { CurrencyListResponse, CurrencyStatusFlag } from '../../../types/currency.js';
7
+ import { Environment } from '../../../types/index.js';
8
+
9
+ export function createCurrencyListCommand(): Command {
10
+ const listCommand = new Command('list');
11
+ listCommand.description('List currencies with pagination');
12
+
13
+ listCommand
14
+ .option('-p, --page <number>', 'Page number', '1')
15
+ .option('-s, --size <number>', 'Page size', '20')
16
+ .option('--status <string>', 'Status filter (enable/disable)')
17
+ .option('--search <string>', 'Search filter (code or name)')
18
+ .option('--json', 'Output as JSON')
19
+ .action(async (options) => {
20
+ // Commander.js boolean flag parsing workaround
21
+ const outputJson = options.json === true || process.argv.includes('--json');
22
+
23
+ const context = configManager.getCurrentContext();
24
+ const environment = (options.env as Environment) || context.environment;
25
+ const tenant = options.tenant || context.tenant;
26
+
27
+ const page = parseInt(options.page as string, 10) - 1;
28
+ const size = parseInt(options.size as string, 10);
29
+
30
+ const params: {
31
+ pageNo: number;
32
+ pageSize: number;
33
+ status?: CurrencyStatusFlag;
34
+ currencyCode?: string;
35
+ currencyName?: string;
36
+ } = { pageNo: page, pageSize: size };
37
+
38
+ if (options.status !== undefined) {
39
+ const statusVal = (options.status as string).toLowerCase();
40
+ if (statusVal === 'enable' || statusVal === '1') {
41
+ params.status = 1;
42
+ } else if (statusVal === 'disable' || statusVal === '2') {
43
+ params.status = 2;
44
+ }
45
+ }
46
+
47
+ if (options.search !== undefined) {
48
+ const searchVal = options.search as string;
49
+ // Search can match either code or name; pass as code for API
50
+ params.currencyCode = searchVal;
51
+ params.currencyName = searchVal;
52
+ }
53
+
54
+ const response = await apiClient.listCurrencies(environment, tenant, params);
55
+
56
+ if (!response.success) {
57
+ console.error(chalk.red(`\n✗ Failed to list currencies: ${response.error?.message || 'Unknown error'}`));
58
+ if (response.error?.code) {
59
+ console.error(chalk.gray(` Error code: ${response.error.code}`));
60
+ }
61
+ console.error();
62
+ process.exit(1);
63
+ }
64
+
65
+ const data = response.data as CurrencyListResponse | null;
66
+
67
+ if (!data) {
68
+ if (outputJson) {
69
+ console.log(JSON.stringify({ success: true, data: { items: [], pagination: { pageNo: 0, pageSize: 20, totalRows: 0 } } }, null, 2));
70
+ } else {
71
+ console.log(chalk.bold('\n💱 Currency List\n'));
72
+ console.log(chalk.gray(' No currencies found\n'));
73
+ }
74
+ return;
75
+ }
76
+
77
+ if (outputJson) {
78
+ console.log(
79
+ JSON.stringify(
80
+ {
81
+ success: true,
82
+ data: {
83
+ items: data.rows || [],
84
+ pagination: {
85
+ pageNo: data.pageNo,
86
+ pageSize: data.pageSize,
87
+ totalRows: data.totalRows,
88
+ },
89
+ },
90
+ },
91
+ null,
92
+ 2
93
+ )
94
+ );
95
+ return;
96
+ }
97
+
98
+ const records = data.rows || [];
99
+
100
+ if (records.length === 0) {
101
+ console.log(chalk.bold('\n💱 Currency List\n'));
102
+ console.log(chalk.gray(' No currencies found\n'));
103
+ return;
104
+ }
105
+
106
+ console.log(chalk.bold('\n💱 Currency List\n'));
107
+
108
+ const table = new Table({
109
+ head: [chalk.bold('ID'), chalk.bold('Code'), chalk.bold('Name'), chalk.bold('Sign'), chalk.bold('Rate'), chalk.bold('Status')],
110
+ colWidths: [14, 12, 30, 10, 16, 10],
111
+ style: {
112
+ head: [],
113
+ border: [],
114
+ },
115
+ });
116
+
117
+ for (const currency of records) {
118
+ const statusText = currency.statusFlag === 1 ? chalk.green('Enable') : chalk.red('Disable');
119
+ table.push([
120
+ currency.currencyId,
121
+ currency.currencyCode || '-',
122
+ currency.currencyName || '-',
123
+ currency.currencySign || '-',
124
+ currency.currencyRate || '-',
125
+ statusText,
126
+ ]);
127
+ }
128
+
129
+ console.log(table.toString());
130
+ console.log();
131
+ console.log(
132
+ chalk.gray(
133
+ ` Total: ${data.totalRows} | Page: ${data.pageNo + 1} / ${Math.ceil(data.totalRows / data.pageSize) || 1} | Size: ${data.pageSize}`
134
+ )
135
+ );
136
+ console.log();
137
+ });
138
+
139
+ return listCommand;
140
+ }
@@ -0,0 +1,129 @@
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 { Currency, UpdateCurrencyRequest } from '../../../types/currency.js';
6
+ import { Environment } from '../../../types/index.js';
7
+
8
+ export function createCurrencyUpdateCommand(): Command {
9
+ const updateCommand = new Command('update');
10
+ updateCommand.description('Update currency information').argument('<currencyId>', 'Currency ID');
11
+
12
+ updateCommand
13
+ .option('-n, --name <name>', 'Currency name')
14
+ .option('-s, --sign <sign>', 'Currency sign/symbol')
15
+ .option('-r, --rate <rate>', 'Currency exchange rate')
16
+ .option('--unit-fraction <number>', 'Unit price fraction places')
17
+ .option('--amount-fraction <number>', 'Amount fraction places')
18
+ .option('--remark <text>', 'Remark')
19
+ .option('--dry-run', 'Preview changes without making API call')
20
+ .option('--json', 'Output result as JSON')
21
+ .action(async (currencyId: string, options: Record<string, unknown>) => {
22
+ const context = configManager.getCurrentContext();
23
+ const environment = context.environment as Environment;
24
+ const tenant = context.tenant;
25
+
26
+ const fields: Partial<UpdateCurrencyRequest> = {};
27
+ if (options.name) fields.currencyName = options.name as string;
28
+ if (options.sign) fields.currencySign = options.sign as string;
29
+ if (options.rate) fields.currencyRate = options.rate as string;
30
+ if (options.unitFraction) fields.unitPriceFractionPlaces = parseInt(options.unitFraction as string, 10);
31
+ if (options.amountFraction) fields.amountFractionPlaces = parseInt(options.amountFraction as string, 10);
32
+ if (options.remark) fields.remark = options.remark as string;
33
+
34
+ const providedFields = Object.keys(fields).filter(
35
+ (k) => fields[k as keyof UpdateCurrencyRequest] !== undefined
36
+ );
37
+ if (providedFields.length === 0) {
38
+ console.error(
39
+ chalk.red('\n✗ No fields to update. Provide at least one of: --name, --sign, --rate, --unit-fraction, --amount-fraction, --remark\n')
40
+ );
41
+ process.exit(1);
42
+ }
43
+
44
+ if (options.dryRun) {
45
+ console.log(chalk.bold(`\n💱 Update Currency — Dry Run (${environment})\n`));
46
+ console.log(chalk.gray(` Currency ID: ${currencyId}`));
47
+ console.log(chalk.gray('\n Changes to be applied:'));
48
+ for (const field of providedFields) {
49
+ const label = field.replace(/([A-Z])/g, (m) => ` ${m.toLowerCase()}`).trim();
50
+ console.log(chalk.cyan(` ${label}: "${fields[field as keyof UpdateCurrencyRequest]}"`));
51
+ }
52
+ console.log();
53
+ return;
54
+ }
55
+
56
+ let currentCurrency: Currency | undefined;
57
+ try {
58
+ const currencyResponse = await apiClient.getCurrency(environment, tenant, currencyId);
59
+ if (!currencyResponse.success || !currencyResponse.data) {
60
+ console.error(chalk.red(`\n✗ Currency not found: ${currencyId}`));
61
+ if (currencyResponse.error?.message) {
62
+ console.error(chalk.gray(` ${currencyResponse.error.message}`));
63
+ }
64
+ if (currencyResponse.error?.code) {
65
+ console.error(chalk.gray(` Error code: ${currencyResponse.error.code}`));
66
+ }
67
+ console.error();
68
+ process.exit(1);
69
+ }
70
+ currentCurrency = currencyResponse.data as Currency;
71
+ } catch (error) {
72
+ console.error(chalk.red(`\n✗ Failed to fetch currency: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
73
+ process.exit(1);
74
+ }
75
+
76
+ (options as Record<string, unknown>).json = process.argv.includes('--json');
77
+ const outputJson = (options as Record<string, unknown>).json === true;
78
+
79
+ console.log(chalk.bold(`\n💱 Update Currency (${environment})\n`));
80
+ console.log(chalk.gray(` Currency ID: ${currencyId}`));
81
+ console.log(chalk.gray(` Current Code: ${currentCurrency.currencyCode}`));
82
+ console.log(chalk.gray(` Current Name: ${currentCurrency.currencyName}`));
83
+ console.log(chalk.gray('\n Changes:'));
84
+ for (const field of providedFields) {
85
+ const label = field.replace(/([A-Z])/g, (m) => ` ${m.toLowerCase()}`).trim();
86
+ const currentVal = (currentCurrency as unknown as Record<string, unknown>)[field] ?? '(not set)';
87
+ const newVal = fields[field as keyof UpdateCurrencyRequest];
88
+ console.log(chalk.cyan(` ${label}: "${currentVal}" → "${newVal}"`));
89
+ }
90
+
91
+ const updateData = { currencyId, ...fields } as UpdateCurrencyRequest;
92
+ try {
93
+ const response = await apiClient.updateCurrency(environment, tenant, updateData);
94
+
95
+ if (response.success) {
96
+ if (outputJson) {
97
+ console.log(JSON.stringify({ success: true, data: response.data }, null, 2));
98
+ } else {
99
+ console.log(chalk.green(`\n✓ Currency updated successfully\n`));
100
+ }
101
+ } else {
102
+ if (outputJson) {
103
+ console.log(JSON.stringify({ success: false, error: response.error }, null, 2));
104
+ } else {
105
+ console.error(chalk.red(`\n✗ Update failed: ${response.error?.message || 'Unknown error'}`));
106
+ if (response.error?.code) {
107
+ console.error(chalk.gray(` Error code: ${response.error.code}`));
108
+ }
109
+ console.error();
110
+ }
111
+ process.exit(1);
112
+ }
113
+ } catch (error) {
114
+ if (outputJson) {
115
+ console.log(
116
+ JSON.stringify({
117
+ success: false,
118
+ error: { message: error instanceof Error ? error.message : 'Unknown error' },
119
+ })
120
+ );
121
+ } else {
122
+ console.error(chalk.red(`\n✗ Error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
123
+ }
124
+ process.exit(1);
125
+ }
126
+ });
127
+
128
+ return updateCommand;
129
+ }
@@ -11,6 +11,7 @@ import { createClientsCommand } from './clients/index.js';
11
11
  import { createSuppliersCommand } from './suppliers/index.js';
12
12
  import { createMaterialsCommand } from './materials/index.js';
13
13
  import { createUomsCommand } from './uoms/index.js';
14
+ import { createCurrencyCommand } from './currency/index.js';
14
15
 
15
16
  export function createLibericaCommand(): Command {
16
17
  const libericaCommand = new Command('liberica');
@@ -27,6 +28,7 @@ export function createLibericaCommand(): Command {
27
28
  libericaCommand.addCommand(createSuppliersCommand());
28
29
  libericaCommand.addCommand(createMaterialsCommand());
29
30
  libericaCommand.addCommand(createUomsCommand());
31
+ libericaCommand.addCommand(createCurrencyCommand());
30
32
 
31
33
  libericaCommand.action(() => {
32
34
  console.log(chalk.bold('\n☕ Liberica Commands\n'));
@@ -40,6 +42,7 @@ export function createLibericaCommand(): Command {
40
42
  console.log(' Use "barista liberica clients <command>" for client management');
41
43
  console.log(' Use "barista liberica materials <command>" for material management');
42
44
  console.log(' Use "barista liberica uoms <command>" for unit of measure management');
45
+ console.log(' Use "barista liberica currencies <command>" for currency management');
43
46
  console.log('\n Run "barista liberica <command> --help" for more details\n');
44
47
  });
45
48