@newpeak/barista-cli 0.1.3 → 0.1.4
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/bin/barista.js +0 -0
- package/dist/commands/liberica/clients/create.d.ts +3 -0
- package/dist/commands/liberica/clients/create.d.ts.map +1 -0
- package/dist/commands/liberica/clients/create.js +125 -0
- package/dist/commands/liberica/clients/create.js.map +1 -0
- package/dist/commands/liberica/clients/delete.d.ts +3 -0
- package/dist/commands/liberica/clients/delete.d.ts.map +1 -0
- package/dist/commands/liberica/clients/delete.js +125 -0
- package/dist/commands/liberica/clients/delete.js.map +1 -0
- package/dist/commands/liberica/clients/get.d.ts +3 -0
- package/dist/commands/liberica/clients/get.d.ts.map +1 -0
- package/dist/commands/liberica/clients/get.js +77 -0
- package/dist/commands/liberica/clients/get.js.map +1 -0
- package/dist/commands/liberica/clients/index.d.ts +3 -0
- package/dist/commands/liberica/clients/index.d.ts.map +1 -0
- package/dist/commands/liberica/clients/index.js +17 -0
- package/dist/commands/liberica/clients/index.js.map +1 -0
- package/dist/commands/liberica/clients/list.d.ts +3 -0
- package/dist/commands/liberica/clients/list.d.ts.map +1 -0
- package/dist/commands/liberica/clients/list.js +92 -0
- package/dist/commands/liberica/clients/list.js.map +1 -0
- package/dist/commands/liberica/clients/update.d.ts +3 -0
- package/dist/commands/liberica/clients/update.d.ts.map +1 -0
- package/dist/commands/liberica/clients/update.js +106 -0
- package/dist/commands/liberica/clients/update.js.map +1 -0
- package/dist/commands/liberica/index.d.ts.map +1 -1
- package/dist/commands/liberica/index.js +3 -0
- package/dist/commands/liberica/index.js.map +1 -1
- package/dist/core/api/client.d.ts +6 -0
- package/dist/core/api/client.d.ts.map +1 -1
- package/dist/core/api/client.js +125 -0
- package/dist/core/api/client.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/client.d.ts +100 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/client.js +2 -0
- package/dist/types/client.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/docs/commands/REFERENCE.md +21 -15
- package/package.json +1 -1
- package/src/commands/liberica/clients/create.ts +122 -0
- package/src/commands/liberica/clients/delete.ts +125 -0
- package/src/commands/liberica/clients/get.ts +88 -0
- package/src/commands/liberica/clients/index.ts +19 -0
- package/src/commands/liberica/clients/list.ts +123 -0
- package/src/commands/liberica/clients/update.ts +103 -0
- package/src/commands/liberica/index.ts +3 -0
- package/src/core/api/client.ts +152 -0
- package/src/index.ts +1 -1
- package/src/types/client.ts +115 -0
- package/src/types/index.ts +3 -0
|
@@ -7,6 +7,7 @@ import { createUsersCommand } from './users/index.js';
|
|
|
7
7
|
import { createOrgsCommand } from './orgs/index.js';
|
|
8
8
|
import { createPositionsCommand } from './positions/index.js';
|
|
9
9
|
import { createRolesCommand } from './roles/index.js';
|
|
10
|
+
import { createClientsCommand } from './clients/index.js';
|
|
10
11
|
|
|
11
12
|
export function createLibericaCommand(): Command {
|
|
12
13
|
const libericaCommand = new Command('liberica');
|
|
@@ -19,6 +20,7 @@ export function createLibericaCommand(): Command {
|
|
|
19
20
|
libericaCommand.addCommand(createOrgsCommand());
|
|
20
21
|
libericaCommand.addCommand(createPositionsCommand());
|
|
21
22
|
libericaCommand.addCommand(createRolesCommand());
|
|
23
|
+
libericaCommand.addCommand(createClientsCommand());
|
|
22
24
|
|
|
23
25
|
libericaCommand.action(() => {
|
|
24
26
|
console.log(chalk.bold('\n☕ Liberica Commands\n'));
|
|
@@ -29,6 +31,7 @@ export function createLibericaCommand(): Command {
|
|
|
29
31
|
console.log(' Use "barista liberica orders <command>" for order operations');
|
|
30
32
|
console.log(' Use "barista liberica products <command>" for product operations');
|
|
31
33
|
console.log(' Use "barista liberica production <command>" for production operations');
|
|
34
|
+
console.log(' Use "barista liberica clients <command>" for client management');
|
|
32
35
|
console.log('\n Run "barista liberica <command> --help" for more details\n');
|
|
33
36
|
});
|
|
34
37
|
|
package/src/core/api/client.ts
CHANGED
|
@@ -14,6 +14,12 @@ import {
|
|
|
14
14
|
UserQueryParams,
|
|
15
15
|
UserApiResponse,
|
|
16
16
|
} from '../../types/user.js';
|
|
17
|
+
import {
|
|
18
|
+
CreateClientRequest,
|
|
19
|
+
UpdateClientRequest,
|
|
20
|
+
ClientQueryParams,
|
|
21
|
+
ClientApiResponse,
|
|
22
|
+
} from '../../types/client.js';
|
|
17
23
|
import { OrgListItem } from '../../types/org.js';
|
|
18
24
|
import { PositionListItem } from '../../types/position.js';
|
|
19
25
|
|
|
@@ -783,6 +789,113 @@ export const apiClient = {
|
|
|
783
789
|
}
|
|
784
790
|
},
|
|
785
791
|
|
|
792
|
+
async listClients(
|
|
793
|
+
environment: Environment,
|
|
794
|
+
tenant: string,
|
|
795
|
+
params: ClientQueryParams
|
|
796
|
+
): Promise<ClientApiResponse> {
|
|
797
|
+
try {
|
|
798
|
+
const token = await tokenManager.getToken({ service: 'liberica', environment, tenant });
|
|
799
|
+
if (!token) {
|
|
800
|
+
return { success: false, error: { code: 'NO_TOKEN', message: 'Not logged in. Run: barista auth login --service liberica --env ' + environment } };
|
|
801
|
+
}
|
|
802
|
+
const client = createAPIClient('liberica' as Service, environment, tenant);
|
|
803
|
+
client.setAuthToken(token);
|
|
804
|
+
const queryString = new URLSearchParams();
|
|
805
|
+
if (params.pageNo !== undefined) queryString.append('pageNo', params.pageNo.toString());
|
|
806
|
+
if (params.pageSize) queryString.append('pageSize', params.pageSize.toString());
|
|
807
|
+
if (params.status) queryString.append('status', params.status.toString());
|
|
808
|
+
if (params.clientCode) queryString.append('clientCode', params.clientCode);
|
|
809
|
+
if (params.clientName) queryString.append('clientName', params.clientName);
|
|
810
|
+
const url = `/api/enterprise/sales/client/page${queryString.toString() ? '?' + queryString.toString() : ''}`;
|
|
811
|
+
const response = await client.getClient().get<ClientApiResponse>(url);
|
|
812
|
+
return response.data;
|
|
813
|
+
} catch (error) {
|
|
814
|
+
return handleApiErrorClient(error);
|
|
815
|
+
}
|
|
816
|
+
},
|
|
817
|
+
|
|
818
|
+
async getClient(
|
|
819
|
+
environment: Environment,
|
|
820
|
+
tenant: string,
|
|
821
|
+
clientId: string
|
|
822
|
+
): Promise<ClientApiResponse> {
|
|
823
|
+
try {
|
|
824
|
+
const token = await tokenManager.getToken({ service: 'liberica', environment, tenant });
|
|
825
|
+
if (!token) {
|
|
826
|
+
return { success: false, error: { code: 'NO_TOKEN', message: 'Not logged in. Run: barista auth login --service liberica --env ' + environment } };
|
|
827
|
+
}
|
|
828
|
+
const client = createAPIClient('liberica' as Service, environment, tenant);
|
|
829
|
+
client.setAuthToken(token);
|
|
830
|
+
const response = await client.getClient().get<ClientApiResponse>(
|
|
831
|
+
`/api/enterprise/sales/client/detail?clientId=${clientId}`
|
|
832
|
+
);
|
|
833
|
+
return response.data;
|
|
834
|
+
} catch (error) {
|
|
835
|
+
return handleApiErrorClient(error);
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
|
|
839
|
+
async createClient(
|
|
840
|
+
environment: Environment,
|
|
841
|
+
tenant: string,
|
|
842
|
+
data: CreateClientRequest
|
|
843
|
+
): Promise<ClientApiResponse> {
|
|
844
|
+
try {
|
|
845
|
+
const token = await tokenManager.getToken({ service: 'liberica', environment, tenant });
|
|
846
|
+
if (!token) {
|
|
847
|
+
return { success: false, error: { code: 'NO_TOKEN', message: 'Not logged in. Run: barista auth login --service liberica --env ' + environment } };
|
|
848
|
+
}
|
|
849
|
+
const client = createAPIClient('liberica' as Service, environment, tenant);
|
|
850
|
+
client.setAuthToken(token);
|
|
851
|
+
const response = await client.getClient().post<ClientApiResponse>('/api/enterprise/sales/client/add', data);
|
|
852
|
+
return response.data;
|
|
853
|
+
} catch (error) {
|
|
854
|
+
return handleApiErrorClient(error);
|
|
855
|
+
}
|
|
856
|
+
},
|
|
857
|
+
|
|
858
|
+
async updateClient(
|
|
859
|
+
environment: Environment,
|
|
860
|
+
tenant: string,
|
|
861
|
+
data: UpdateClientRequest
|
|
862
|
+
): Promise<ClientApiResponse> {
|
|
863
|
+
try {
|
|
864
|
+
const token = await tokenManager.getToken({ service: 'liberica', environment, tenant });
|
|
865
|
+
if (!token) {
|
|
866
|
+
return { success: false, error: { code: 'NO_TOKEN', message: 'Not logged in. Run: barista auth login --service liberica --env ' + environment } };
|
|
867
|
+
}
|
|
868
|
+
const client = createAPIClient('liberica' as Service, environment, tenant);
|
|
869
|
+
client.setAuthToken(token);
|
|
870
|
+
const response = await client.getClient().post<ClientApiResponse>('/api/enterprise/sales/client/edit', data);
|
|
871
|
+
return response.data;
|
|
872
|
+
} catch (error) {
|
|
873
|
+
return handleApiErrorClient(error);
|
|
874
|
+
}
|
|
875
|
+
},
|
|
876
|
+
|
|
877
|
+
async deleteClient(
|
|
878
|
+
environment: Environment,
|
|
879
|
+
tenant: string,
|
|
880
|
+
clientId: string
|
|
881
|
+
): Promise<ClientApiResponse> {
|
|
882
|
+
try {
|
|
883
|
+
const token = await tokenManager.getToken({ service: 'liberica', environment, tenant });
|
|
884
|
+
if (!token) {
|
|
885
|
+
return { success: false, error: { code: 'NO_TOKEN', message: 'Not logged in. Run: barista auth login --service liberica --env ' + environment } };
|
|
886
|
+
}
|
|
887
|
+
const client = createAPIClient('liberica' as Service, environment, tenant);
|
|
888
|
+
client.setAuthToken(token);
|
|
889
|
+
const response = await client.getClient().post<ClientApiResponse>(
|
|
890
|
+
'/api/enterprise/sales/client/delete',
|
|
891
|
+
{ clientId }
|
|
892
|
+
);
|
|
893
|
+
return response.data;
|
|
894
|
+
} catch (error) {
|
|
895
|
+
return handleApiErrorClient(error);
|
|
896
|
+
}
|
|
897
|
+
},
|
|
898
|
+
|
|
786
899
|
};
|
|
787
900
|
|
|
788
901
|
function handleApiError(error: unknown): EmployeeApiResponse {
|
|
@@ -822,4 +935,43 @@ function handleApiError(error: unknown): EmployeeApiResponse {
|
|
|
822
935
|
message: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
823
936
|
},
|
|
824
937
|
};
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
function handleApiErrorClient(error: unknown): ClientApiResponse {
|
|
941
|
+
if (axios.isAxiosError(error)) {
|
|
942
|
+
const axiosError = error as AxiosError<Record<string, unknown>>;
|
|
943
|
+
const responseData = axiosError.response?.data;
|
|
944
|
+
if (responseData) {
|
|
945
|
+
const success = responseData.success as boolean | undefined;
|
|
946
|
+
if (success === false) {
|
|
947
|
+
const code = responseData.code as string | undefined;
|
|
948
|
+
const message = responseData.message as string | undefined;
|
|
949
|
+
const errorObj = responseData.error as { code?: string; message?: string } | undefined;
|
|
950
|
+
if (!errorObj && (code || message)) {
|
|
951
|
+
return {
|
|
952
|
+
success: false,
|
|
953
|
+
error: {
|
|
954
|
+
code: code || 'API_ERROR',
|
|
955
|
+
message: message || 'API error occurred',
|
|
956
|
+
},
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
return responseData as unknown as ClientApiResponse;
|
|
961
|
+
}
|
|
962
|
+
return {
|
|
963
|
+
success: false,
|
|
964
|
+
error: {
|
|
965
|
+
code: 'NETWORK_ERROR',
|
|
966
|
+
message: axiosError.message || 'Network error occurred',
|
|
967
|
+
},
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
return {
|
|
971
|
+
success: false,
|
|
972
|
+
error: {
|
|
973
|
+
code: 'UNKNOWN_ERROR',
|
|
974
|
+
message: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
975
|
+
},
|
|
976
|
+
};
|
|
825
977
|
}
|
package/src/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ async function main(): Promise<void> {
|
|
|
15
15
|
program
|
|
16
16
|
.name('barista')
|
|
17
17
|
.description('Barista CLI - Bridge between AI agents and Liberica/Arabica')
|
|
18
|
-
.version('0.1.
|
|
18
|
+
.version('0.1.4')
|
|
19
19
|
.option('-e, --env <environment>', 'Target environment (dev|test|prod-cn|prod-jp)')
|
|
20
20
|
.option('-t, --tenant <tenant>', 'Target tenant (for Liberica)')
|
|
21
21
|
.option('--dry-run', 'Execute in dry-run mode')
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Status flag literal type
|
|
2
|
+
export type StatusFlag = 1 | 2;
|
|
3
|
+
|
|
4
|
+
// Full Client entity (from MasterClientRequest - all fields)
|
|
5
|
+
export interface MasterClientResponse {
|
|
6
|
+
clientId: string;
|
|
7
|
+
clientCode: string;
|
|
8
|
+
clientName: string;
|
|
9
|
+
clientClasses?: string[];
|
|
10
|
+
follower?: string;
|
|
11
|
+
officeAddress?: string;
|
|
12
|
+
officeTelephone?: string;
|
|
13
|
+
officeFax?: string;
|
|
14
|
+
clientCredit?: string;
|
|
15
|
+
defaultCurrency?: string;
|
|
16
|
+
defaultManageFee?: number;
|
|
17
|
+
receiveAddress?: string;
|
|
18
|
+
receiveTelephone?: string;
|
|
19
|
+
receiveFax?: string;
|
|
20
|
+
sendPeriod?: number;
|
|
21
|
+
defaultTransactionMethod?: string;
|
|
22
|
+
region?: string;
|
|
23
|
+
defaultShippingMethod?: string;
|
|
24
|
+
defaultTradeType?: string;
|
|
25
|
+
lowLotRate?: number;
|
|
26
|
+
statusFlag: StatusFlag;
|
|
27
|
+
remark?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Compact Client entity for list items
|
|
31
|
+
export interface MasterClientCompactResponse {
|
|
32
|
+
clientId: string;
|
|
33
|
+
clientCode: string;
|
|
34
|
+
clientName: string;
|
|
35
|
+
follower?: string;
|
|
36
|
+
statusFlag: StatusFlag;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Request for creating client (add endpoint)
|
|
40
|
+
export interface CreateClientRequest {
|
|
41
|
+
clientCode: string;
|
|
42
|
+
clientName?: string;
|
|
43
|
+
follower?: string;
|
|
44
|
+
officeAddress?: string;
|
|
45
|
+
officeTelephone?: string;
|
|
46
|
+
officeFax?: string;
|
|
47
|
+
clientCredit?: string;
|
|
48
|
+
defaultCurrency?: string;
|
|
49
|
+
defaultManageFee?: number;
|
|
50
|
+
receiveAddress?: string;
|
|
51
|
+
receiveTelephone?: string;
|
|
52
|
+
receiveFax?: string;
|
|
53
|
+
sendPeriod?: number;
|
|
54
|
+
defaultTransactionMethod?: string;
|
|
55
|
+
region?: string;
|
|
56
|
+
defaultShippingMethod?: string;
|
|
57
|
+
defaultTradeType?: string;
|
|
58
|
+
lowLotRate?: number;
|
|
59
|
+
statusFlag?: StatusFlag;
|
|
60
|
+
remark?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Request for updating client (edit endpoint)
|
|
64
|
+
export interface UpdateClientRequest {
|
|
65
|
+
clientId: string;
|
|
66
|
+
clientName?: string;
|
|
67
|
+
follower?: string;
|
|
68
|
+
officeAddress?: string;
|
|
69
|
+
officeTelephone?: string;
|
|
70
|
+
officeFax?: string;
|
|
71
|
+
clientCredit?: string;
|
|
72
|
+
defaultCurrency?: string;
|
|
73
|
+
defaultManageFee?: number;
|
|
74
|
+
receiveAddress?: string;
|
|
75
|
+
receiveTelephone?: string;
|
|
76
|
+
receiveFax?: string;
|
|
77
|
+
sendPeriod?: number;
|
|
78
|
+
defaultTransactionMethod?: string;
|
|
79
|
+
region?: string;
|
|
80
|
+
defaultShippingMethod?: string;
|
|
81
|
+
defaultTradeType?: string;
|
|
82
|
+
lowLotRate?: number;
|
|
83
|
+
statusFlag?: StatusFlag;
|
|
84
|
+
remark?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Query params for list/pagination
|
|
88
|
+
export interface ClientQueryParams {
|
|
89
|
+
pageNo?: number;
|
|
90
|
+
pageSize?: number;
|
|
91
|
+
status?: StatusFlag;
|
|
92
|
+
clientCode?: string;
|
|
93
|
+
clientName?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Paginated response wrapper (PageResult from Roses framework)
|
|
97
|
+
export interface PageResult<T> {
|
|
98
|
+
totalRows: number;
|
|
99
|
+
pageSize: number;
|
|
100
|
+
pageNo: number;
|
|
101
|
+
rows: T[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// List response type
|
|
105
|
+
export interface ClientListResponse extends PageResult<MasterClientCompactResponse> {}
|
|
106
|
+
|
|
107
|
+
// API response wrapper
|
|
108
|
+
export interface ClientApiResponse {
|
|
109
|
+
success: boolean;
|
|
110
|
+
data?: MasterClientResponse | ClientListResponse;
|
|
111
|
+
error?: {
|
|
112
|
+
code: string;
|
|
113
|
+
message: string;
|
|
114
|
+
};
|
|
115
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -73,3 +73,6 @@ export interface TokenContext {
|
|
|
73
73
|
export * from './employee.js';
|
|
74
74
|
export * from './org.js';
|
|
75
75
|
export * from './position.js';
|
|
76
|
+
// Export client types explicitly to avoid conflicts with employee types
|
|
77
|
+
export type { StatusFlag, ClientListResponse, MasterClientCompactResponse, ClientQueryParams, ClientApiResponse } from './client.js';
|
|
78
|
+
export type { MasterClientResponse, CreateClientRequest, UpdateClientRequest } from './client.js';
|