@newpeak/barista-cli 0.1.11 → 0.1.13
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/dict-types/get.d.ts.map +1 -1
- package/dist/commands/liberica/dict-types/get.js +9 -1
- package/dist/commands/liberica/dict-types/get.js.map +1 -1
- package/dist/commands/liberica/dict-types/index.d.ts.map +1 -1
- package/dist/commands/liberica/dict-types/index.js +2 -0
- package/dist/commands/liberica/dict-types/index.js.map +1 -1
- package/dist/commands/liberica/dict-types/list.d.ts.map +1 -1
- package/dist/commands/liberica/dict-types/list.js +19 -1
- package/dist/commands/liberica/dict-types/list.js.map +1 -1
- package/dist/commands/liberica/dict-types/tenant-items.d.ts +3 -0
- package/dist/commands/liberica/dict-types/tenant-items.d.ts.map +1 -0
- package/dist/commands/liberica/dict-types/tenant-items.js +275 -0
- package/dist/commands/liberica/dict-types/tenant-items.js.map +1 -0
- package/dist/commands/liberica/dicts/get.d.ts.map +1 -1
- package/dist/commands/liberica/dicts/get.js +9 -1
- package/dist/commands/liberica/dicts/get.js.map +1 -1
- package/dist/commands/liberica/dicts/list.d.ts.map +1 -1
- package/dist/commands/liberica/dicts/list.js +9 -1
- package/dist/commands/liberica/dicts/list.js.map +1 -1
- package/dist/core/api/client.d.ts +7 -7
- package/dist/core/api/client.d.ts.map +1 -1
- package/dist/core/api/client.js +15 -12
- package/dist/core/api/client.js.map +1 -1
- package/dist/core/config/manager.d.ts.map +1 -1
- package/dist/core/config/manager.js +1 -0
- package/dist/core/config/manager.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/dict.d.ts +2 -0
- package/dist/types/dict.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +7 -3
- package/docs/ARCHITECTURE.md +0 -184
- package/docs/COMMANDS.md +0 -352
- package/docs/COMMAND_DESIGN_SPEC.md +0 -840
- package/docs/INTEGRATION_NOTES.md +0 -270
- package/docs/commands/REFERENCE.md +0 -323
- package/docs/commands/arabica/auth/index.md +0 -296
- package/docs/commands/liberica/auth/index.md +0 -133
- package/docs/commands/liberica/calendar/DESIGN.md +0 -333
- package/docs/commands/liberica/client-contacts/create.md +0 -152
- package/docs/commands/liberica/client-contacts/delete.md +0 -123
- package/docs/commands/liberica/client-contacts/get.md +0 -133
- package/docs/commands/liberica/client-contacts/list.md +0 -143
- package/docs/commands/liberica/client-contacts/update.md +0 -158
- package/docs/commands/liberica/context/index.md +0 -60
- package/docs/commands/liberica/currency/create.md +0 -145
- package/docs/commands/liberica/currency/delete.md +0 -121
- package/docs/commands/liberica/currency/disable.md +0 -119
- package/docs/commands/liberica/currency/enable.md +0 -115
- package/docs/commands/liberica/currency/get.md +0 -118
- package/docs/commands/liberica/currency/list.md +0 -149
- package/docs/commands/liberica/currency/update.md +0 -141
- package/docs/commands/liberica/employees/create.md +0 -185
- package/docs/commands/liberica/employees/disable.md +0 -138
- package/docs/commands/liberica/employees/enable.md +0 -137
- package/docs/commands/liberica/employees/get.md +0 -153
- package/docs/commands/liberica/employees/list.md +0 -168
- package/docs/commands/liberica/employees/update.md +0 -180
- package/docs/commands/liberica/locations/create.md +0 -195
- package/docs/commands/liberica/locations/list.md +0 -171
- package/docs/commands/liberica/materials/create.md +0 -293
- package/docs/commands/liberica/materials/delete.md +0 -240
- package/docs/commands/liberica/materials/disable.md +0 -150
- package/docs/commands/liberica/materials/enable.md +0 -146
- package/docs/commands/liberica/materials/get.md +0 -188
- package/docs/commands/liberica/materials/list.md +0 -198
- package/docs/commands/liberica/materials/update.md +0 -250
- package/docs/commands/liberica/orgs/list.md +0 -62
- package/docs/commands/liberica/positions/list.md +0 -61
- package/docs/commands/liberica/roles/list.md +0 -67
- package/docs/commands/liberica/stock/ledger.md +0 -209
- package/docs/commands/liberica/stock/list.md +0 -165
- package/docs/commands/liberica/supplier-contacts/create.md +0 -152
- package/docs/commands/liberica/supplier-contacts/delete.md +0 -123
- package/docs/commands/liberica/supplier-contacts/get.md +0 -133
- package/docs/commands/liberica/supplier-contacts/list.md +0 -143
- package/docs/commands/liberica/supplier-contacts/update.md +0 -158
- package/docs/commands/liberica/teams/issues/close.md +0 -161
- package/docs/commands/liberica/teams/issues/create.md +0 -212
- package/docs/commands/liberica/teams/issues/delete.md +0 -179
- package/docs/commands/liberica/teams/issues/get.md +0 -167
- package/docs/commands/liberica/teams/issues/list.md +0 -182
- package/docs/commands/liberica/teams/issues/tests-design.md +0 -341
- package/docs/commands/liberica/teams/issues/update.md +0 -202
- package/docs/commands/liberica/teams/projects/create.md +0 -174
- package/docs/commands/liberica/teams/projects/delete.md +0 -180
- package/docs/commands/liberica/teams/projects/get.md +0 -150
- package/docs/commands/liberica/teams/projects/list.md +0 -179
- package/docs/commands/liberica/teams/projects/update.md +0 -175
- package/docs/commands/liberica/teams/tasks/create.md +0 -163
- package/docs/commands/liberica/teams/tasks/delete.md +0 -109
- package/docs/commands/liberica/teams/tasks/get.md +0 -121
- package/docs/commands/liberica/teams/tasks/list.md +0 -148
- package/docs/commands/liberica/teams/tasks/update.md +0 -158
- package/docs/commands/liberica/teams/work-logs/create.md +0 -151
- package/docs/commands/liberica/teams/work-logs/delete.md +0 -130
- package/docs/commands/liberica/teams/work-logs/get.md +0 -131
- package/docs/commands/liberica/teams/work-logs/list.md +0 -153
- package/docs/commands/liberica/teams/work-logs/update.md +0 -150
- package/docs/commands/liberica/transfer-in-forms/batch-delete.md +0 -157
- package/docs/commands/liberica/transfer-in-forms/batch-review.md +0 -157
- package/docs/commands/liberica/transfer-in-forms/batch-unreview.md +0 -157
- package/docs/commands/liberica/transfer-in-forms/create.md +0 -220
- package/docs/commands/liberica/transfer-in-forms/get.md +0 -221
- package/docs/commands/liberica/transfer-in-forms/list.md +0 -242
- package/docs/commands/liberica/transfer-in-forms/update.md +0 -185
- package/docs/commands/liberica/transfer-out-forms/batch-delete.md +0 -187
- package/docs/commands/liberica/transfer-out-forms/batch-review.md +0 -157
- package/docs/commands/liberica/transfer-out-forms/batch-unreview.md +0 -157
- package/docs/commands/liberica/transfer-out-forms/create.md +0 -280
- package/docs/commands/liberica/transfer-out-forms/get.md +0 -211
- package/docs/commands/liberica/transfer-out-forms/list.md +0 -233
- package/docs/commands/liberica/transfer-out-forms/update.md +0 -286
- package/docs/commands/liberica/uoms/create.md +0 -136
- package/docs/commands/liberica/uoms/delete.md +0 -119
- package/docs/commands/liberica/uoms/disable.md +0 -117
- package/docs/commands/liberica/uoms/enable.md +0 -115
- package/docs/commands/liberica/uoms/get.md +0 -119
- package/docs/commands/liberica/uoms/list.md +0 -155
- package/docs/commands/liberica/uoms/update.md +0 -148
- package/docs/commands/liberica/users/create.md +0 -170
- package/docs/commands/liberica/users/get.md +0 -151
- package/docs/commands/liberica/users/list.md +0 -175
- package/docs/commands/liberica/warehouses/create.md +0 -222
- package/docs/commands/liberica/warehouses/list.md +0 -184
- package/src/commands/arabica/auth/index.ts +0 -277
- package/src/commands/arabica/auth/login.ts +0 -5
- package/src/commands/arabica/auth/logout.ts +0 -5
- package/src/commands/arabica/auth/register.ts +0 -5
- package/src/commands/arabica/auth/status.ts +0 -5
- package/src/commands/arabica/index.ts +0 -23
- package/src/commands/auth.ts +0 -107
- package/src/commands/context.ts +0 -60
- package/src/commands/liberica/auth/index.ts +0 -176
- package/src/commands/liberica/calendar/index.ts +0 -13
- package/src/commands/liberica/calendar/list.ts +0 -214
- package/src/commands/liberica/calendar/set.ts +0 -130
- package/src/commands/liberica/client-contacts/create.ts +0 -115
- package/src/commands/liberica/client-contacts/delete.ts +0 -140
- package/src/commands/liberica/client-contacts/get.ts +0 -103
- package/src/commands/liberica/client-contacts/index.ts +0 -19
- package/src/commands/liberica/client-contacts/list.ts +0 -118
- package/src/commands/liberica/client-contacts/update.ts +0 -137
- package/src/commands/liberica/clients/create.ts +0 -122
- package/src/commands/liberica/clients/delete.ts +0 -125
- package/src/commands/liberica/clients/get.ts +0 -88
- package/src/commands/liberica/clients/index.ts +0 -19
- package/src/commands/liberica/clients/list.ts +0 -123
- package/src/commands/liberica/clients/update.ts +0 -103
- package/src/commands/liberica/context/index.ts +0 -43
- package/src/commands/liberica/currency/create.ts +0 -183
- package/src/commands/liberica/currency/delete.ts +0 -124
- package/src/commands/liberica/currency/disable.ts +0 -147
- package/src/commands/liberica/currency/enable.ts +0 -128
- package/src/commands/liberica/currency/get.ts +0 -91
- package/src/commands/liberica/currency/index.ts +0 -23
- package/src/commands/liberica/currency/list.ts +0 -140
- package/src/commands/liberica/currency/update.ts +0 -129
- package/src/commands/liberica/dict-types/get.ts +0 -74
- package/src/commands/liberica/dict-types/index.ts +0 -15
- package/src/commands/liberica/dict-types/list.ts +0 -118
- package/src/commands/liberica/dict-types/update.ts +0 -134
- package/src/commands/liberica/dicts/create.ts +0 -175
- package/src/commands/liberica/dicts/delete.ts +0 -107
- package/src/commands/liberica/dicts/get.ts +0 -80
- package/src/commands/liberica/dicts/index.ts +0 -19
- package/src/commands/liberica/dicts/list.ts +0 -114
- package/src/commands/liberica/dicts/update.ts +0 -116
- package/src/commands/liberica/employees/create.ts +0 -275
- package/src/commands/liberica/employees/delete.ts +0 -122
- package/src/commands/liberica/employees/disable.ts +0 -97
- package/src/commands/liberica/employees/enable.ts +0 -97
- package/src/commands/liberica/employees/get.ts +0 -115
- package/src/commands/liberica/employees/index.ts +0 -23
- package/src/commands/liberica/employees/list.ts +0 -131
- package/src/commands/liberica/employees/update.ts +0 -157
- package/src/commands/liberica/index.ts +0 -81
- package/src/commands/liberica/materials/create.ts +0 -199
- package/src/commands/liberica/materials/delete.ts +0 -105
- package/src/commands/liberica/materials/disable.ts +0 -148
- package/src/commands/liberica/materials/enable.ts +0 -129
- package/src/commands/liberica/materials/get.ts +0 -83
- package/src/commands/liberica/materials/index.ts +0 -23
- package/src/commands/liberica/materials/list.ts +0 -142
- package/src/commands/liberica/materials/update.ts +0 -125
- package/src/commands/liberica/mould/get.ts +0 -111
- package/src/commands/liberica/mould/index.ts +0 -17
- package/src/commands/liberica/mould/list.ts +0 -157
- package/src/commands/liberica/mould/set-status.ts +0 -99
- package/src/commands/liberica/mould/stock-in.ts +0 -165
- package/src/commands/liberica/operations/active.ts +0 -153
- package/src/commands/liberica/operations/batch-delete.ts +0 -131
- package/src/commands/liberica/operations/copy.ts +0 -138
- package/src/commands/liberica/operations/create.ts +0 -223
- package/src/commands/liberica/operations/deactive.ts +0 -152
- package/src/commands/liberica/operations/delete.ts +0 -128
- package/src/commands/liberica/operations/design.md +0 -587
- package/src/commands/liberica/operations/get.ts +0 -112
- package/src/commands/liberica/operations/index.ts +0 -27
- package/src/commands/liberica/operations/list.ts +0 -180
- package/src/commands/liberica/operations/update.ts +0 -218
- package/src/commands/liberica/orgs/index.ts +0 -34
- package/src/commands/liberica/positions/index.ts +0 -30
- package/src/commands/liberica/roles/index.ts +0 -59
- package/src/commands/liberica/stock/index.ts +0 -13
- package/src/commands/liberica/stock/ledger.ts +0 -159
- package/src/commands/liberica/stock/list.ts +0 -128
- package/src/commands/liberica/supplier-contacts/create.ts +0 -120
- package/src/commands/liberica/supplier-contacts/delete.ts +0 -88
- package/src/commands/liberica/supplier-contacts/get.ts +0 -94
- package/src/commands/liberica/supplier-contacts/index.ts +0 -19
- package/src/commands/liberica/supplier-contacts/list.ts +0 -130
- package/src/commands/liberica/supplier-contacts/update.ts +0 -127
- package/src/commands/liberica/suppliers/create.ts +0 -149
- package/src/commands/liberica/suppliers/delete.ts +0 -102
- package/src/commands/liberica/suppliers/disable.ts +0 -145
- package/src/commands/liberica/suppliers/enable.ts +0 -126
- package/src/commands/liberica/suppliers/get.ts +0 -86
- package/src/commands/liberica/suppliers/index.ts +0 -23
- package/src/commands/liberica/suppliers/list.ts +0 -134
- package/src/commands/liberica/suppliers/update.ts +0 -128
- package/src/commands/liberica/teams/index.ts +0 -17
- package/src/commands/liberica/teams/issues/close.ts +0 -104
- package/src/commands/liberica/teams/issues/create.ts +0 -254
- package/src/commands/liberica/teams/issues/delete.ts +0 -58
- package/src/commands/liberica/teams/issues/get.ts +0 -78
- package/src/commands/liberica/teams/issues/index.ts +0 -21
- package/src/commands/liberica/teams/issues/list.ts +0 -144
- package/src/commands/liberica/teams/issues/update.ts +0 -141
- package/src/commands/liberica/teams/projects/create.ts +0 -159
- package/src/commands/liberica/teams/projects/delete.ts +0 -58
- package/src/commands/liberica/teams/projects/get.ts +0 -87
- package/src/commands/liberica/teams/projects/index.ts +0 -19
- package/src/commands/liberica/teams/projects/list.ts +0 -147
- package/src/commands/liberica/teams/projects/update.ts +0 -117
- package/src/commands/liberica/teams/tasks/create.ts +0 -102
- package/src/commands/liberica/teams/tasks/delete.ts +0 -92
- package/src/commands/liberica/teams/tasks/get.ts +0 -64
- package/src/commands/liberica/teams/tasks/index.ts +0 -19
- package/src/commands/liberica/teams/tasks/list.ts +0 -102
- package/src/commands/liberica/teams/tasks/update.ts +0 -122
- package/src/commands/liberica/teams/work-logs/create.ts +0 -204
- package/src/commands/liberica/teams/work-logs/delete.ts +0 -58
- package/src/commands/liberica/teams/work-logs/get.ts +0 -87
- package/src/commands/liberica/teams/work-logs/index.ts +0 -19
- package/src/commands/liberica/teams/work-logs/list.ts +0 -141
- package/src/commands/liberica/teams/work-logs/update.ts +0 -120
- package/src/commands/liberica/transfer-in-forms/batch-delete.ts +0 -152
- package/src/commands/liberica/transfer-in-forms/batch-review.ts +0 -151
- package/src/commands/liberica/transfer-in-forms/batch-unreview.ts +0 -152
- package/src/commands/liberica/transfer-in-forms/create.ts +0 -179
- package/src/commands/liberica/transfer-in-forms/get.ts +0 -107
- package/src/commands/liberica/transfer-in-forms/index.ts +0 -23
- package/src/commands/liberica/transfer-in-forms/list.ts +0 -97
- package/src/commands/liberica/transfer-in-forms/update.ts +0 -213
- package/src/commands/liberica/transfer-out-forms/batch-delete.ts +0 -83
- package/src/commands/liberica/transfer-out-forms/batch-review.ts +0 -148
- package/src/commands/liberica/transfer-out-forms/batch-unreview.ts +0 -56
- package/src/commands/liberica/transfer-out-forms/create.ts +0 -194
- package/src/commands/liberica/transfer-out-forms/get.ts +0 -114
- package/src/commands/liberica/transfer-out-forms/index.ts +0 -23
- package/src/commands/liberica/transfer-out-forms/list.ts +0 -125
- package/src/commands/liberica/transfer-out-forms/update.ts +0 -197
- package/src/commands/liberica/uoms/create.ts +0 -134
- package/src/commands/liberica/uoms/delete.ts +0 -105
- package/src/commands/liberica/uoms/disable.ts +0 -148
- package/src/commands/liberica/uoms/enable.ts +0 -129
- package/src/commands/liberica/uoms/get.ts +0 -83
- package/src/commands/liberica/uoms/index.ts +0 -23
- package/src/commands/liberica/uoms/list.ts +0 -129
- package/src/commands/liberica/uoms/update.ts +0 -124
- package/src/commands/liberica/users/create.ts +0 -133
- package/src/commands/liberica/users/delete.ts +0 -49
- package/src/commands/liberica/users/disable.ts +0 -41
- package/src/commands/liberica/users/enable.ts +0 -30
- package/src/commands/liberica/users/get.ts +0 -46
- package/src/commands/liberica/users/index.ts +0 -27
- package/src/commands/liberica/users/list.ts +0 -68
- package/src/commands/liberica/users/me.ts +0 -42
- package/src/commands/liberica/users/reset-password.ts +0 -42
- package/src/commands/liberica/users/update.ts +0 -48
- package/src/commands/liberica/warehouses/create.ts +0 -204
- package/src/commands/liberica/warehouses/delete.ts +0 -112
- package/src/commands/liberica/warehouses/disable.ts +0 -174
- package/src/commands/liberica/warehouses/enable.ts +0 -174
- package/src/commands/liberica/warehouses/get.ts +0 -101
- package/src/commands/liberica/warehouses/index.ts +0 -25
- package/src/commands/liberica/warehouses/list.ts +0 -136
- package/src/commands/liberica/warehouses/locations/create.ts +0 -209
- package/src/commands/liberica/warehouses/locations/delete.ts +0 -116
- package/src/commands/liberica/warehouses/locations/disable.ts +0 -174
- package/src/commands/liberica/warehouses/locations/enable.ts +0 -174
- package/src/commands/liberica/warehouses/locations/get.ts +0 -84
- package/src/commands/liberica/warehouses/locations/index.ts +0 -23
- package/src/commands/liberica/warehouses/locations/list.ts +0 -140
- package/src/commands/liberica/warehouses/locations/update.ts +0 -135
- package/src/commands/liberica/warehouses/update.ts +0 -142
- package/src/core/api/client.ts +0 -4443
- package/src/core/auth/token-manager.ts +0 -183
- package/src/core/config/manager.ts +0 -164
- package/src/index.ts +0 -35
- package/src/types/calendar.ts +0 -36
- package/src/types/client-contact.ts +0 -78
- package/src/types/client.ts +0 -115
- package/src/types/currency.ts +0 -90
- package/src/types/dict.ts +0 -121
- package/src/types/employee.ts +0 -102
- package/src/types/index.ts +0 -93
- package/src/types/location.ts +0 -66
- package/src/types/material.ts +0 -61
- package/src/types/mould-stock-in.ts +0 -82
- package/src/types/mould.ts +0 -74
- package/src/types/operation.ts +0 -72
- package/src/types/org.ts +0 -25
- package/src/types/position.ts +0 -24
- package/src/types/stock.ts +0 -161
- package/src/types/supplier-contact.ts +0 -78
- package/src/types/supplier.ts +0 -66
- package/src/types/team-issue.ts +0 -94
- package/src/types/team-project.ts +0 -74
- package/src/types/team-task.ts +0 -98
- package/src/types/team-work-log.ts +0 -87
- package/src/types/transfer-in-form.ts +0 -265
- package/src/types/transfer-out-form.ts +0 -290
- package/src/types/uom.ts +0 -60
- package/src/types/user.ts +0 -64
- package/src/types/warehouse.ts +0 -82
|
@@ -1,103 +0,0 @@
|
|
|
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 { UpdateClientRequest, StatusFlag } from '../../../types/client.js';
|
|
7
|
-
|
|
8
|
-
export function createClientUpdateCommand(): Command {
|
|
9
|
-
const cmd = new Command('update');
|
|
10
|
-
cmd.description('Update a client');
|
|
11
|
-
cmd.arguments('<clientId>');
|
|
12
|
-
|
|
13
|
-
cmd
|
|
14
|
-
.option('--client-name <name>', 'Client name')
|
|
15
|
-
.option('--follower <name>', 'Follower/salesperson')
|
|
16
|
-
.option('--office-address <address>', 'Office address')
|
|
17
|
-
.option('--office-telephone <phone>', 'Office telephone')
|
|
18
|
-
.option('--status <status>', 'Status (1=enable, 2=disable)')
|
|
19
|
-
.option('--remark <remark>', 'Remark')
|
|
20
|
-
.option('--json', 'Output as JSON')
|
|
21
|
-
.action(async (clientId: string, options: Record<string, unknown>) => {
|
|
22
|
-
const context = configManager.getCurrentContext();
|
|
23
|
-
const environment = context.environment as Environment;
|
|
24
|
-
const tenant = context.tenant;
|
|
25
|
-
const jsonOutput = options.json === true;
|
|
26
|
-
|
|
27
|
-
if (!clientId) {
|
|
28
|
-
if (jsonOutput) {
|
|
29
|
-
console.log(JSON.stringify({ success: false, error: { code: 'VALIDATION_ERROR', message: 'Client ID is required' } }));
|
|
30
|
-
} else {
|
|
31
|
-
console.error(chalk.red('\n✗ Client ID is required\n'));
|
|
32
|
-
}
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const fields: Partial<UpdateClientRequest> = {
|
|
37
|
-
clientId,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
if (options.clientName) fields.clientName = options.clientName as string;
|
|
41
|
-
if (options.follower) fields.follower = options.follower as string;
|
|
42
|
-
if (options.officeAddress) fields.officeAddress = options.officeAddress as string;
|
|
43
|
-
if (options.officeTelephone) fields.officeTelephone = options.officeTelephone as string;
|
|
44
|
-
if (options.status) fields.statusFlag = parseInt(options.status as string) as StatusFlag;
|
|
45
|
-
if (options.remark) fields.remark = options.remark as string;
|
|
46
|
-
|
|
47
|
-
const updateFields = Object.keys(fields).filter(k => k !== 'clientId' && fields[k as keyof UpdateClientRequest] !== undefined);
|
|
48
|
-
if (updateFields.length === 0) {
|
|
49
|
-
if (jsonOutput) {
|
|
50
|
-
console.log(JSON.stringify({ success: false, error: { code: 'VALIDATION_ERROR', message: 'No fields to update. Provide at least one of: --client-name, --follower, --office-address, --office-telephone, --status, --remark' } }));
|
|
51
|
-
} else {
|
|
52
|
-
console.error(chalk.red('\n✗ No fields to update. Provide at least one of: --client-name, --follower, --office-address, --office-telephone, --status, --remark\n'));
|
|
53
|
-
}
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const updateData: UpdateClientRequest = fields as UpdateClientRequest;
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const response = await apiClient.updateClient(environment, tenant, updateData);
|
|
61
|
-
|
|
62
|
-
if (response.success) {
|
|
63
|
-
if (jsonOutput) {
|
|
64
|
-
console.log(JSON.stringify({ success: true, data: response.data }));
|
|
65
|
-
} else {
|
|
66
|
-
console.log(chalk.green('\n✓ Client updated successfully\n'));
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
const errorMsg = response.error?.message || 'Unknown error';
|
|
70
|
-
const errorCode = response.error?.code || 'UPDATE_CLIENT_ERROR';
|
|
71
|
-
|
|
72
|
-
if (errorCode === '01001150001' || errorMsg.includes('不存在')) {
|
|
73
|
-
if (jsonOutput) {
|
|
74
|
-
console.log(JSON.stringify({ success: false, error: { code: 'NOT_FOUND', message: `Client not found: ${clientId}` } }));
|
|
75
|
-
} else {
|
|
76
|
-
console.error(chalk.red(`\n✗ Client not found: ${clientId}\n`));
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
if (jsonOutput) {
|
|
80
|
-
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
81
|
-
} else {
|
|
82
|
-
console.error(chalk.red(`\n✗ Failed to update client: ${errorMsg}`));
|
|
83
|
-
if (response.error?.code) {
|
|
84
|
-
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
85
|
-
}
|
|
86
|
-
console.error();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
process.exit(1);
|
|
90
|
-
}
|
|
91
|
-
} catch (error) {
|
|
92
|
-
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
93
|
-
if (jsonOutput) {
|
|
94
|
-
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
95
|
-
} else {
|
|
96
|
-
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
97
|
-
}
|
|
98
|
-
process.exit(1);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
return cmd;
|
|
103
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { configManager } from '../../../core/config/manager.js';
|
|
4
|
-
import { tokenManager } from '../../../core/auth/token-manager.js';
|
|
5
|
-
|
|
6
|
-
export function createLibericaContextCommand(): Command {
|
|
7
|
-
const contextCommand = new Command('context');
|
|
8
|
-
contextCommand.description('Manage Liberica context (tenant, environment)');
|
|
9
|
-
|
|
10
|
-
contextCommand.action(async () => {
|
|
11
|
-
await contextCommand.help();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
contextCommand
|
|
15
|
-
.command('show')
|
|
16
|
-
.description('Show current Liberica context')
|
|
17
|
-
.action(async () => {
|
|
18
|
-
const context = configManager.getCurrentContext();
|
|
19
|
-
const token = await tokenManager.getToken({
|
|
20
|
-
service: 'liberica',
|
|
21
|
-
environment: context.environment,
|
|
22
|
-
tenant: context.tenant,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
console.log(chalk.bold('\n📋 Liberica Context\n'));
|
|
26
|
-
console.log(` ${chalk.gray('Environment:')} ${chalk.green(context.environment)}`);
|
|
27
|
-
console.log(` ${chalk.gray('Tenant:')} ${chalk.green(context.tenant)}`);
|
|
28
|
-
console.log(
|
|
29
|
-
` ${chalk.gray('Auth Status:')} ${token ? chalk.green('✓ Logged in') : chalk.red('✗ Not logged in')}`
|
|
30
|
-
);
|
|
31
|
-
console.log();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
contextCommand
|
|
35
|
-
.command('use-enterprise <tenant>')
|
|
36
|
-
.description('Switch Liberica tenant (enterprise)')
|
|
37
|
-
.action(async (tenant: string) => {
|
|
38
|
-
await configManager.setTenant(tenant);
|
|
39
|
-
console.log(chalk.green(`\n✓ Tenant set to ${tenant}\n`));
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return contextCommand;
|
|
43
|
-
}
|
|
@@ -1,183 +0,0 @@
|
|
|
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 { CreateCurrencyRequest, CurrencyDefault } from '../../../types/currency.js';
|
|
7
|
-
|
|
8
|
-
function formatTable(data: CreateCurrencyRequest): string {
|
|
9
|
-
const lines: string[] = [];
|
|
10
|
-
lines.push(` ${chalk.gray('Code:')} ${data.currencyCode || '(not set)'}`);
|
|
11
|
-
lines.push(` ${chalk.gray('Name:')} ${data.currencyName || '(auto-filled from API)'}`);
|
|
12
|
-
lines.push(` ${chalk.gray('Sign:')} ${data.currencySign || '(auto-filled from API)'}`);
|
|
13
|
-
if (data.currencyRate) lines.push(` ${chalk.gray('Rate:')} ${data.currencyRate}`);
|
|
14
|
-
if (data.unitPriceFractionPlaces !== undefined) lines.push(` ${chalk.gray('Unit Fraction Places:')} ${data.unitPriceFractionPlaces}`);
|
|
15
|
-
if (data.amountFractionPlaces !== undefined) lines.push(` ${chalk.gray('Amount Fraction Places:')} ${data.amountFractionPlaces}`);
|
|
16
|
-
if (data.remark) lines.push(` ${chalk.gray('Remark:')} ${data.remark}`);
|
|
17
|
-
return lines.join('\n');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function createCurrencyCreateCommand(): Command {
|
|
21
|
-
const cmd = new Command('create');
|
|
22
|
-
cmd.description('Create a new currency (auto-fills name and sign from getCurrencyDefault)');
|
|
23
|
-
|
|
24
|
-
cmd
|
|
25
|
-
.option('-c, --code <code>', 'Currency code (3 uppercase letters, e.g., CNY, USD)')
|
|
26
|
-
.option('-r, --rate <rate>', 'Currency exchange rate')
|
|
27
|
-
.option('--unit-fraction <places>', 'Unit price fraction places', '2')
|
|
28
|
-
.option('--amount-fraction <places>', 'Amount fraction places', '2')
|
|
29
|
-
.option('--remark <text>', 'Remark')
|
|
30
|
-
.option('--dry-run', 'Preview without making API call')
|
|
31
|
-
.option('--json', 'Output as JSON');
|
|
32
|
-
|
|
33
|
-
cmd.action(async () => {
|
|
34
|
-
const context = configManager.getCurrentContext();
|
|
35
|
-
const opts = cmd.opts();
|
|
36
|
-
|
|
37
|
-
const dryRun = opts.dryRun === true;
|
|
38
|
-
const outputJson = (opts as Record<string, unknown>).json === true || process.argv.includes('--json');
|
|
39
|
-
|
|
40
|
-
let code = opts.code as string | undefined;
|
|
41
|
-
|
|
42
|
-
if (!code) {
|
|
43
|
-
const { inputCode } = await inquirer.prompt([
|
|
44
|
-
{
|
|
45
|
-
type: 'input',
|
|
46
|
-
name: 'inputCode',
|
|
47
|
-
message: 'Enter currency code (3 letters, e.g., CNY, USD):',
|
|
48
|
-
validate: (input: string) => {
|
|
49
|
-
const trimmed = input.trim().toUpperCase();
|
|
50
|
-
if (!trimmed) return 'Currency code is required';
|
|
51
|
-
if (!/^[A-Z]{3}$/.test(trimmed)) return 'Currency code must be 3 uppercase letters (e.g., CNY, USD)';
|
|
52
|
-
return true;
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
]);
|
|
56
|
-
code = inputCode.trim().toUpperCase();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (!/^[A-Z]{3}$/.test(code!)) {
|
|
60
|
-
const errMsg = 'Currency code must be 3 uppercase letters (e.g., CNY, USD)';
|
|
61
|
-
if (outputJson) {
|
|
62
|
-
console.log(JSON.stringify({ success: false, error: { code: 'INVALID_CODE', message: errMsg } }));
|
|
63
|
-
} else {
|
|
64
|
-
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
65
|
-
}
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const validatedCode = code!;
|
|
70
|
-
|
|
71
|
-
if (!outputJson) {
|
|
72
|
-
console.log(chalk.bold('\n🔍 Fetching currency default info...\n'));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const defaultResponse = await apiClient.getCurrencyDefault(context.environment, context.tenant, validatedCode);
|
|
76
|
-
|
|
77
|
-
if (!defaultResponse.success || !defaultResponse.data) {
|
|
78
|
-
const errMsg = defaultResponse.error?.message || `Failed to fetch currency default for ${validatedCode}`;
|
|
79
|
-
if (outputJson) {
|
|
80
|
-
console.log(JSON.stringify({ success: false, error: { code: 'DEFAULT_FETCH_ERROR', message: errMsg } }));
|
|
81
|
-
} else {
|
|
82
|
-
console.error(chalk.red(`\n✗ Failed to fetch currency default: ${errMsg}`));
|
|
83
|
-
if (defaultResponse.error?.code) {
|
|
84
|
-
console.error(chalk.gray(` Error code: ${defaultResponse.error.code}`));
|
|
85
|
-
}
|
|
86
|
-
console.error();
|
|
87
|
-
}
|
|
88
|
-
process.exit(1);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const defaultData = defaultResponse.data as CurrencyDefault;
|
|
92
|
-
|
|
93
|
-
const rate = opts.rate as string | undefined;
|
|
94
|
-
const unitFractionPlaces = parseInt(opts.unitFraction as string, 10) || 2;
|
|
95
|
-
const amountFractionPlaces = parseInt(opts.amountFraction as string, 10) || 2;
|
|
96
|
-
const remark = opts.remark as string | undefined;
|
|
97
|
-
|
|
98
|
-
const data: CreateCurrencyRequest = {
|
|
99
|
-
currencyCode: validatedCode,
|
|
100
|
-
currencyName: defaultData.currencyName,
|
|
101
|
-
currencySign: defaultData.currencySign,
|
|
102
|
-
currencyRate: rate,
|
|
103
|
-
unitPriceFractionPlaces: unitFractionPlaces,
|
|
104
|
-
amountFractionPlaces: amountFractionPlaces,
|
|
105
|
-
remark: remark,
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
Object.keys(data).forEach(key => {
|
|
109
|
-
if (data[key as keyof CreateCurrencyRequest] === undefined) {
|
|
110
|
-
delete data[key as keyof CreateCurrencyRequest];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
if (dryRun) {
|
|
115
|
-
if (outputJson) {
|
|
116
|
-
console.log(JSON.stringify({ success: true, dryRun: true, data }));
|
|
117
|
-
} else {
|
|
118
|
-
console.log(chalk.bold('\n🔍 Dry-Run Mode: No changes will be made\n'));
|
|
119
|
-
console.log(' Currency to be created:');
|
|
120
|
-
console.log(formatTable(data));
|
|
121
|
-
console.log();
|
|
122
|
-
}
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (!outputJson) {
|
|
127
|
-
console.log(chalk.bold('\n📝 Creating Currency\n'));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const response = await apiClient.createCurrency(context.environment, context.tenant, data);
|
|
131
|
-
|
|
132
|
-
if (!response.success) {
|
|
133
|
-
const errorMsg = response.error?.message || 'Failed to create currency';
|
|
134
|
-
const errorCode = response.error?.code || 'CREATE_CURRENCY_ERROR';
|
|
135
|
-
if (outputJson) {
|
|
136
|
-
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
137
|
-
} else {
|
|
138
|
-
console.error(chalk.red(`\n✗ Failed to create currency: ${errorMsg}`));
|
|
139
|
-
if (response.error?.code) {
|
|
140
|
-
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
141
|
-
}
|
|
142
|
-
console.error();
|
|
143
|
-
}
|
|
144
|
-
process.exit(1);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (response.success) {
|
|
148
|
-
const currency = response.data as {
|
|
149
|
-
currencyId?: string;
|
|
150
|
-
currencyCode?: string;
|
|
151
|
-
currencyName?: string;
|
|
152
|
-
currencySign?: string;
|
|
153
|
-
currencyRate?: string;
|
|
154
|
-
unitPriceFractionPlaces?: number;
|
|
155
|
-
amountFractionPlaces?: number;
|
|
156
|
-
statusFlag?: number;
|
|
157
|
-
remark?: string;
|
|
158
|
-
createTime?: string;
|
|
159
|
-
} | undefined;
|
|
160
|
-
|
|
161
|
-
if (outputJson) {
|
|
162
|
-
console.log(JSON.stringify({ success: true, data: currency }));
|
|
163
|
-
} else {
|
|
164
|
-
console.log(chalk.green('✓ Currency created successfully\n'));
|
|
165
|
-
if (currency?.currencyId) console.log(` ${chalk.gray('Currency ID:')} ${chalk.green(String(currency.currencyId))}`);
|
|
166
|
-
if (currency?.currencyCode) console.log(` ${chalk.gray('Code:')} ${currency.currencyCode}`);
|
|
167
|
-
if (currency?.currencyName) console.log(` ${chalk.gray('Name:')} ${currency.currencyName}`);
|
|
168
|
-
if (currency?.currencySign) console.log(` ${chalk.gray('Sign:')} ${currency.currencySign}`);
|
|
169
|
-
if (currency?.currencyRate) console.log(` ${chalk.gray('Rate:')} ${currency.currencyRate}`);
|
|
170
|
-
if (currency?.unitPriceFractionPlaces !== undefined) console.log(` ${chalk.gray('Unit Fraction:')} ${currency.unitPriceFractionPlaces}`);
|
|
171
|
-
if (currency?.amountFractionPlaces !== undefined) console.log(` ${chalk.gray('Amount Fraction:')} ${currency.amountFractionPlaces}`);
|
|
172
|
-
if (currency?.statusFlag !== undefined) {
|
|
173
|
-
const statusText = currency.statusFlag === 1 ? 'Enabled' : 'Disabled';
|
|
174
|
-
console.log(` ${chalk.gray('Status:')} ${chalk.green(statusText)}`);
|
|
175
|
-
}
|
|
176
|
-
if (currency?.remark) console.log(` ${chalk.gray('Remark:')} ${currency.remark}`);
|
|
177
|
-
console.log();
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
return cmd;
|
|
183
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
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 createCurrencyDeleteCommand(): Command {
|
|
10
|
-
const deleteCommand = new Command('delete');
|
|
11
|
-
deleteCommand
|
|
12
|
-
.description('Delete a currency')
|
|
13
|
-
.argument('<currencyId>', 'Currency ID')
|
|
14
|
-
.option('--force', 'Skip confirmation and delete directly')
|
|
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 jsonOutput = options.json === true;
|
|
22
|
-
|
|
23
|
-
if (!jsonOutput) {
|
|
24
|
-
console.log(chalk.bold(`\n🗑️ Delete Currency (${environment})\n`));
|
|
25
|
-
console.log(chalk.gray(` Currency ID: ${currencyId}`));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (options.dryRun) {
|
|
29
|
-
if (jsonOutput) {
|
|
30
|
-
console.log(JSON.stringify({ success: true, dryRun: true, currencyId }));
|
|
31
|
-
} else {
|
|
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 delete the currency.'));
|
|
34
|
-
console.log();
|
|
35
|
-
}
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
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
|
-
if (!options.force) {
|
|
63
|
-
if (!jsonOutput) {
|
|
64
|
-
console.log(chalk.gray(` Name: ${currency.currencyName}`));
|
|
65
|
-
console.log(chalk.gray(` Code: ${currency.currencyCode}`));
|
|
66
|
-
console.log(chalk.gray(` Sign: ${currency.currencySign}`));
|
|
67
|
-
if (currency.currencyRate !== undefined) {
|
|
68
|
-
console.log(chalk.gray(` Rate: ${currency.currencyRate}`));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const { confirm } = await inquirer.prompt([
|
|
73
|
-
{
|
|
74
|
-
type: 'confirm',
|
|
75
|
-
name: 'confirm',
|
|
76
|
-
message: `Delete currency "${currency.currencyName}" (${currency.currencyCode})? This action cannot be undone.`,
|
|
77
|
-
default: false,
|
|
78
|
-
},
|
|
79
|
-
]);
|
|
80
|
-
|
|
81
|
-
if (!confirm) {
|
|
82
|
-
if (!jsonOutput) {
|
|
83
|
-
console.log(chalk.gray('\n Operation cancelled.\n'));
|
|
84
|
-
}
|
|
85
|
-
process.exit(0);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const response = await apiClient.deleteCurrency(environment, tenant, currencyId);
|
|
91
|
-
|
|
92
|
-
if (response.success) {
|
|
93
|
-
if (jsonOutput) {
|
|
94
|
-
console.log(JSON.stringify({ success: true, currencyId, name: currency.currencyName }));
|
|
95
|
-
} else {
|
|
96
|
-
console.log(chalk.green(`\n✓ Currency "${currency.currencyName}" (ID: ${currencyId}) deleted\n`));
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
const errorMsg = response.error?.message || 'Unknown error';
|
|
100
|
-
const errorCode = response.error?.code || 'DELETE_ERROR';
|
|
101
|
-
if (jsonOutput) {
|
|
102
|
-
console.log(JSON.stringify({ success: false, error: { code: errorCode, message: errorMsg } }));
|
|
103
|
-
} else {
|
|
104
|
-
console.error(chalk.red(`\n✗ Failed to delete currency: ${errorMsg}`));
|
|
105
|
-
if (response.error?.code) {
|
|
106
|
-
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
107
|
-
}
|
|
108
|
-
console.error();
|
|
109
|
-
}
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
} catch (error) {
|
|
113
|
-
const errMsg = error instanceof Error ? error.message : 'Unknown error';
|
|
114
|
-
if (jsonOutput) {
|
|
115
|
-
console.log(JSON.stringify({ success: false, error: { code: 'ERROR', message: errMsg } }));
|
|
116
|
-
} else {
|
|
117
|
-
console.error(chalk.red(`\n✗ Error: ${errMsg}\n`));
|
|
118
|
-
}
|
|
119
|
-
process.exit(1);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
return deleteCommand;
|
|
124
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
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
|
-
}
|