@newpeak/barista-cli 0.1.0
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/.eslintrc.json +23 -0
- package/.prettierrc +9 -0
- package/.sisyphus/notepads/liberica-employees/learnings.md +73 -0
- package/AGENTS.md +270 -0
- package/CONTRIBUTING.md +291 -0
- package/README.md +707 -0
- package/bin/barista +6 -0
- package/bin/barista.js +3 -0
- package/docs/ARCHITECTURE.md +184 -0
- package/docs/COMMANDS.md +352 -0
- package/docs/COMMAND_DESIGN_SPEC.md +811 -0
- package/docs/INTEGRATION_NOTES.md +270 -0
- package/docs/commands/REFERENCE.md +297 -0
- package/docs/commands/arabica/auth/index.md +296 -0
- package/docs/commands/liberica/auth/index.md +133 -0
- package/docs/commands/liberica/context/index.md +60 -0
- package/docs/commands/liberica/employees/create.md +185 -0
- package/docs/commands/liberica/employees/disable.md +138 -0
- package/docs/commands/liberica/employees/enable.md +137 -0
- package/docs/commands/liberica/employees/get.md +153 -0
- package/docs/commands/liberica/employees/list.md +168 -0
- package/docs/commands/liberica/employees/update.md +180 -0
- package/docs/commands/liberica/orgs/list.md +62 -0
- package/docs/commands/liberica/positions/list.md +61 -0
- package/docs/commands/liberica/roles/list.md +67 -0
- package/docs/commands/liberica/users/create.md +170 -0
- package/docs/commands/liberica/users/get.md +151 -0
- package/docs/commands/liberica/users/list.md +175 -0
- package/package.json +37 -0
- package/src/commands/arabica/auth/index.ts +277 -0
- package/src/commands/arabica/auth/login.ts +5 -0
- package/src/commands/arabica/auth/logout.ts +5 -0
- package/src/commands/arabica/auth/register.ts +5 -0
- package/src/commands/arabica/auth/status.ts +5 -0
- package/src/commands/arabica/index.ts +23 -0
- package/src/commands/auth.ts +107 -0
- package/src/commands/context.ts +60 -0
- package/src/commands/liberica/auth/index.ts +170 -0
- package/src/commands/liberica/context/index.ts +43 -0
- package/src/commands/liberica/employees/create.ts +275 -0
- package/src/commands/liberica/employees/delete.ts +122 -0
- package/src/commands/liberica/employees/disable.ts +97 -0
- package/src/commands/liberica/employees/enable.ts +97 -0
- package/src/commands/liberica/employees/get.ts +115 -0
- package/src/commands/liberica/employees/index.ts +23 -0
- package/src/commands/liberica/employees/list.ts +131 -0
- package/src/commands/liberica/employees/update.ts +157 -0
- package/src/commands/liberica/index.ts +36 -0
- package/src/commands/liberica/orgs/index.ts +35 -0
- package/src/commands/liberica/positions/index.ts +30 -0
- package/src/commands/liberica/roles/index.ts +59 -0
- package/src/commands/liberica/users/create.ts +132 -0
- package/src/commands/liberica/users/delete.ts +49 -0
- package/src/commands/liberica/users/disable.ts +41 -0
- package/src/commands/liberica/users/enable.ts +30 -0
- package/src/commands/liberica/users/get.ts +46 -0
- package/src/commands/liberica/users/index.ts +27 -0
- package/src/commands/liberica/users/list.ts +68 -0
- package/src/commands/liberica/users/me.ts +42 -0
- package/src/commands/liberica/users/reset-password.ts +42 -0
- package/src/commands/liberica/users/update.ts +48 -0
- package/src/core/api/client.ts +825 -0
- package/src/core/auth/token-manager.ts +183 -0
- package/src/core/config/manager.ts +164 -0
- package/src/index.ts +37 -0
- package/src/types/employee.ts +102 -0
- package/src/types/index.ts +75 -0
- package/src/types/org.ts +25 -0
- package/src/types/position.ts +24 -0
- package/src/types/user.ts +64 -0
- package/tests/unit/commands/arabica/auth.test.ts +230 -0
- package/tests/unit/commands/liberica/auth.test.ts +175 -0
- package/tests/unit/commands/liberica/context.test.ts +98 -0
- package/tests/unit/commands/liberica/employees/create.test.ts +463 -0
- package/tests/unit/commands/liberica/employees/disable.test.ts +82 -0
- package/tests/unit/commands/liberica/employees/enable.test.ts +82 -0
- package/tests/unit/commands/liberica/employees/get.test.ts +111 -0
- package/tests/unit/commands/liberica/employees/list.test.ts +294 -0
- package/tests/unit/commands/liberica/employees/update.test.ts +210 -0
- package/tests/unit/config.test.ts +141 -0
- package/tests/unit/types.test.ts +195 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,97 @@
|
|
|
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 { Employee } from '../../../types/employee.js';
|
|
8
|
+
|
|
9
|
+
export function createEmployeeDisableCommand(): Command {
|
|
10
|
+
const disableCommand = new Command('disable');
|
|
11
|
+
disableCommand
|
|
12
|
+
.description('Disable (deactivate) an employee account')
|
|
13
|
+
.argument('<id>', 'Employee ID')
|
|
14
|
+
.option('--force', 'Skip confirmation prompt')
|
|
15
|
+
.option('--dry-run', 'Preview the operation without executing')
|
|
16
|
+
.action(async (id: string, options: Record<string, unknown>) => {
|
|
17
|
+
const context = configManager.getCurrentContext();
|
|
18
|
+
const environment = context.environment as Environment;
|
|
19
|
+
const tenant = context.tenant;
|
|
20
|
+
|
|
21
|
+
const employeeId = id;
|
|
22
|
+
if (!employeeId || employeeId.trim() === '') {
|
|
23
|
+
console.error(chalk.red('\nā Invalid employee ID\n'));
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log(chalk.bold(`\nš¤ Disable Employee (${environment})\n`));
|
|
28
|
+
console.log(chalk.gray(` Employee ID: ${employeeId}`));
|
|
29
|
+
|
|
30
|
+
// Dry-run mode: preview
|
|
31
|
+
if (options.dryRun) {
|
|
32
|
+
console.log(chalk.cyan('\nš Dry-Run Mode: No actual API call will be made\n'));
|
|
33
|
+
console.log(chalk.gray(' This operation will disable the employee.'));
|
|
34
|
+
console.log();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Get employee details for confirmation
|
|
39
|
+
let employee: Employee | undefined;
|
|
40
|
+
try {
|
|
41
|
+
const employeeResponse = await apiClient.getEmployee(environment, tenant, employeeId);
|
|
42
|
+
if (!employeeResponse.success || !employeeResponse.data) {
|
|
43
|
+
console.error(chalk.red(`\nā Employee not found: ${employeeId}`));
|
|
44
|
+
if (employeeResponse.error?.message) {
|
|
45
|
+
console.error(chalk.gray(` ${employeeResponse.error.message}`));
|
|
46
|
+
}
|
|
47
|
+
console.error();
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
employee = employeeResponse.data as Employee;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(chalk.red(`\nā Failed to fetch employee: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Confirm unless --force
|
|
57
|
+
if (!options.force) {
|
|
58
|
+
console.log(chalk.gray(` Name: ${employee.employeeName}`));
|
|
59
|
+
console.log(chalk.gray(` Code: ${employee.employeeNo}`));
|
|
60
|
+
|
|
61
|
+
const { confirm } = await inquirer.prompt([
|
|
62
|
+
{
|
|
63
|
+
type: 'confirm',
|
|
64
|
+
name: 'confirm',
|
|
65
|
+
message: `Disable employee "${employee.employeeName}"?`,
|
|
66
|
+
default: false,
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
if (!confirm) {
|
|
71
|
+
console.log(chalk.gray('\n Operation cancelled.\n'));
|
|
72
|
+
process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Execute disable
|
|
77
|
+
try {
|
|
78
|
+
const response = await apiClient.disableEmployee(environment, tenant, employeeId);
|
|
79
|
+
|
|
80
|
+
if (response.success) {
|
|
81
|
+
console.log(chalk.green(`\nā Employee ${employee?.employeeName || employeeId} disabled\n`));
|
|
82
|
+
} else {
|
|
83
|
+
console.error(chalk.red(`\nā Failed to disable employee: ${response.error?.message || 'Unknown error'}`));
|
|
84
|
+
if (response.error?.code) {
|
|
85
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
86
|
+
}
|
|
87
|
+
console.error();
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error(chalk.red(`\nā Error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return disableCommand;
|
|
97
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
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 { Employee } from '../../../types/employee.js';
|
|
8
|
+
|
|
9
|
+
export function createEmployeeEnableCommand(): Command {
|
|
10
|
+
const enableCommand = new Command('enable');
|
|
11
|
+
enableCommand
|
|
12
|
+
.description('Enable (activate) an employee account')
|
|
13
|
+
.argument('<id>', 'Employee ID')
|
|
14
|
+
.option('--force', 'Skip confirmation prompt')
|
|
15
|
+
.option('--dry-run', 'Preview the operation without executing')
|
|
16
|
+
.action(async (id: string, options: Record<string, unknown>) => {
|
|
17
|
+
const context = configManager.getCurrentContext();
|
|
18
|
+
const environment = context.environment as Environment;
|
|
19
|
+
const tenant = context.tenant;
|
|
20
|
+
|
|
21
|
+
const employeeId = id;
|
|
22
|
+
if (!employeeId || employeeId.trim() === '') {
|
|
23
|
+
console.error(chalk.red('\nā Invalid employee ID\n'));
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log(chalk.bold(`\nš¤ Enable Employee (${environment})\n`));
|
|
28
|
+
console.log(chalk.gray(` Employee ID: ${employeeId}`));
|
|
29
|
+
|
|
30
|
+
// Dry-run mode: preview
|
|
31
|
+
if (options.dryRun) {
|
|
32
|
+
console.log(chalk.cyan('\nš Dry-Run Mode: No actual API call will be made\n'));
|
|
33
|
+
console.log(chalk.gray(' This operation will enable the employee.'));
|
|
34
|
+
console.log();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Get employee details for confirmation
|
|
39
|
+
let employee: Employee | undefined;
|
|
40
|
+
try {
|
|
41
|
+
const employeeResponse = await apiClient.getEmployee(environment, tenant, employeeId);
|
|
42
|
+
if (!employeeResponse.success || !employeeResponse.data) {
|
|
43
|
+
console.error(chalk.red(`\nā Employee not found: ${employeeId}`));
|
|
44
|
+
if (employeeResponse.error?.message) {
|
|
45
|
+
console.error(chalk.gray(` ${employeeResponse.error.message}`));
|
|
46
|
+
}
|
|
47
|
+
console.error();
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
employee = employeeResponse.data as Employee;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(chalk.red(`\nā Failed to fetch employee: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Confirm unless --force
|
|
57
|
+
if (!options.force) {
|
|
58
|
+
console.log(chalk.gray(` Name: ${employee.employeeName}`));
|
|
59
|
+
console.log(chalk.gray(` Code: ${employee.employeeNo}`));
|
|
60
|
+
|
|
61
|
+
const { confirm } = await inquirer.prompt([
|
|
62
|
+
{
|
|
63
|
+
type: 'confirm',
|
|
64
|
+
name: 'confirm',
|
|
65
|
+
message: `Enable employee "${employee.employeeName}"?`,
|
|
66
|
+
default: false,
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
if (!confirm) {
|
|
71
|
+
console.log(chalk.gray('\n Operation cancelled.\n'));
|
|
72
|
+
process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Execute enable
|
|
77
|
+
try {
|
|
78
|
+
const response = await apiClient.enableEmployee(environment, tenant, employeeId);
|
|
79
|
+
|
|
80
|
+
if (response.success) {
|
|
81
|
+
console.log(chalk.green(`\nā Employee ${employee?.employeeName || employeeId} enabled\n`));
|
|
82
|
+
} else {
|
|
83
|
+
console.error(chalk.red(`\nā Failed to enable employee: ${response.error?.message || 'Unknown error'}`));
|
|
84
|
+
if (response.error?.code) {
|
|
85
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
86
|
+
}
|
|
87
|
+
console.error();
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error(chalk.red(`\nā Error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return enableCommand;
|
|
97
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
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 { Employee } from '../../../types/employee.js';
|
|
7
|
+
|
|
8
|
+
export function createEmployeeGetCommand(): Command {
|
|
9
|
+
const getCommand = new Command('get');
|
|
10
|
+
getCommand.description('Get employee details by ID');
|
|
11
|
+
getCommand.arguments('<id>');
|
|
12
|
+
getCommand.option('--json', 'Output as JSON');
|
|
13
|
+
|
|
14
|
+
getCommand.action(async (id: 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 (!id) {
|
|
20
|
+
console.error(chalk.red('\nā Employee ID is required\n'));
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const employeeId = id;
|
|
25
|
+
if (!employeeId || employeeId.trim() === '') {
|
|
26
|
+
console.error(chalk.red('\nā Invalid employee ID.\n'));
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const response = await apiClient.getEmployee(environment, tenant, employeeId);
|
|
32
|
+
|
|
33
|
+
if (!response.success) {
|
|
34
|
+
const errorCode = response.error?.code || 'UNKNOWN_ERROR';
|
|
35
|
+
const errorMessage = response.error?.message || 'Unknown error';
|
|
36
|
+
|
|
37
|
+
// Handle "employee not found" case
|
|
38
|
+
if (errorCode === '01001150001' || errorMessage.includes('äøååØ')) {
|
|
39
|
+
console.error(chalk.red(`\nā Employee not found: ${employeeId}\n`));
|
|
40
|
+
} else {
|
|
41
|
+
console.error(chalk.red(`\nā Error: ${errorMessage} (${errorCode})\n`));
|
|
42
|
+
}
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const employee = response.data as Employee | null;
|
|
47
|
+
|
|
48
|
+
if (!employee) {
|
|
49
|
+
console.error(chalk.red('\nā Employee not found\n'));
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (options.json) {
|
|
54
|
+
console.log(JSON.stringify({
|
|
55
|
+
success: true,
|
|
56
|
+
data: employee,
|
|
57
|
+
}, null, 2));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Table output
|
|
62
|
+
console.log(chalk.bold('\nš¤ Employee Details\n'));
|
|
63
|
+
console.log(` ${chalk.gray('ID:')} ${employee.employeeId}`);
|
|
64
|
+
console.log(` ${chalk.gray('Code:')} ${employee.employeeCode}`);
|
|
65
|
+
console.log(` ${chalk.gray('Name:')} ${employee.employeeName}`);
|
|
66
|
+
console.log(` ${chalk.gray('No:')} ${employee.employeeNo}`);
|
|
67
|
+
if (employee.employeePhone) {
|
|
68
|
+
console.log(` ${chalk.gray('Phone:')} ${employee.employeePhone}`);
|
|
69
|
+
}
|
|
70
|
+
if (employee.employeeEmail) {
|
|
71
|
+
console.log(` ${chalk.gray('Email:')} ${employee.employeeEmail}`);
|
|
72
|
+
}
|
|
73
|
+
if (employee.employeeSex) {
|
|
74
|
+
console.log(` ${chalk.gray('Sex:')} ${employee.employeeSex}`);
|
|
75
|
+
}
|
|
76
|
+
if (employee.employeeIdType) {
|
|
77
|
+
console.log(` ${chalk.gray('ID Type:')} ${employee.employeeIdType}`);
|
|
78
|
+
}
|
|
79
|
+
if (employee.employeeIdNo) {
|
|
80
|
+
console.log(` ${chalk.gray('ID Number:')} ${employee.employeeIdNo}`);
|
|
81
|
+
}
|
|
82
|
+
if (employee.employeeJoinedDate) {
|
|
83
|
+
console.log(` ${chalk.gray('Join Date:')} ${employee.employeeJoinedDate}`);
|
|
84
|
+
}
|
|
85
|
+
if (employee.employeeLeaveDate) {
|
|
86
|
+
console.log(` ${chalk.gray('Leave Date:')} ${employee.employeeLeaveDate}`);
|
|
87
|
+
}
|
|
88
|
+
if (employee.employeeBirthday) {
|
|
89
|
+
console.log(` ${chalk.gray('Birthday:')} ${employee.employeeBirthday}`);
|
|
90
|
+
}
|
|
91
|
+
if (employee.orgName) {
|
|
92
|
+
console.log(` ${chalk.gray('Organization:')} ${employee.orgName} (${employee.orgCode})`);
|
|
93
|
+
}
|
|
94
|
+
if (employee.positionName) {
|
|
95
|
+
console.log(` ${chalk.gray('Position:')} ${employee.positionName}`);
|
|
96
|
+
}
|
|
97
|
+
if (employee.jobType) {
|
|
98
|
+
console.log(` ${chalk.gray('Job Type:')} ${employee.jobType}`);
|
|
99
|
+
}
|
|
100
|
+
if (employee.jobLevelNo) {
|
|
101
|
+
console.log(` ${chalk.gray('Job Level:')} ${employee.jobLevelNo}`);
|
|
102
|
+
}
|
|
103
|
+
if (employee.employeeStatus) {
|
|
104
|
+
console.log(` ${chalk.gray('Status:')} ${employee.employeeStatus}`);
|
|
105
|
+
}
|
|
106
|
+
console.log(` ${chalk.gray('Enabled:')} ${employee.statusFlag === 1 ? 'Yes' : 'No'}`);
|
|
107
|
+
console.log();
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error(chalk.red(`\nā Unexpected error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return getCommand;
|
|
115
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { createEmployeeCreateCommand } from './create.js';
|
|
3
|
+
import { createEmployeeListCommand } from './list.js';
|
|
4
|
+
import { createEmployeeGetCommand } from './get.js';
|
|
5
|
+
import { createEmployeeDisableCommand } from './disable.js';
|
|
6
|
+
import { createEmployeeEnableCommand } from './enable.js';
|
|
7
|
+
import { createEmployeeUpdateCommand } from './update.js';
|
|
8
|
+
import { createEmployeeDeleteCommand } from './delete.js';
|
|
9
|
+
|
|
10
|
+
export function createEmployeesCommand(): Command {
|
|
11
|
+
const employeesCommand = new Command('employees');
|
|
12
|
+
employeesCommand.description('Manage employees');
|
|
13
|
+
|
|
14
|
+
employeesCommand.addCommand(createEmployeeCreateCommand());
|
|
15
|
+
employeesCommand.addCommand(createEmployeeListCommand());
|
|
16
|
+
employeesCommand.addCommand(createEmployeeGetCommand());
|
|
17
|
+
employeesCommand.addCommand(createEmployeeDisableCommand());
|
|
18
|
+
employeesCommand.addCommand(createEmployeeEnableCommand());
|
|
19
|
+
employeesCommand.addCommand(createEmployeeUpdateCommand());
|
|
20
|
+
employeesCommand.addCommand(createEmployeeDeleteCommand());
|
|
21
|
+
|
|
22
|
+
return employeesCommand;
|
|
23
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
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 { EmployeeListResponse, StatusFlag } from '../../../types/employee.js';
|
|
7
|
+
import { Environment } from '../../../types/index.js';
|
|
8
|
+
|
|
9
|
+
export function createEmployeeListCommand(): Command {
|
|
10
|
+
const listCommand = new Command('list');
|
|
11
|
+
listCommand.description('List employees with pagination');
|
|
12
|
+
|
|
13
|
+
listCommand
|
|
14
|
+
.option('-p, --page <number>', 'Page number', '1')
|
|
15
|
+
.option('-s, --size <number>', 'Page size', '20')
|
|
16
|
+
.option('--status <number>', 'Status filter (1=enable, 2=disable)')
|
|
17
|
+
.option('--org-id <number>', 'Organization ID filter')
|
|
18
|
+
.option('--json', 'Output as JSON')
|
|
19
|
+
.action(async (options) => {
|
|
20
|
+
const context = configManager.getCurrentContext();
|
|
21
|
+
const environment = (options.env as Environment) || context.environment;
|
|
22
|
+
const tenant = options.tenant || context.tenant;
|
|
23
|
+
|
|
24
|
+
const page = parseInt(options.page as string, 10) - 1; // API uses 0-based pagination
|
|
25
|
+
const size = parseInt(options.size as string, 10);
|
|
26
|
+
|
|
27
|
+
const params: {
|
|
28
|
+
pageNo: number;
|
|
29
|
+
pageSize: number;
|
|
30
|
+
status?: StatusFlag;
|
|
31
|
+
organizationId?: number;
|
|
32
|
+
} = { pageNo: page, pageSize: size };
|
|
33
|
+
|
|
34
|
+
if (options.status !== undefined) {
|
|
35
|
+
const statusNum = parseInt(options.status as string, 10);
|
|
36
|
+
if (statusNum === 1 || statusNum === 2) {
|
|
37
|
+
params.status = statusNum as StatusFlag;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (options.orgId !== undefined) {
|
|
42
|
+
params.organizationId = parseInt(options.orgId as string, 10);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const response = await apiClient.listEmployees(environment, tenant, params);
|
|
46
|
+
|
|
47
|
+
if (!response.success) {
|
|
48
|
+
console.error(chalk.red(`\nā Failed to list employees: ${response.error?.message || 'Unknown error'}`));
|
|
49
|
+
if (response.error?.code) {
|
|
50
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
51
|
+
}
|
|
52
|
+
console.error();
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const data = response.data as EmployeeListResponse | null;
|
|
57
|
+
|
|
58
|
+
if (!data) {
|
|
59
|
+
if (options.json) {
|
|
60
|
+
console.log(JSON.stringify({ success: true, data: { items: [], pagination: { pageNo: 0, pageSize: 20, totalRows: 0 } } }, null, 2));
|
|
61
|
+
} else {
|
|
62
|
+
console.log(chalk.bold('\nš Employee List\n'));
|
|
63
|
+
console.log(chalk.gray(' No employees found\n'));
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (options.json) {
|
|
69
|
+
console.log(
|
|
70
|
+
JSON.stringify(
|
|
71
|
+
{
|
|
72
|
+
success: true,
|
|
73
|
+
data: {
|
|
74
|
+
items: data.rows || [],
|
|
75
|
+
pagination: {
|
|
76
|
+
pageNo: data.pageNo,
|
|
77
|
+
pageSize: data.pageSize,
|
|
78
|
+
totalRows: data.totalRows,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
null,
|
|
83
|
+
2
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const records = data.rows || [];
|
|
90
|
+
|
|
91
|
+
if (records.length === 0) {
|
|
92
|
+
console.log(chalk.bold('\nš Employee List\n'));
|
|
93
|
+
console.log(chalk.gray(' No employees found\n'));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log(chalk.bold('\nš Employee List\n'));
|
|
98
|
+
|
|
99
|
+
const table = new Table({
|
|
100
|
+
head: [chalk.bold('ID'), chalk.bold('Code'), chalk.bold('Name'), chalk.bold('Phone'), chalk.bold('Org'), chalk.bold('Status')],
|
|
101
|
+
colWidths: [8, 12, 18, 15, 20, 10],
|
|
102
|
+
style: {
|
|
103
|
+
head: [],
|
|
104
|
+
border: [],
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
for (const emp of records) {
|
|
109
|
+
const statusText = emp.statusFlag === 1 ? chalk.green('Enable') : chalk.red('Disable');
|
|
110
|
+
table.push([
|
|
111
|
+
emp.employeeId,
|
|
112
|
+
emp.employeeCode || '-',
|
|
113
|
+
emp.employeeName || '-',
|
|
114
|
+
emp.employeePhone || '-',
|
|
115
|
+
emp.orgName || '-',
|
|
116
|
+
statusText,
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log(table.toString());
|
|
121
|
+
console.log();
|
|
122
|
+
console.log(
|
|
123
|
+
chalk.gray(
|
|
124
|
+
` Total: ${data.totalRows} | Page: ${data.pageNo} / ${Math.ceil(data.totalRows / data.pageSize) || 1} | Size: ${data.pageSize}`
|
|
125
|
+
)
|
|
126
|
+
);
|
|
127
|
+
console.log();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
return listCommand;
|
|
131
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
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 { Employee, UpdateEmployeeRequest } from '../../../types/employee.js';
|
|
8
|
+
|
|
9
|
+
export function createEmployeeUpdateCommand(): Command {
|
|
10
|
+
const updateCommand = new Command('update');
|
|
11
|
+
updateCommand
|
|
12
|
+
.description('Update employee information')
|
|
13
|
+
.argument('<id>', 'Employee ID')
|
|
14
|
+
.option('-n, --name <name>', 'Employee name')
|
|
15
|
+
.option('-p, --phone <phone>', 'Phone number')
|
|
16
|
+
.option('-e, --email <email>', 'Email address')
|
|
17
|
+
.option('--position-id <positionId>', 'Position ID')
|
|
18
|
+
.option('-d, --joined-date <date>', 'Joined date (YYYY-MM-DD)')
|
|
19
|
+
.option('--org-id <orgId>', 'Organization (department) ID')
|
|
20
|
+
.option('--dry-run', 'Preview changes without making API call')
|
|
21
|
+
.option('--json', 'Output result as JSON')
|
|
22
|
+
.action(async (id: string, options: Record<string, unknown>) => {
|
|
23
|
+
const context = configManager.getCurrentContext();
|
|
24
|
+
const environment = context.environment as Environment;
|
|
25
|
+
const tenant = context.tenant;
|
|
26
|
+
|
|
27
|
+
const employeeId = id;
|
|
28
|
+
|
|
29
|
+
const fields: Partial<UpdateEmployeeRequest> = {};
|
|
30
|
+
if (options.name) fields.employeeName = options.name as string;
|
|
31
|
+
if (options.phone) fields.employeePhone = options.phone as string;
|
|
32
|
+
if (options.email) fields.employeeEmail = options.email as string;
|
|
33
|
+
if (options.positionId) fields.positionId = options.positionId as string;
|
|
34
|
+
if (options.joinedDate) fields.employeeJoinedDate = options.joinedDate as string;
|
|
35
|
+
if (options.orgId) fields.organizationId = options.orgId as string;
|
|
36
|
+
|
|
37
|
+
const providedFields = Object.keys(fields).filter(
|
|
38
|
+
(k) => fields[k as keyof UpdateEmployeeRequest] !== undefined
|
|
39
|
+
);
|
|
40
|
+
if (providedFields.length === 0) {
|
|
41
|
+
console.error(
|
|
42
|
+
chalk.red('\nā No fields to update. Provide at least one of: --name, --phone, --email, --position-id, --joined-date, --org-id\n')
|
|
43
|
+
);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (options.email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(options.email as string)) {
|
|
48
|
+
console.error(chalk.red('\nā Invalid email format\n'));
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (options.phone && !/^\+?[\d\s\-()]+$/.test(options.phone as string)) {
|
|
53
|
+
console.error(chalk.red('\nā Invalid phone number format\n'));
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (options.joinedDate && !/^\d{4}-\d{2}-\d{2}$/.test(options.joinedDate as string)) {
|
|
58
|
+
console.error(chalk.red('\nā Invalid date format. Use YYYY-MM-DD\n'));
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (options.dryRun) {
|
|
63
|
+
console.log(chalk.bold(`\nš¤ Update Employee ā Dry Run (${environment})\n`));
|
|
64
|
+
console.log(chalk.gray(` Employee ID: ${employeeId}`));
|
|
65
|
+
console.log(chalk.gray('\n Changes to be applied:'));
|
|
66
|
+
for (const field of providedFields) {
|
|
67
|
+
const label = field.replace(/([A-Z])/g, (m) => ` ${m.toLowerCase()}`).trim();
|
|
68
|
+
console.log(chalk.cyan(` ${label}: "${fields[field as keyof UpdateEmployeeRequest]}"`));
|
|
69
|
+
}
|
|
70
|
+
console.log();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let currentEmployee: Employee | undefined;
|
|
75
|
+
try {
|
|
76
|
+
const employeeResponse = await apiClient.getEmployee(environment, tenant, employeeId);
|
|
77
|
+
if (!employeeResponse.success || !employeeResponse.data) {
|
|
78
|
+
console.error(chalk.red(`\nā Employee not found: ${employeeId}`));
|
|
79
|
+
if (employeeResponse.error?.message) {
|
|
80
|
+
console.error(chalk.gray(` ${employeeResponse.error.message}`));
|
|
81
|
+
}
|
|
82
|
+
if (employeeResponse.error?.code) {
|
|
83
|
+
console.error(chalk.gray(` Error code: ${employeeResponse.error.code}`));
|
|
84
|
+
}
|
|
85
|
+
console.error();
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
currentEmployee = employeeResponse.data as Employee;
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error(chalk.red(`\nā Failed to fetch employee: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.log(chalk.bold(`\nš¤ Update Employee (${environment})\n`));
|
|
95
|
+
console.log(chalk.gray(` Employee ID: ${employeeId}`));
|
|
96
|
+
console.log(chalk.gray(` Current Name: ${currentEmployee.employeeName}`));
|
|
97
|
+
console.log(chalk.gray('\n Changes:'));
|
|
98
|
+
for (const field of providedFields) {
|
|
99
|
+
const label = field.replace(/([A-Z])/g, (m) => ` ${m.toLowerCase()}`).trim();
|
|
100
|
+
const currentVal = (currentEmployee as unknown as Record<string, unknown>)[field] ?? '(not set)';
|
|
101
|
+
const newVal = fields[field as keyof UpdateEmployeeRequest];
|
|
102
|
+
console.log(chalk.cyan(` ${label}: "${currentVal}" ā "${newVal}"`));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const { confirm } = await inquirer.prompt([
|
|
106
|
+
{
|
|
107
|
+
type: 'confirm',
|
|
108
|
+
name: 'confirm',
|
|
109
|
+
message: 'Apply these changes?',
|
|
110
|
+
default: true,
|
|
111
|
+
},
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
if (!confirm) {
|
|
115
|
+
console.log(chalk.gray('\n Operation cancelled.\n'));
|
|
116
|
+
process.exit(0);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const updateData: UpdateEmployeeRequest = { employeeId, ...fields };
|
|
120
|
+
try {
|
|
121
|
+
const response = await apiClient.updateEmployee(environment, tenant, updateData);
|
|
122
|
+
|
|
123
|
+
if (response.success) {
|
|
124
|
+
if (options.json) {
|
|
125
|
+
console.log(JSON.stringify({ success: true, data: response.data }, null, 2));
|
|
126
|
+
} else {
|
|
127
|
+
console.log(chalk.green(`\nā Employee updated successfully\n`));
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
if (options.json) {
|
|
131
|
+
console.log(JSON.stringify({ success: false, error: response.error }, null, 2));
|
|
132
|
+
} else {
|
|
133
|
+
console.error(chalk.red(`\nā Update failed: ${response.error?.message || 'Unknown error'}`));
|
|
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
|
+
if (options.json) {
|
|
143
|
+
console.log(
|
|
144
|
+
JSON.stringify({
|
|
145
|
+
success: false,
|
|
146
|
+
error: { message: error instanceof Error ? error.message : 'Unknown error' },
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
} else {
|
|
150
|
+
console.error(chalk.red(`\nā Error: ${error instanceof Error ? error.message : 'Unknown error'}\n`));
|
|
151
|
+
}
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return updateCommand;
|
|
157
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { createLibericaAuthCommand } from './auth/index.js';
|
|
4
|
+
import { createLibericaContextCommand } from './context/index.js';
|
|
5
|
+
import { createEmployeesCommand } from './employees/index.js';
|
|
6
|
+
import { createUsersCommand } from './users/index.js';
|
|
7
|
+
import { createOrgsCommand } from './orgs/index.js';
|
|
8
|
+
import { createPositionsCommand } from './positions/index.js';
|
|
9
|
+
import { createRolesCommand } from './roles/index.js';
|
|
10
|
+
|
|
11
|
+
export function createLibericaCommand(): Command {
|
|
12
|
+
const libericaCommand = new Command('liberica');
|
|
13
|
+
libericaCommand.description('Liberica production management operations');
|
|
14
|
+
|
|
15
|
+
libericaCommand.addCommand(createLibericaAuthCommand());
|
|
16
|
+
libericaCommand.addCommand(createLibericaContextCommand());
|
|
17
|
+
libericaCommand.addCommand(createEmployeesCommand());
|
|
18
|
+
libericaCommand.addCommand(createUsersCommand());
|
|
19
|
+
libericaCommand.addCommand(createOrgsCommand());
|
|
20
|
+
libericaCommand.addCommand(createPositionsCommand());
|
|
21
|
+
libericaCommand.addCommand(createRolesCommand());
|
|
22
|
+
|
|
23
|
+
libericaCommand.action(() => {
|
|
24
|
+
console.log(chalk.bold('\nā Liberica Commands\n'));
|
|
25
|
+
console.log(' Use "barista liberica auth <command>" for authentication');
|
|
26
|
+
console.log(' Use "barista liberica context <command>" for context management');
|
|
27
|
+
console.log(' Use "barista liberica employees <command>" for employee management');
|
|
28
|
+
console.log(' Use "barista liberica users <command>" for user management');
|
|
29
|
+
console.log(' Use "barista liberica orders <command>" for order operations');
|
|
30
|
+
console.log(' Use "barista liberica products <command>" for product operations');
|
|
31
|
+
console.log(' Use "barista liberica production <command>" for production operations');
|
|
32
|
+
console.log('\n Run "barista liberica <command> --help" for more details\n');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return libericaCommand;
|
|
36
|
+
}
|