@newpeak/barista-cli 0.1.4 ā 0.1.5
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/auth/index.d.ts.map +1 -1
- package/dist/commands/liberica/auth/index.js +5 -0
- package/dist/commands/liberica/auth/index.js.map +1 -1
- package/dist/commands/liberica/index.d.ts.map +1 -1
- package/dist/commands/liberica/index.js +8 -0
- package/dist/commands/liberica/index.js.map +1 -1
- package/dist/commands/liberica/materials/create.d.ts +3 -0
- package/dist/commands/liberica/materials/create.d.ts.map +1 -0
- package/dist/commands/liberica/materials/create.js +154 -0
- package/dist/commands/liberica/materials/create.js.map +1 -0
- package/dist/commands/liberica/materials/delete.d.ts +3 -0
- package/dist/commands/liberica/materials/delete.d.ts.map +1 -0
- package/dist/commands/liberica/materials/delete.js +104 -0
- package/dist/commands/liberica/materials/delete.js.map +1 -0
- package/dist/commands/liberica/materials/disable.d.ts +3 -0
- package/dist/commands/liberica/materials/disable.d.ts.map +1 -0
- package/dist/commands/liberica/materials/disable.js +146 -0
- package/dist/commands/liberica/materials/disable.js.map +1 -0
- package/dist/commands/liberica/materials/enable.d.ts +3 -0
- package/dist/commands/liberica/materials/enable.d.ts.map +1 -0
- package/dist/commands/liberica/materials/enable.js +126 -0
- package/dist/commands/liberica/materials/enable.js.map +1 -0
- package/dist/commands/liberica/materials/get.d.ts +3 -0
- package/dist/commands/liberica/materials/get.d.ts.map +1 -0
- package/dist/commands/liberica/materials/get.js +71 -0
- package/dist/commands/liberica/materials/get.js.map +1 -0
- package/dist/commands/liberica/materials/index.d.ts +3 -0
- package/dist/commands/liberica/materials/index.d.ts.map +1 -0
- package/dist/commands/liberica/materials/index.js +21 -0
- package/dist/commands/liberica/materials/index.js.map +1 -0
- package/dist/commands/liberica/materials/list.d.ts +3 -0
- package/dist/commands/liberica/materials/list.d.ts.map +1 -0
- package/dist/commands/liberica/materials/list.js +107 -0
- package/dist/commands/liberica/materials/list.js.map +1 -0
- package/dist/commands/liberica/materials/update.d.ts +3 -0
- package/dist/commands/liberica/materials/update.d.ts.map +1 -0
- package/dist/commands/liberica/materials/update.js +118 -0
- package/dist/commands/liberica/materials/update.js.map +1 -0
- package/dist/commands/liberica/suppliers/create.d.ts +3 -0
- package/dist/commands/liberica/suppliers/create.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/create.js +140 -0
- package/dist/commands/liberica/suppliers/create.js.map +1 -0
- package/dist/commands/liberica/suppliers/delete.d.ts +3 -0
- package/dist/commands/liberica/suppliers/delete.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/delete.js +102 -0
- package/dist/commands/liberica/suppliers/delete.js.map +1 -0
- package/dist/commands/liberica/suppliers/disable.d.ts +3 -0
- package/dist/commands/liberica/suppliers/disable.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/disable.js +144 -0
- package/dist/commands/liberica/suppliers/disable.js.map +1 -0
- package/dist/commands/liberica/suppliers/enable.d.ts +3 -0
- package/dist/commands/liberica/suppliers/enable.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/enable.js +124 -0
- package/dist/commands/liberica/suppliers/enable.js.map +1 -0
- package/dist/commands/liberica/suppliers/get.d.ts +3 -0
- package/dist/commands/liberica/suppliers/get.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/get.js +75 -0
- package/dist/commands/liberica/suppliers/get.js.map +1 -0
- package/dist/commands/liberica/suppliers/index.d.ts +3 -0
- package/dist/commands/liberica/suppliers/index.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/index.js +21 -0
- package/dist/commands/liberica/suppliers/index.js.map +1 -0
- package/dist/commands/liberica/suppliers/list.d.ts +3 -0
- package/dist/commands/liberica/suppliers/list.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/list.js +100 -0
- package/dist/commands/liberica/suppliers/list.js.map +1 -0
- package/dist/commands/liberica/suppliers/update.d.ts +3 -0
- package/dist/commands/liberica/suppliers/update.d.ts.map +1 -0
- package/dist/commands/liberica/suppliers/update.js +122 -0
- package/dist/commands/liberica/suppliers/update.js.map +1 -0
- package/dist/commands/liberica/uoms/create.d.ts +3 -0
- package/dist/commands/liberica/uoms/create.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/create.js +120 -0
- package/dist/commands/liberica/uoms/create.js.map +1 -0
- package/dist/commands/liberica/uoms/delete.d.ts +3 -0
- package/dist/commands/liberica/uoms/delete.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/delete.js +104 -0
- package/dist/commands/liberica/uoms/delete.js.map +1 -0
- package/dist/commands/liberica/uoms/disable.d.ts +3 -0
- package/dist/commands/liberica/uoms/disable.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/disable.js +146 -0
- package/dist/commands/liberica/uoms/disable.js.map +1 -0
- package/dist/commands/liberica/uoms/enable.d.ts +3 -0
- package/dist/commands/liberica/uoms/enable.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/enable.js +126 -0
- package/dist/commands/liberica/uoms/enable.js.map +1 -0
- package/dist/commands/liberica/uoms/get.d.ts +3 -0
- package/dist/commands/liberica/uoms/get.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/get.js +71 -0
- package/dist/commands/liberica/uoms/get.js.map +1 -0
- package/dist/commands/liberica/uoms/index.d.ts +3 -0
- package/dist/commands/liberica/uoms/index.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/index.js +21 -0
- package/dist/commands/liberica/uoms/index.js.map +1 -0
- package/dist/commands/liberica/uoms/list.d.ts +3 -0
- package/dist/commands/liberica/uoms/list.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/list.js +98 -0
- package/dist/commands/liberica/uoms/list.js.map +1 -0
- package/dist/commands/liberica/uoms/update.d.ts +3 -0
- package/dist/commands/liberica/uoms/update.d.ts.map +1 -0
- package/dist/commands/liberica/uoms/update.js +115 -0
- package/dist/commands/liberica/uoms/update.js.map +1 -0
- package/dist/core/api/client.d.ts +24 -0
- package/dist/core/api/client.d.ts.map +1 -1
- package/dist/core/api/client.js +465 -0
- package/dist/core/api/client.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +5 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/material.d.ts +49 -0
- package/dist/types/material.d.ts.map +1 -0
- package/dist/types/material.js +2 -0
- package/dist/types/material.js.map +1 -0
- package/dist/types/supplier.d.ts +53 -0
- package/dist/types/supplier.d.ts.map +1 -0
- package/dist/types/supplier.js +2 -0
- package/dist/types/supplier.js.map +1 -0
- package/dist/types/uom.d.ts +47 -0
- package/dist/types/uom.d.ts.map +1 -0
- package/dist/types/uom.js +2 -0
- package/dist/types/uom.js.map +1 -0
- package/docs/commands/liberica/materials-create.md +293 -0
- package/docs/commands/liberica/materials-delete.md +240 -0
- package/docs/commands/liberica/materials-disable.md +150 -0
- package/docs/commands/liberica/materials-enable.md +146 -0
- package/docs/commands/liberica/materials-get.md +188 -0
- package/docs/commands/liberica/materials-list.md +198 -0
- package/docs/commands/liberica/materials-update.md +250 -0
- package/docs/commands/liberica/uoms-create.md +136 -0
- package/docs/commands/liberica/uoms-delete.md +119 -0
- package/docs/commands/liberica/uoms-disable.md +117 -0
- package/docs/commands/liberica/uoms-enable.md +115 -0
- package/docs/commands/liberica/uoms-get.md +119 -0
- package/docs/commands/liberica/uoms-list.md +155 -0
- package/docs/commands/liberica/uoms-update.md +148 -0
- package/package.json +2 -4
- package/src/commands/liberica/auth/index.ts +6 -0
- package/src/commands/liberica/index.ts +8 -0
- package/src/commands/liberica/materials/create.ts +168 -0
- package/src/commands/liberica/materials/delete.ts +105 -0
- package/src/commands/liberica/materials/disable.ts +148 -0
- package/src/commands/liberica/materials/enable.ts +129 -0
- package/src/commands/liberica/materials/get.ts +83 -0
- package/src/commands/liberica/materials/index.ts +23 -0
- package/src/commands/liberica/materials/list.ts +142 -0
- package/src/commands/liberica/materials/update.ts +125 -0
- package/src/commands/liberica/suppliers/create.ts +149 -0
- package/src/commands/liberica/suppliers/delete.ts +102 -0
- package/src/commands/liberica/suppliers/disable.ts +145 -0
- package/src/commands/liberica/suppliers/enable.ts +126 -0
- package/src/commands/liberica/suppliers/get.ts +86 -0
- package/src/commands/liberica/suppliers/index.ts +23 -0
- package/src/commands/liberica/suppliers/list.ts +134 -0
- package/src/commands/liberica/suppliers/update.ts +128 -0
- package/src/commands/liberica/uoms/create.ts +134 -0
- package/src/commands/liberica/uoms/delete.ts +105 -0
- package/src/commands/liberica/uoms/disable.ts +148 -0
- package/src/commands/liberica/uoms/enable.ts +129 -0
- package/src/commands/liberica/uoms/get.ts +83 -0
- package/src/commands/liberica/uoms/index.ts +23 -0
- package/src/commands/liberica/uoms/list.ts +129 -0
- package/src/commands/liberica/uoms/update.ts +124 -0
- package/src/core/api/client.ts +585 -0
- package/src/index.ts +1 -1
- package/src/types/index.ts +5 -2
- package/src/types/material.ts +61 -0
- package/src/types/supplier.ts +66 -0
- package/src/types/uom.ts +60 -0
- package/bin/barista.js +0 -3
|
@@ -0,0 +1,148 @@
|
|
|
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 { Material } from '../../../types/material.js';
|
|
8
|
+
|
|
9
|
+
export function createMaterialDisableCommand(): Command {
|
|
10
|
+
const disableCommand = new Command('disable');
|
|
11
|
+
disableCommand
|
|
12
|
+
.description('Disable (deactivate) a material')
|
|
13
|
+
.argument('<materialId>', 'Material 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 (materialId: 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
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
(options as any).json = process.argv.includes('--json');
|
|
26
|
+
const jsonOutput = options.json === true;
|
|
27
|
+
|
|
28
|
+
if (!materialId || materialId.trim() === '') {
|
|
29
|
+
const errMsg = 'Invalid material ID';
|
|
30
|
+
if (jsonOutput) {
|
|
31
|
+
console.log(JSON.stringify({ success: false, error: { code: 'INVALID_ID', message: errMsg } }));
|
|
32
|
+
} else {
|
|
33
|
+
console.error(chalk.red(`\nā ${errMsg}\n`));
|
|
34
|
+
}
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!jsonOutput) {
|
|
39
|
+
console.log(chalk.bold(`\n⬠Disable Material (${environment})\n`));
|
|
40
|
+
console.log(chalk.gray(` Material ID: ${materialId}`));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (dryRun) {
|
|
44
|
+
if (jsonOutput) {
|
|
45
|
+
console.log(JSON.stringify({ success: true, dryRun: true, message: 'No actual API call will be made' }));
|
|
46
|
+
} else {
|
|
47
|
+
console.log(chalk.cyan('\nš Dry-Run Mode: No actual API call will be made\n'));
|
|
48
|
+
console.log(chalk.gray(' This operation will disable the material.'));
|
|
49
|
+
console.log();
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let material: Material | undefined;
|
|
55
|
+
try {
|
|
56
|
+
const materialResponse = await apiClient.getMaterial(environment, tenant, materialId);
|
|
57
|
+
if (!materialResponse.success || !materialResponse.data || !('materialId' in materialResponse.data)) {
|
|
58
|
+
const errMsg = `Material not found: ${materialId}`;
|
|
59
|
+
if (jsonOutput) {
|
|
60
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
61
|
+
} else {
|
|
62
|
+
console.error(chalk.red(`\nā ${errMsg}\n`));
|
|
63
|
+
}
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
material = materialResponse.data as Material;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
69
|
+
const jsonErr = { success: false, error: { code: 'FETCH_ERROR', message: 'Failed to fetch material: ' + errMsg } };
|
|
70
|
+
if (jsonOutput) {
|
|
71
|
+
console.log(JSON.stringify(jsonErr));
|
|
72
|
+
} else {
|
|
73
|
+
console.error(chalk.red(`\nā Failed to fetch material: ${errMsg}\n`));
|
|
74
|
+
}
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (material.statusFlag === 2) {
|
|
79
|
+
const errMsg = `Material "${material.materialName}" is already disabled`;
|
|
80
|
+
if (jsonOutput) {
|
|
81
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ALREADY_DISABLED', message: errMsg } }));
|
|
82
|
+
} else {
|
|
83
|
+
console.error(chalk.yellow(`\nā ${errMsg}\n`));
|
|
84
|
+
}
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!force) {
|
|
89
|
+
if (!jsonOutput) {
|
|
90
|
+
console.log(chalk.gray(` Name: ${material.materialName}`));
|
|
91
|
+
console.log(chalk.gray(` Code: ${material.materialCode}`));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const { confirm } = await inquirer.prompt([
|
|
95
|
+
{
|
|
96
|
+
type: 'confirm',
|
|
97
|
+
name: 'confirm',
|
|
98
|
+
message: `Disable material "${material.materialName}"?`,
|
|
99
|
+
default: false,
|
|
100
|
+
},
|
|
101
|
+
]);
|
|
102
|
+
|
|
103
|
+
if (!confirm) {
|
|
104
|
+
if (jsonOutput) {
|
|
105
|
+
console.log(JSON.stringify({ success: false, error: { code: 'CANCELLED', message: 'Operation cancelled' } }));
|
|
106
|
+
} else {
|
|
107
|
+
console.log(chalk.gray('\n Operation cancelled.\n'));
|
|
108
|
+
}
|
|
109
|
+
process.exit(0);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const response = await apiClient.disableMaterial(environment, tenant, materialId);
|
|
115
|
+
|
|
116
|
+
if (response.success) {
|
|
117
|
+
if (jsonOutput) {
|
|
118
|
+
console.log(JSON.stringify({ success: true, materialId, name: material?.materialName }));
|
|
119
|
+
} else {
|
|
120
|
+
console.log(chalk.green(`\nā Material ${material?.materialName || materialId} disabled\n`));
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
124
|
+
const errorCode = response.error?.code || 'DISABLE_ERROR';
|
|
125
|
+
if (jsonOutput) {
|
|
126
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
127
|
+
} else {
|
|
128
|
+
console.error(chalk.red(`\nā Failed to disable material: ${errorMsg}`));
|
|
129
|
+
if (response.error?.code) {
|
|
130
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
131
|
+
}
|
|
132
|
+
console.error();
|
|
133
|
+
}
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
} catch (error) {
|
|
137
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
138
|
+
if (jsonOutput) {
|
|
139
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
140
|
+
} else {
|
|
141
|
+
console.error(chalk.red(`\nā Error: ${errMsg}\n`));
|
|
142
|
+
}
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return disableCommand;
|
|
148
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
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 { Material } from '../../../types/material.js';
|
|
8
|
+
|
|
9
|
+
export function createMaterialEnableCommand(): Command {
|
|
10
|
+
const enableCommand = new Command('enable');
|
|
11
|
+
enableCommand
|
|
12
|
+
.description('Enable (activate) a material')
|
|
13
|
+
.argument('<materialId>', 'Material ID')
|
|
14
|
+
.option('--json', 'Output as JSON')
|
|
15
|
+
.action(async (materialId: string, options: Record<string, unknown>) => {
|
|
16
|
+
const context = configManager.getCurrentContext();
|
|
17
|
+
const environment = context.environment as Environment;
|
|
18
|
+
const tenant = context.tenant;
|
|
19
|
+
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
(options as any).json = process.argv.includes('--json');
|
|
22
|
+
const jsonOutput = options.json === true;
|
|
23
|
+
|
|
24
|
+
if (!materialId || materialId.trim() === '') {
|
|
25
|
+
const errMsg = 'Invalid material ID';
|
|
26
|
+
if (jsonOutput) {
|
|
27
|
+
console.log(JSON.stringify({ success: false, error: { code: 'INVALID_ID', message: errMsg } }));
|
|
28
|
+
} else {
|
|
29
|
+
console.error(chalk.red(`\nā ${errMsg}\n`));
|
|
30
|
+
}
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!jsonOutput) {
|
|
35
|
+
console.log(chalk.bold(`\nā Enable Material (${environment})\n`));
|
|
36
|
+
console.log(chalk.gray(` Material ID: ${materialId}`));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Get material details for confirmation
|
|
40
|
+
let material: Material | undefined;
|
|
41
|
+
try {
|
|
42
|
+
const materialResponse = await apiClient.getMaterial(environment, tenant, materialId);
|
|
43
|
+
if (!materialResponse.success || !materialResponse.data || !('materialId' in materialResponse.data)) {
|
|
44
|
+
const errMsg = `Material not found: ${materialId}`;
|
|
45
|
+
if (jsonOutput) {
|
|
46
|
+
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: errMsg } }));
|
|
47
|
+
} else {
|
|
48
|
+
console.error(chalk.red(`\nā ${errMsg}\n`));
|
|
49
|
+
}
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
material = materialResponse.data as Material;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
55
|
+
if (jsonOutput) {
|
|
56
|
+
console.log(JSON.stringify({ success: false, error: { code: 'FETCH_ERROR', message: `Failed to fetch material: ${errMsg}` } }));
|
|
57
|
+
} else {
|
|
58
|
+
console.error(chalk.red(`\nā Failed to fetch material: ${errMsg}\n`));
|
|
59
|
+
}
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Check if already enabled
|
|
64
|
+
if (material.statusFlag === 1) {
|
|
65
|
+
const errMsg = `Material "${material.materialName}" is already enabled`;
|
|
66
|
+
if (jsonOutput) {
|
|
67
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ALREADY_ENABLED', message: errMsg } }));
|
|
68
|
+
} else {
|
|
69
|
+
console.error(chalk.yellow(`\nā ${errMsg}\n`));
|
|
70
|
+
}
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!jsonOutput) {
|
|
75
|
+
console.log(chalk.gray(` Name: ${material.materialName}`));
|
|
76
|
+
console.log(chalk.gray(` Code: ${material.materialCode}`));
|
|
77
|
+
|
|
78
|
+
const { confirm } = await inquirer.prompt([
|
|
79
|
+
{
|
|
80
|
+
type: 'confirm',
|
|
81
|
+
name: 'confirm',
|
|
82
|
+
message: `Enable material "${material.materialName}"?`,
|
|
83
|
+
default: false,
|
|
84
|
+
},
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
if (!confirm) {
|
|
88
|
+
console.log(chalk.gray('\n Operation cancelled.\n'));
|
|
89
|
+
process.exit(0);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Execute enable
|
|
94
|
+
try {
|
|
95
|
+
const response = await apiClient.enableMaterial(environment, tenant, materialId);
|
|
96
|
+
|
|
97
|
+
if (response.success) {
|
|
98
|
+
if (jsonOutput) {
|
|
99
|
+
console.log(JSON.stringify({ success: true, materialId, name: material?.materialName }));
|
|
100
|
+
} else {
|
|
101
|
+
console.log(chalk.green(`\nā Material ${material?.materialName || materialId} enabled\n`));
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
const errorMsg = response.error?.message || 'Unknown error';
|
|
105
|
+
const errorCode = response.error?.code || 'ENABLE_ERROR';
|
|
106
|
+
if (jsonOutput) {
|
|
107
|
+
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
108
|
+
} else {
|
|
109
|
+
console.error(chalk.red(`\nā Failed to enable material: ${errorMsg}`));
|
|
110
|
+
if (response.error?.code) {
|
|
111
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
112
|
+
}
|
|
113
|
+
console.error();
|
|
114
|
+
}
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
119
|
+
if (jsonOutput) {
|
|
120
|
+
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
121
|
+
} else {
|
|
122
|
+
console.error(chalk.red(`\nā Error: ${errMsg}\n`));
|
|
123
|
+
}
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return enableCommand;
|
|
129
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { Material } from '../../../types/material.js';
|
|
7
|
+
|
|
8
|
+
export function createMaterialsGetCommand(): Command {
|
|
9
|
+
const getCommand = new Command('get');
|
|
10
|
+
getCommand.description('Get material details by ID');
|
|
11
|
+
getCommand.arguments('<materialId>');
|
|
12
|
+
getCommand.option('--json', 'Output as JSON');
|
|
13
|
+
|
|
14
|
+
getCommand.action(async (materialId: 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 (!materialId) {
|
|
20
|
+
console.error(chalk.red('\nā Material ID is required\n'));
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!materialId || materialId.trim() === '') {
|
|
25
|
+
console.error(chalk.red('\nā Invalid material ID.\n'));
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const response = await apiClient.getMaterial(environment, tenant, materialId);
|
|
31
|
+
|
|
32
|
+
if (!response.success) {
|
|
33
|
+
const errorCode = response.error?.code || 'UNKNOWN_ERROR';
|
|
34
|
+
const errorMessage = response.error?.message || 'Unknown error';
|
|
35
|
+
|
|
36
|
+
// Handle "material not found" case
|
|
37
|
+
if (errorCode === '01001150001' || errorMessage.includes('äøååØ')) {
|
|
38
|
+
console.error(chalk.red(`\nā Material not found: ${materialId}\n`));
|
|
39
|
+
} else {
|
|
40
|
+
console.error(chalk.red(`\nā Error: ${errorMessage} (${errorCode})\n`));
|
|
41
|
+
}
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const material = response.data as Material | null;
|
|
46
|
+
|
|
47
|
+
// Workaround: Commander.js doesn't propagate --json to nested subcommands properly
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
(options as any).json = process.argv.includes('--json');
|
|
50
|
+
const outputJson = (options as Record<string, unknown>).json === true;
|
|
51
|
+
|
|
52
|
+
if (!material) {
|
|
53
|
+
console.error(chalk.red('\nā Material not found\n'));
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (outputJson) {
|
|
58
|
+
console.log(JSON.stringify({
|
|
59
|
+
success: true,
|
|
60
|
+
data: material,
|
|
61
|
+
}, null, 2));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Table output
|
|
66
|
+
console.log(chalk.bold('\nš¦ Material Details\n'));
|
|
67
|
+
console.log(` ${chalk.gray('ID:')} ${material.materialId}`);
|
|
68
|
+
console.log(` ${chalk.gray('Code:')} ${material.materialCode}`);
|
|
69
|
+
console.log(` ${chalk.gray('No:')} ${material.materialNo}`);
|
|
70
|
+
console.log(` ${chalk.gray('Name:')} ${material.materialName}`);
|
|
71
|
+
if (material.materialClass) {
|
|
72
|
+
console.log(` ${chalk.gray('Class:')} ${material.materialClass}`);
|
|
73
|
+
}
|
|
74
|
+
console.log(` ${chalk.gray('Status:')} ${material.statusFlag === 1 ? 'Enable' : 'Disable'}`);
|
|
75
|
+
console.log();
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error(chalk.red(`\nā Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return getCommand;
|
|
83
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { createMaterialsCreateCommand } from './create.js';
|
|
3
|
+
import { createMaterialListCommand } from './list.js';
|
|
4
|
+
import { createMaterialsGetCommand } from './get.js';
|
|
5
|
+
import { createMaterialEnableCommand } from './enable.js';
|
|
6
|
+
import { createMaterialDisableCommand } from './disable.js';
|
|
7
|
+
import { createMaterialUpdateCommand } from './update.js';
|
|
8
|
+
import { createMaterialDeleteCommand } from './delete.js';
|
|
9
|
+
|
|
10
|
+
export function createMaterialsCommand(): Command {
|
|
11
|
+
const materialsCommand = new Command('materials');
|
|
12
|
+
materialsCommand.description('Manage materials');
|
|
13
|
+
|
|
14
|
+
materialsCommand.addCommand(createMaterialsCreateCommand());
|
|
15
|
+
materialsCommand.addCommand(createMaterialListCommand());
|
|
16
|
+
materialsCommand.addCommand(createMaterialsGetCommand());
|
|
17
|
+
materialsCommand.addCommand(createMaterialEnableCommand());
|
|
18
|
+
materialsCommand.addCommand(createMaterialDisableCommand());
|
|
19
|
+
materialsCommand.addCommand(createMaterialUpdateCommand());
|
|
20
|
+
materialsCommand.addCommand(createMaterialDeleteCommand());
|
|
21
|
+
|
|
22
|
+
return materialsCommand;
|
|
23
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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 { MaterialListResponse, MaterialStatusFlag } from '../../../types/material.js';
|
|
7
|
+
import { Environment } from '../../../types/index.js';
|
|
8
|
+
|
|
9
|
+
export function createMaterialListCommand(): Command {
|
|
10
|
+
const listCommand = new Command('list');
|
|
11
|
+
listCommand.description('List materials 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('-c, --class <string>', 'Material class filter')
|
|
18
|
+
.option('-k, --keyword <string>', 'Keyword search')
|
|
19
|
+
.option('--json', 'Output as JSON')
|
|
20
|
+
.action(async (options) => {
|
|
21
|
+
// Commander.js boolean flag parsing workaround
|
|
22
|
+
const outputJson = options.json === true || process.argv.includes('--json');
|
|
23
|
+
|
|
24
|
+
const context = configManager.getCurrentContext();
|
|
25
|
+
const environment = (options.env as Environment) || context.environment;
|
|
26
|
+
const tenant = options.tenant || context.tenant;
|
|
27
|
+
|
|
28
|
+
const page = parseInt(options.page as string, 10) - 1;
|
|
29
|
+
const size = parseInt(options.size as string, 10);
|
|
30
|
+
|
|
31
|
+
const params: {
|
|
32
|
+
pageNo: number;
|
|
33
|
+
pageSize: number;
|
|
34
|
+
statusFlag?: MaterialStatusFlag;
|
|
35
|
+
materialClass?: string;
|
|
36
|
+
keyword?: string;
|
|
37
|
+
} = { pageNo: page, pageSize: size };
|
|
38
|
+
|
|
39
|
+
if (options.status !== undefined) {
|
|
40
|
+
const statusVal = (options.status as string).toLowerCase();
|
|
41
|
+
if (statusVal === 'enable' || statusVal === '1') {
|
|
42
|
+
params.statusFlag = 1;
|
|
43
|
+
} else if (statusVal === 'disable' || statusVal === '2') {
|
|
44
|
+
params.statusFlag = 2;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (options.class !== undefined) {
|
|
49
|
+
params.materialClass = options.class as string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (options.keyword !== undefined) {
|
|
53
|
+
params.keyword = options.keyword as string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const response = await apiClient.listMaterials(environment, tenant, params);
|
|
57
|
+
|
|
58
|
+
if (!response.success) {
|
|
59
|
+
console.error(chalk.red(`\nā Failed to list materials: ${response.error?.message || 'Unknown error'}`));
|
|
60
|
+
if (response.error?.code) {
|
|
61
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
62
|
+
}
|
|
63
|
+
console.error();
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const data = response.data as MaterialListResponse | null;
|
|
68
|
+
|
|
69
|
+
if (!data) {
|
|
70
|
+
if (outputJson) {
|
|
71
|
+
console.log(JSON.stringify({ success: true, data: { items: [], pagination: { pageNo: 0, pageSize: 20, totalRows: 0 } } }, null, 2));
|
|
72
|
+
} else {
|
|
73
|
+
console.log(chalk.bold('\nš¦ Material List\n'));
|
|
74
|
+
console.log(chalk.gray(' No materials found\n'));
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (outputJson) {
|
|
80
|
+
console.log(
|
|
81
|
+
JSON.stringify(
|
|
82
|
+
{
|
|
83
|
+
success: true,
|
|
84
|
+
data: {
|
|
85
|
+
items: data.rows || [],
|
|
86
|
+
pagination: {
|
|
87
|
+
pageNo: data.pageNo,
|
|
88
|
+
pageSize: data.pageSize,
|
|
89
|
+
totalRows: data.totalRows,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
null,
|
|
94
|
+
2
|
|
95
|
+
)
|
|
96
|
+
);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const records = data.rows || [];
|
|
101
|
+
|
|
102
|
+
if (records.length === 0) {
|
|
103
|
+
console.log(chalk.bold('\nš¦ Material List\n'));
|
|
104
|
+
console.log(chalk.gray(' No materials found\n'));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log(chalk.bold('\nš¦ Material List\n'));
|
|
109
|
+
|
|
110
|
+
const table = new Table({
|
|
111
|
+
head: [chalk.bold('ID'), chalk.bold('Code'), chalk.bold('No'), chalk.bold('Name'), chalk.bold('Class'), chalk.bold('Status')],
|
|
112
|
+
colWidths: [14, 14, 14, 30, 16, 10],
|
|
113
|
+
style: {
|
|
114
|
+
head: [],
|
|
115
|
+
border: [],
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
for (const material of records) {
|
|
120
|
+
const statusText = material.statusFlag === 1 ? chalk.green('Enable') : chalk.red('Disable');
|
|
121
|
+
table.push([
|
|
122
|
+
material.materialId,
|
|
123
|
+
material.materialCode || '-',
|
|
124
|
+
material.materialNo || '-',
|
|
125
|
+
material.materialName || '-',
|
|
126
|
+
material.materialClass || '-',
|
|
127
|
+
statusText,
|
|
128
|
+
]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
console.log(table.toString());
|
|
132
|
+
console.log();
|
|
133
|
+
console.log(
|
|
134
|
+
chalk.gray(
|
|
135
|
+
` Total: ${data.totalRows} | Page: ${data.pageNo + 1} / ${Math.ceil(data.totalRows / data.pageSize) || 1} | Size: ${data.pageSize}`
|
|
136
|
+
)
|
|
137
|
+
);
|
|
138
|
+
console.log();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
return listCommand;
|
|
142
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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 { Material, MaterialRequest } from '../../../types/material.js';
|
|
7
|
+
|
|
8
|
+
export function createMaterialUpdateCommand(): Command {
|
|
9
|
+
const updateCommand = new Command('update');
|
|
10
|
+
updateCommand
|
|
11
|
+
.description('Update material information')
|
|
12
|
+
.argument('<materialId>', 'Material ID')
|
|
13
|
+
.option('-n, --name <name>', 'Material name')
|
|
14
|
+
.option('-c, --class <class>', 'Material class')
|
|
15
|
+
.option('--type <type>', 'Material type')
|
|
16
|
+
.option('--unit <unit>', 'Material unit')
|
|
17
|
+
.option('--dry-run', 'Preview changes without making API call')
|
|
18
|
+
.option('--json', 'Output result as JSON')
|
|
19
|
+
.action(async (materialId: string, options: Record<string, unknown>) => {
|
|
20
|
+
const context = configManager.getCurrentContext();
|
|
21
|
+
const environment = context.environment as Environment;
|
|
22
|
+
const tenant = context.tenant;
|
|
23
|
+
|
|
24
|
+
const fields: Partial<MaterialRequest> = {};
|
|
25
|
+
if (options.name) fields.materialName = options.name as string;
|
|
26
|
+
if (options.class) fields.materialClass = options.class as string;
|
|
27
|
+
if (options.type) fields.materialType = options.type as string;
|
|
28
|
+
if (options.unit) fields.materialUnit = options.unit as string;
|
|
29
|
+
|
|
30
|
+
const providedFields = Object.keys(fields).filter(
|
|
31
|
+
(k) => fields[k as keyof MaterialRequest] !== undefined
|
|
32
|
+
);
|
|
33
|
+
if (providedFields.length === 0) {
|
|
34
|
+
console.error(
|
|
35
|
+
chalk.red('\nā No fields to update. Provide at least one of: --name, --class, --type, --unit\n')
|
|
36
|
+
);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (options.dryRun) {
|
|
41
|
+
console.log(chalk.bold(`\nš¦ Update Material ā Dry Run (${environment})\n`));
|
|
42
|
+
console.log(chalk.gray(` Material ID: ${materialId}`));
|
|
43
|
+
console.log(chalk.gray('\n Changes to be applied:'));
|
|
44
|
+
for (const field of providedFields) {
|
|
45
|
+
const label = field.replace(/([A-Z])/g, (m) => ` ${m.toLowerCase()}`).trim();
|
|
46
|
+
console.log(chalk.cyan(` ${label}: "${fields[field as keyof MaterialRequest]}"`));
|
|
47
|
+
}
|
|
48
|
+
console.log();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let currentMaterial: Material | undefined;
|
|
53
|
+
try {
|
|
54
|
+
const materialResponse = await apiClient.getMaterial(environment, tenant, materialId);
|
|
55
|
+
if (!materialResponse.success || !materialResponse.data) {
|
|
56
|
+
console.error(chalk.red(`\nā Material not found: ${materialId}`));
|
|
57
|
+
if (materialResponse.error?.message) {
|
|
58
|
+
console.error(chalk.gray(` ${materialResponse.error.message}`));
|
|
59
|
+
}
|
|
60
|
+
if (materialResponse.error?.code) {
|
|
61
|
+
console.error(chalk.gray(` Error code: ${materialResponse.error.code}`));
|
|
62
|
+
}
|
|
63
|
+
console.error();
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
currentMaterial = materialResponse.data as Material;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(chalk.red(`\nā Failed to fetch material: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
(options as any).json = process.argv.includes('--json');
|
|
74
|
+
const outputJson = (options as Record<string, unknown>).json === true;
|
|
75
|
+
|
|
76
|
+
console.log(chalk.bold(`\nš¦ Update Material (${environment})\n`));
|
|
77
|
+
console.log(chalk.gray(` Material ID: ${materialId}`));
|
|
78
|
+
console.log(chalk.gray(` Current Name: ${currentMaterial.materialName}`));
|
|
79
|
+
console.log(chalk.gray('\n Changes:'));
|
|
80
|
+
for (const field of providedFields) {
|
|
81
|
+
const label = field.replace(/([A-Z])/g, (m) => ` ${m.toLowerCase()}`).trim();
|
|
82
|
+
const currentVal = (currentMaterial as unknown as Record<string, unknown>)[field] ?? '(not set)';
|
|
83
|
+
const newVal = fields[field as keyof MaterialRequest];
|
|
84
|
+
console.log(chalk.cyan(` ${label}: "${currentVal}" ā "${newVal}"`));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const updateData = { materialId, ...fields } as MaterialRequest;
|
|
88
|
+
try {
|
|
89
|
+
const response = await apiClient.updateMaterial(environment, tenant, materialId, updateData);
|
|
90
|
+
|
|
91
|
+
if (response.success) {
|
|
92
|
+
if (outputJson) {
|
|
93
|
+
console.log(JSON.stringify({ success: true, data: response.data }, null, 2));
|
|
94
|
+
} else {
|
|
95
|
+
console.log(chalk.green(`\nā Material updated successfully\n`));
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
if (outputJson) {
|
|
99
|
+
console.log(JSON.stringify({ success: false, error: response.error }, null, 2));
|
|
100
|
+
} else {
|
|
101
|
+
console.error(chalk.red(`\nā Update failed: ${response.error?.message || 'Unknown error'}`));
|
|
102
|
+
if (response.error?.code) {
|
|
103
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
104
|
+
}
|
|
105
|
+
console.error();
|
|
106
|
+
}
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (outputJson) {
|
|
111
|
+
console.log(
|
|
112
|
+
JSON.stringify({
|
|
113
|
+
success: false,
|
|
114
|
+
error: { message: error instanceof Error ? error.message : 'Unknown error' },
|
|
115
|
+
})
|
|
116
|
+
);
|
|
117
|
+
} else {
|
|
118
|
+
console.error(chalk.red(`\nā Error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
119
|
+
}
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return updateCommand;
|
|
125
|
+
}
|